Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
fixes #10 - added ability to set lexer options by config
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Nov 16, 2012
1 parent 73174b5 commit 9c1f507
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
-----------------

Expand Down
13 changes: 13 additions & 0 deletions SublimeHighlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion SublimeHighlight.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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.