Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes #10 - added ability to set lexer options by config

  • Loading branch information...
commit 9c1f507392b913db23a53a4455e1021f027d2d97 1 parent 73174b5
@n1k0 authored
View
12 README.md
@@ -96,6 +96,18 @@ You can set the rendered HTML code to use inline styles instead of CSS classes:
"noclasses": true
}
+### Lexer options
+
+SublimeHighlight supports [Pygments lexer options](http://pygments.org/docs/lexers/). To set an option for a given lexer, eg. `PHP`:
+
+ {
+ "lexer_options": {
+ "PHP": {
+ "startinline": true
+ }
+ }
+ }
+
Why this package?
-----------------
View
13 SublimeHighlight.py
@@ -87,6 +87,19 @@ def get_lexer(self, code=None):
lexer = self.guess_lexer_from_syntax()
if not lexer:
lexer = pygments.lexers.guess_lexer(code)
+ try:
+ options = settings.get('lexer_options', {}).get(lexer.name)
+ except AttributeError:
+ return lexer
+ if not options:
+ return lexer
+ # handle lexer options
+ for option, value in options.iteritems():
+ try:
+ setattr(lexer, option, value)
+ except AttributeError:
+ sublime.error_message(u'Highlight: unsupported %s lexer option: "%s"'
+ % (lexer.name, option))
return lexer
def highlight(self, output_type):
View
9 SublimeHighlight.sublime-settings
@@ -12,5 +12,12 @@
"linenos": false,
/* Uses inline styles instead of css classes */
- "noclasses": true
+ "noclasses": true,
+
+ /* Lexer options */
+ "lexer_options": {
+ "PHP": {
+ "startinline": true
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.