Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a theme/language enum? #38

Open
rudedogg opened this issue Mar 17, 2018 · 3 comments
Open

Provide a theme/language enum? #38

rudedogg opened this issue Mar 17, 2018 · 3 comments

Comments

@rudedogg
Copy link
Contributor

rudedogg commented Mar 17, 2018

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.

@rudedogg
Copy link
Contributor Author

rudedogg commented Mar 17, 2018

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.

@rudedogg rudedogg changed the title Provide a theme enum? Provide a theme/language enum? Mar 17, 2018
@raspu
Copy link
Owner

raspu commented Mar 19, 2018

I like this a lot! Awesome idea :).

@rudedogg
Copy link
Contributor Author

Sweet! I'll try and get a PR up soon. If someone else wants to feel free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants