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.

Advertisements

One thought on “SyntaxHighlighter: LDIF

  1. Okay, I extended the regular expression to /[\w;-]+(?=:.*(\r|\n)?)/g. That takes the following string all the way to the end of the line, which seems to work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s