joelpt / sublimetext-print-to-html

Sublime Text 2 plugin to print colorized files as HTML via your browser.
57 stars 11 forks source link

Sublime Lexer - ST2's internal scope data for colour #6

Open DanielOaks opened 11 years ago

DanielOaks commented 11 years ago

I'm currently writing a fairly large change to how Print to Html interfaces with Pygments, in order to fulfil this goal:

Basically, instead of passing the text to Pygments' lexer, it goes through a custom-written lexer that maps ST2 scopes to Pygments tokens. The formatting and output are the same, it's just how it interfaces with the lexer that changes.

Currently, here's a comparison between the outputs of Pygments (top) and the SublimeLexer (bottom):

pyg

And I'm gonna go through the other languages, get them to an alright state with any language-specific scopes that need to be mapped across.

joelpt commented 11 years ago

Very nice, looking forward to seeing this in action.

DanielOaks commented 11 years ago

Thanks. I'm developing this on my branch if you wanna take a look at how it works.

Basically, I create a custom Lexer in sublimepygments.py, and offload all the Sublime scope to Pygments token mapping to that. Figured that was a fairly simple solution.

In addition, the list PrintToHTML uses to map scopes to tokens is in a sublime-settings file, to make things nicer and easier on the user. I've decided to put it in its own settings file, seeing as how large it is, and how users may simply replace/exchange their Mappings file with other users, without wanting to worry about their usual config.

I've yet to finish up the documentation, but there's a very barebones guide on how to colour new languages (add your own mappings) at ColoringNewLanguages.md

So basically, not ready for production yet, but getting more usable (and already production-ready for Python code and languages that use the basic Sublime scopes).