raspu / Highlightr

iOS & OSX Syntax Highlighter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create a custom theme

opened this issue · comments

Hi Raspu,
Thank you for your amazing work.
I have a question: is it possible to create a custom theme?
Or in another way, is it possible to change the font and the color of the text? Because I have read something about it on other issues but I haven't understood it very well
Thank you for your patience

Hi @AaronLatnok I am glad you like it :).

You can always modify the font of a theme, if you see the Theme class there's 3 properties you can use to modify this:

    /// Regular font to be used by this theme
    open var codeFont : RPFont!
    /// Bold font to be used by this theme
    open var boldCodeFont : RPFont!
    /// Italic font to be used by this theme
    open var italicCodeFont : RPFont!

And, if you want to get the font variations automatically populated from a regular font you can also use: open func setCodeFont(_ font: RPFont) and it will try to populate those 3 properties. By the way, RPFont is just an Alias for UIFont or NSFont (depending on the platform).

Now, even if there's no public API for modifying the color of the fonts, you can still achieve this by modifying directly the CSS theme files that are included with the project, they are just regular CSS files, that you can easily de-minify and change as you wish.

Let me know if you need a more elaborated example on how to do this.

Best!

Thank you so much Raspu, you helped me a lot! Done it without any problem
I have a last doubt: is it possibile delete themes and languages? In my app I want to show just few themes and seven coding languages. I tried to delete what I don't need from the project but the app crashes, so I have looked for some dependencies but I didn't find them (I typed the name of the files, but in truth I don't know what to search exactly)

Thanks a lot for the patience and a huge thanks for the help, I started to learn Swift just a month ago and for me everything is new

Hi, I am glad you were able to make it work!

About removing themes and languages, did you try just deleting the JS files and the CSS files? I never tried this myself tbh... If that doesn't work you can always make a list of theme and languages yourself and present that as the only option to the user, no need of modifying the library itself... But if you really need to avoid including those files in your project you'll probably need to build a new delivery from the original highlighter.js, but I am not really sure if there's any option for limiting the langs or themes... (If you try this, make sure to build it with the CDN option). Let me know if you make it work, if not I can try to make build myself...

Best!

Hi @AaronLatnok, I am going to close this issue for now, feel free to re-open it if you have more questions.