Permalink
Browse files

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

  • Loading branch information...
1 parent 73174b5 commit 9c1f507392b913db23a53a4455e1021f027d2d97 @n1k0 committed Nov 16, 2012
Showing with 33 additions and 1 deletion.
  1. +12 −0 README.md
  2. +13 −0 SublimeHighlight.py
  3. +8 −1 SublimeHighlight.sublime-settings
View
@@ -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
@@ -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):
@@ -12,5 +12,12 @@
"linenos": false,
/* Uses inline styles instead of css classes */
- "noclasses": true
+ "noclasses": true,
+
+ /* Lexer options */
+ "lexer_options": {
+ "PHP": {
+ "startinline": true
+ }
+ }
}

0 comments on commit 9c1f507

Please sign in to comment.