raspu / Highlightr

iOS & OSX Syntax Highlighter.
MIT License
1.66k stars 261 forks source link

Added public modifier to Theme initializer #59

Closed SvenTiigi closed 5 years ago

SvenTiigi commented 5 years ago

Currently the Theme initializer init(themeString: String) was set to internal. Making the initializer public allows developers to inject custom CSS Highlightr Code.

let customHighlightrCSS = "......."
let customTheme = Theme(themeString: customHighlightrCSS)

let highlightr = Highlightr()
highlightr?.theme = customTheme
bpisano commented 5 years ago

Have you tested this code ? Making the initializer public doesn't work for me :

let highlighter = Highlightr()

let theme = Theme(themeString: "github")
highlighter?.theme = theme

let storage = CodeAttributedString(highlightr: highlighter!)
storage.language = "Swift"

textView.layoutManager?.replaceTextStorage(storage)

The solution to make a custom theme is create a new .min.css file and use the setTheme() method.

SvenTiigi commented 5 years ago

Hi @bpisano,

Sorry I forgot to close this PR when I deleted my fork.

As you already mentioned I've used the setTheme() function to use a custom theme.

Thanks ✌️