LeaVerou/prism — pull request #319 by zeitgeist87 (2014-08-10 07:15:32+00:00)
Title: Allow multiple tokens to be mapped to the same CSS class

In most languages there are different ways of declaring the same
constructs, but with the current implementation of Prism it is only
possible to define one pattern for a particular token type. This is not
a problem, as long as it is possible to match everything with one regex.
But sometimes it isn't easily possible to do that, especially if things
like `lookbehind` or `inside` are needed for one part but not for the
other. This patch splits the token type into two parts, whereby the
second part is optional: {token type}#{description}

For example there is a minor bug in the current definition of the
`clike` language, that could be solved with this patch:

The character immediately in front of a single line comment is
highlighted as a comment as well.

```javascript
something// something
```

This is because both definitions for single and multiline comments have
to be matched with a single regex and the `lookbehind` parameter can
only be applied to the first captured string.

With this patch one could split the two definitions up and use
`lookbehind` for both, thereby eliminating the bug.

```javascript
'comment': {
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//g,
lookbehind: true
},
'comment#single-line': {
pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/g,
lookbehind: true
},
```