|
| 1 | +# Custom Highlight Templates |
| 2 | + |
| 3 | +The highlight.php library takes its highlighting metadata/rules |
| 4 | +from highlight.js. That library builds the highlighting metadata/rules |
| 5 | +in Node and then outputs them as JSON: |
| 6 | + |
| 7 | +* Source Language files: https://github.com/highlightjs/highlight.js/tree/master/src/languages |
| 8 | +* Final Language files: https://github.com/scrivo/highlight.php/tree/master/Highlight/languages |
| 9 | + |
| 10 | +In a few cases, we've extended the language rules, which (in theory) |
| 11 | +should make it back upstream to highlight.js. These files began |
| 12 | +as copies of the .json files (which were then prettified) then extended. |
| 13 | + |
| 14 | +A few things we've learned about how the language files work: |
| 15 | + |
| 16 | +* `begin` is the regex that marks the beginning of something |
| 17 | +* `end` is optional. Without it, `begin` will be used, and as |
| 18 | + soon as it finds a non-matching character, it will stop. |
| 19 | + If you have a situation where using begin is causing |
| 20 | + over-matching, then you can use end to tell it exactly where |
| 21 | + to stop. |
| 22 | +* `excludeEnd` can be used to match an entire string with `begin` |
| 23 | + and `end`, but then only apply the class name to the part |
| 24 | + matched by `start`. This was useful with `::` where we wanted |
| 25 | + to match `::` THEN some valid string (to avoid over-matching |
| 26 | + `::` in other situations). But, we only wanted the class name |
| 27 | + applied to the `start` part (the `::` part). |
| 28 | +* `contains` the way for building embedded rules. `function` is |
| 29 | + a nice example, which outlines the `start` and `end` and then |
| 30 | + also outlines some items that will be embedded inside of it. |
0 commit comments