Skip to content

Commit

Permalink
Merge branch 'LatexBranch' of https://github.com/zeitgeist87/prism in…
Browse files Browse the repository at this point in the history
…to gh-pages + update tests

Conflicts:
	components/prism-latex.js
	components/prism-latex.min.js
  • Loading branch information
Golmote committed Sep 5, 2015
2 parents c451611 + c9ec813 commit 942a6ec
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 35 deletions.
67 changes: 61 additions & 6 deletions components/prism-latex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
Prism.languages.latex = {
'comment': /%.*/m,
'string': /(\$)(\\?.)*?\1/,
'punctuation': /[{}]/,
'selector': /\\[a-z;,:\.]*/i
};
(function(Prism) {
var funcPattern = /\\([^a-z()[\]]|[a-z\*]+)/i,
insideEqu = {
'equation-command': {
pattern: funcPattern,
alias: 'regex'
}
};

Prism.languages.latex = {
'comment': /%.*/m,
// the verbatim environment prints whitespace to the document
'cdata': {
pattern: /(\\begin\{((?:verbatim|lstlisting)\*?)\})([\w\W]*?)(?=\\end\{\2\})/,
lookbehind: true
},
/*
* equations can be between $ $ or \( \) or \[ \]
* (all are multiline)
*/
'equation': [
{
pattern: /\$(?:\\?[\w\W])*?\$|\\\((?:\\?[\w\W])*?\\\)|\\\[(?:\\?[\w\W])*?\\\]/,
inside: insideEqu,
alias: 'string'
},
{
pattern: /(\\begin\{((?:equation|math|eqnarray|align|multline|gather)\*?)\})([\w\W]*?)(?=\\end\{\2\})/,
lookbehind: true,
inside: insideEqu,
alias: 'string'
}
],
/*
* arguments which are keywords or references are highlighted
* as keywords
*/
'keyword': {
pattern: /(\\(?:begin|end|ref|cite|label|usepackage|documentclass)(?:\[[^\]]+\])?\{)[^}]+(?=\})/,
lookbehind: true
},
'url': {
pattern: /(\\url\{)[^}]+(?=\})/,
lookbehind: true
},
/*
* section or chapter headlines are highlighted as bold so that
* they stand out more
*/
'headline': {
pattern: /(\\(?:part|chapter|section|subsection|frametitle|subsubsection|paragraph|subparagraph|subsubparagraph|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\}(?:\[[^\]]+\])?)/,
lookbehind: true,
alias: 'class-name'
},
'function': {
pattern: funcPattern,
alias: 'selector'
},
'punctuation': /[[\]{}&]/
};
})(Prism);
2 changes: 1 addition & 1 deletion components/prism-latex.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions tests/languages/latex/cdata_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
\begin{verbatim*}
Foo bar
\end{verbatim*}

\begin{lstlisting}
Foo bar
baz
\end{lstlisting}

----------------------------------------------------

[
["function", "\\begin"], ["punctuation", "{"],
["keyword", "verbatim*"], ["punctuation", "}"],
["cdata", "\r\nFoo bar\r\n"],
["function", "\\end"], ["punctuation", "{"],
["keyword", "verbatim*"], ["punctuation", "}"],

["function", "\\begin"], ["punctuation", "{"],
["keyword", "lstlisting"], ["punctuation", "}"],
["cdata", "\r\nFoo bar\r\nbaz\r\n"],
["function", "\\end"], ["punctuation", "{"],
["keyword", "lstlisting"], ["punctuation", "}"]
]

----------------------------------------------------

Checks for verbatim environment.
121 changes: 121 additions & 0 deletions tests/languages/latex/equation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
$foo$
$a \dots
b$
\(foo\)
\(a \dots
b\)
\[foo\]
\[a \dots
b\]

\begin{equation}foo\end{equation}
\begin{equation}a \dots
b\end{equation}
\begin{math}foo\end{math}
\begin{math}a \dots
b\end{math}
\begin{eqnarray}foo\end{eqnarray}
\begin{eqnarray}a \dots
b\end{eqnarray}
\begin{align}foo\end{align}
\begin{align*}a \dots
b\end{align*}
\begin{multline}foo\end{multline}
\begin{multline}a \dots
b\end{multline}
\begin{gather}foo\end{gather}
\begin{gather}a \dots
b\end{gather}

----------------------------------------------------

[
["equation", ["$foo$"]],
["equation", [
"$a ",
["equation-command", "\\dots"],
"\r\nb$"
]],
["equation", ["\\(foo\\)"]],
["equation", [
"\\(a ",
["equation-command", "\\dots"],
"\r\nb\\)"
]],
["equation", ["\\[foo\\]"]],
["equation", [
"\\[a ",
["equation-command", "\\dots"],
"\r\nb\\]"
]],

["function", "\\begin"], ["punctuation", "{"],
["keyword", "equation"], ["punctuation", "}"],
["equation", ["foo"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "equation"], ["punctuation", "}"],
["function", "\\begin"], ["punctuation", "{"],
["keyword", "equation"], ["punctuation", "}"],
["equation", ["a ", ["equation-command", "\\dots"], "\r\nb"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "equation"], ["punctuation", "}"],

["function", "\\begin"], ["punctuation", "{"],
["keyword", "math"], ["punctuation", "}"],
["equation", ["foo"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "math"], ["punctuation", "}"],
["function", "\\begin"], ["punctuation", "{"],
["keyword", "math"], ["punctuation", "}"],
["equation", ["a ", ["equation-command", "\\dots"], "\r\nb"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "math"], ["punctuation", "}"],

["function", "\\begin"], ["punctuation", "{"],
["keyword", "eqnarray"], ["punctuation", "}"],
["equation", ["foo"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "eqnarray"], ["punctuation", "}"],
["function", "\\begin"], ["punctuation", "{"],
["keyword", "eqnarray"], ["punctuation", "}"],
["equation", ["a ", ["equation-command", "\\dots"], "\r\nb"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "eqnarray"], ["punctuation", "}"],

["function", "\\begin"], ["punctuation", "{"],
["keyword", "align"], ["punctuation", "}"],
["equation", ["foo"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "align"], ["punctuation", "}"],
["function", "\\begin"], ["punctuation", "{"],
["keyword", "align*"], ["punctuation", "}"],
["equation", ["a ", ["equation-command", "\\dots"], "\r\nb"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "align*"], ["punctuation", "}"],

["function", "\\begin"], ["punctuation", "{"],
["keyword", "multline"], ["punctuation", "}"],
["equation", ["foo"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "multline"], ["punctuation", "}"],
["function", "\\begin"], ["punctuation", "{"],
["keyword", "multline"], ["punctuation", "}"],
["equation", ["a ", ["equation-command", "\\dots"], "\r\nb"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "multline"], ["punctuation", "}"],

["function", "\\begin"], ["punctuation", "{"],
["keyword", "gather"], ["punctuation", "}"],
["equation", ["foo"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "gather"], ["punctuation", "}"],
["function", "\\begin"], ["punctuation", "{"],
["keyword", "gather"], ["punctuation", "}"],
["equation", ["a ", ["equation-command", "\\dots"], "\r\nb"]],
["function", "\\end"], ["punctuation", "{"],
["keyword", "gather"], ["punctuation", "}"]
]

----------------------------------------------------

Checks for equations.
39 changes: 39 additions & 0 deletions tests/languages/latex/headline_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
\part{Foobar}
\chapter{Foobar}
\section{Foobar}
\subsection{Foobar}
\frametitle{Foobar}
\subsubsection{Foobar}
\paragraph{Foobar}
\subparagraph{Foobar}
\subsubparagraph{Foobar}
\subsubsubparagraph{Foobar}

----------------------------------------------------

[
["function", "\\part"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\chapter"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\section"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\subsection"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\frametitle"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\subsubsection"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\paragraph"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\subparagraph"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\subsubparagraph"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"],
["function", "\\subsubsubparagraph"], ["punctuation", "{"],
["headline", "Foobar"], ["punctuation", "}"]
]

----------------------------------------------------

Checks for headlines.
32 changes: 32 additions & 0 deletions tests/languages/latex/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
\begin{foobar}
\end{foobar}
\ref{foobar}
\cite{foobar}
\label{foobar}
\usepackage{foobar}
\documentclass[11px,twoside,a4paper]{foobar}

----------------------------------------------------

[
["function", "\\begin"], ["punctuation", "{"],
["keyword", "foobar"], ["punctuation", "}"],
["function", "\\end"], ["punctuation", "{"],
["keyword", "foobar"], ["punctuation", "}"],
["function", "\\ref"], ["punctuation", "{"],
["keyword", "foobar"], ["punctuation", "}"],
["function", "\\cite"], ["punctuation", "{"],
["keyword", "foobar"], ["punctuation", "}"],
["function", "\\label"], ["punctuation", "{"],
["keyword", "foobar"], ["punctuation", "}"],
["function", "\\usepackage"], ["punctuation", "{"],
["keyword", "foobar"], ["punctuation", "}"],
["function", "\\documentclass"],
["punctuation", "["], "11px,twoside,a4paper", ["punctuation", "]"],
["punctuation", "{"],
["keyword", "foobar"], ["punctuation", "}"]
]

----------------------------------------------------

Checks for keywords.
13 changes: 0 additions & 13 deletions tests/languages/latex/selector_feature.test

This file was deleted.

15 changes: 0 additions & 15 deletions tests/languages/latex/string_feature.test

This file was deleted.

12 changes: 12 additions & 0 deletions tests/languages/latex/url_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\url{http://prismjs.com}

----------------------------------------------------

[
["function", "\\url"], ["punctuation", "{"],
["url", "http://prismjs.com"], ["punctuation", "}"]
]

----------------------------------------------------

Checks for URLs.

0 comments on commit 942a6ec

Please sign in to comment.