Provide a theme/language enum?
rudedogg opened this issue · comments
What are your thoughts on providing a theme enum? There are 79 styles/themes currently, so it'll be a pretty large enum, but it seems like it would make the API a little more swifty.
ex:
enum HighlightrTheme: String {
case solarizedDark = "solarized-dark"
case solarizedLight = "solarized-light"
case xCode = "xcode"
}
And setting a theme would look like:
highlightr.setTheme(to: .solarizedDark)
Thinking about it more, we'd probably want to do the same for languages (176 currently) if bothering to make this change. It wouldn't be backward compatible and require a full version bump.
Here's an extension that makes this work:
extension Highlightr {
enum Theme: String {
case arta = "arta"
case atelierCaveDark = "atelier-cave-dark"
case atelierCaveLight = "atelier-cave-light"
case dracula = "dracula"
case pojoaque = "pojoaque"
case solarizedDark = "solarized-dark"
case solarizedLight = "solarized-light"
case xcode = "xcode"
}
enum Language: String {
case css = "css"
case html = "html"
}
@discardableResult
func setTheme(to theme: Highlightr.Theme) -> Bool {
return setTheme(to: theme.rawValue)
}
func highlight(_ code: String, as language: Highlightr.Language, fastRender: Bool = true) -> NSAttributedString? {
return highlight(code, as: language.rawValue, fastRender: fastRender)
}
}
My comment about it requiring a version bump and being a breaking change is incorrect. It could be an additional API and we can deprecate the old usage with @available(*, deprecated, message: "Replaced by Highlight.Theme enum usage")
etc.
I like this a lot! Awesome idea :).
Sweet! I'll try and get a PR up soon. If someone else wants to feel free.