Olov Lassus

Dart syntax highlighting update

26 Nov 2011

Here’s a short update on the Pygments Dart support I created a month back.

I consider it good to go now and will submit it to the Pygments upstream and github shortly. The most notable addition is support for string interpolation. I’ve also created a custom color scheme (based on tango) that works well with at least Dart, JS and Diff.

It looks like this:


main() {
  String name = "Zoidberg";
  const age = 42;
  var liar = Math.random() > 0.5;

  // Present ourselves
  print("Hi! My name is $name and I'm ${liar ? age / 2 : age} years old");

Source code is available at https://gist.github.com/1320163. Install it by appending the gist to Pygments’s agile.py and add the following line to _mapping.py.

    'DartLexer': ('pygments.lexers.agile', 'Dart', ('dart'), ('*.dart',), ('text/x-dart')),

Then run pygmentize -f html -o yourfile.html yourfile.dart to generate markup from your source code. You’ll need to combine it with a style sheet. Feel free to copy my color scheme (syntax.css) if you like it.

Show comments (Dart misc)

Follow me on Twitter

« Let's create us some Dart ranges    ↑ Home     »