Read in JSON/CSON tokens from a TextMate-style lexical analyser and render the tokens with rendering modules written in a TextMate-style syntax.
Companion to the Textlex lexical analyser project.
Based on code converted from the Highlights project.
Installing
npm install delexe
Using
Run delexe -h
for full details about the supported options.
To convert a JSON token file to tokenized HTML run the following:
delexe tokens.json -o file.html
Now you have a file.html
file that has a big <pre>
tag with a <div>
for
each line with <span>
elements for each token's scope.
Then you can compile an existing Atom theme into a stylesheet with the following:
git clone https://github.com/atom/atom-dark-syntaxcd atom-dark-syntaxnpm install -g lesslessc --include-path=stylesheets index.less atom-dark-syntax.css
Now you have an atom-dark-syntax.css
stylesheet that can be combined with
the file.html
file to generate some nice looking code.
Check out the examples to see it in action.
Check out atom.io to find more themes.
Some popular themes:
Using in code
To convert a JSON token string to tokenized HTML run the following:
var Delexe = ;var renderer = ;var fileTokens = "value": "var" "scopes": "source.js" "storage.modifier.js" "value": " hello " "scopes": "source.js" "value": "=" "scopes": "source.js" "keyword.operator.js" "value": " " "scopes": "source.js" "value": "'" "scopes": "source.js" "string.quoted.single.js" "punctuation.definition.string.begin.js" "value": "world" "scopes": "source.js" "string.quoted.single.js" "value": "'" "scopes": "source.js" "string.quoted.single.js" "punctuation.definition.string.end.js" "value": ";" "scopes": "source.js" "punctuation.terminator.statement.js" ; var text = renderer; console; var html = renderer; console;
Outputs:
var hello = 'world';
var hello = ' world ' ;
Developing
- Clone this repository
git clone https://github.com/jonruttan/delexe
- Update the submodules by running
git submodule update --init --recursive
- Run
npm install
to install the dependencies, compile the CoffeeScript, and build the grammars - Run
npm test
to run the specs
💚 Pull requests are greatly appreciated and welcomed.