diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-30 19:47:21 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-30 19:47:21 +0100 |
| commit | a98b5ea6fe8e8cc98a55e0fd793e6e8660ea31c1 (patch) | |
| tree | 542810ab5aef99150db228bb54fd58303dcb31c7 /public/prism/prism-latex.js | |
| parent | ab355897a12b7bda1089a44de326d41455a0f7a3 (diff) | |
chore: add prismjs for syntax highlighting
Diffstat (limited to 'public/prism/prism-latex.js')
| -rw-r--r-- | public/prism/prism-latex.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/public/prism/prism-latex.js b/public/prism/prism-latex.js new file mode 100644 index 0000000..35aefec --- /dev/null +++ b/public/prism/prism-latex.js @@ -0,0 +1,69 @@ +(function (Prism) { + var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i; + var insideEqu = { + 'equation-command': { + pattern: funcPattern, + alias: 'regex', + }, + }; + + Prism.languages.latex = { + comment: /%.*/, + // the verbatim environment prints whitespace to the document + cdata: { + pattern: + /(\\begin\{((?:lstlisting|verbatim)\*?)\})[\s\S]*?(?=\\end\{\2\})/, + lookbehind: true, + }, + /* + * equations can be between $$ $$ or $ $ or \( \) or \[ \] + * (all are multiline) + */ + equation: [ + { + pattern: + /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/, + inside: insideEqu, + alias: 'string', + }, + { + pattern: + /(\\begin\{((?:align|eqnarray|equation|gather|math|multline)\*?)\})[\s\S]*?(?=\\end\{\2\})/, + lookbehind: true, + inside: insideEqu, + alias: 'string', + }, + ], + /* + * arguments which are keywords or references are highlighted + * as keywords + */ + keyword: { + pattern: + /(\\(?:begin|cite|documentclass|end|label|ref|usepackage)(?:\[[^\]]+\])?\{)[^}]+(?=\})/, + lookbehind: true, + }, + url: { + pattern: /(\\url\{)[^}]+(?=\})/, + lookbehind: true, + }, + /* + * section or chapter headlines are highlighted as bold so that + * they stand out more + */ + headline: { + pattern: + /(\\(?:chapter|frametitle|paragraph|part|section|subparagraph|subsection|subsubparagraph|subsubsection|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\})/, + lookbehind: true, + alias: 'class-name', + }, + function: { + pattern: funcPattern, + alias: 'selector', + }, + punctuation: /[[\]{}&]/, + }; + + Prism.languages.tex = Prism.languages.latex; + Prism.languages.context = Prism.languages.latex; +})(Prism); |
