Daily Archives: May 2, 2012

SyntaxHighlighter: LDIF

LDIF syntax highlighting example

Using the examples from RFC 2849, I tried making a SyntaxHighlighter brush for LDIF. I started with the plain brush and added some content into the Brush() function.

function Brush()
{
  var keywords = 'add changetype control delete deleteoldrdn dn ' +
    'moddn modify modrdn newrdn newsuperior replace version';

  this.regexList = [
    { regex: new RegExp(this.getKeywords(keywords), 'gmi'), css: 'keyword' },
    { regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
    { regex: SyntaxHighlighter.regexLib.url, css: 'a' },
    { regex: /-(\n|$)/g, css: 'color3' },
    { regex: /\b(\d+\.)+\d+\b/g, css: 'color1' },
    { regex: /:<|:<|:/g, css: 'color3' },
    { regex: /[\w;-]+(?=:)/g, css: 'string' },
  ];
};

The resulting test page is at http://mcraig.org/fr/sh/ldif.html. Clearly there’s something I don’t understand about keyword highlighting: What I want is to get the keywords highlighted as keywords preferentially over any of the other /[\w;-]+(?=:)/g matches, but that’s not what’s happening.

1 Comment

Filed under Docs, Tools