mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 18:46:57 +02:00
feat(theme-common): code block MagicComments support for TeX/LaTeX/Matlab (#8982)
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
This commit is contained in:
parent
4f3901b932
commit
30a4181290
2 changed files with 35 additions and 2 deletions
|
@ -21,6 +21,7 @@ const commentPatterns = {
|
||||||
html: {start: '<!--', end: '-->'},
|
html: {start: '<!--', end: '-->'},
|
||||||
lua: {start: '--', end: ''},
|
lua: {start: '--', end: ''},
|
||||||
wasm: {start: '\\;\\;', end: ''},
|
wasm: {start: '\\;\\;', end: ''},
|
||||||
|
tex: {start: '%', end: ''},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommentType = keyof typeof commentPatterns;
|
type CommentType = keyof typeof commentPatterns;
|
||||||
|
@ -85,6 +86,11 @@ function getAllMagicCommentDirectiveStyles(
|
||||||
// Text uses HTML, front matter uses bash
|
// Text uses HTML, front matter uses bash
|
||||||
return getCommentPattern(['html', 'jsx', 'bash'], magicCommentDirectives);
|
return getCommentPattern(['html', 'jsx', 'bash'], magicCommentDirectives);
|
||||||
|
|
||||||
|
case 'tex':
|
||||||
|
case 'latex':
|
||||||
|
case 'matlab':
|
||||||
|
return getCommentPattern(['tex'], magicCommentDirectives);
|
||||||
|
|
||||||
case 'lua':
|
case 'lua':
|
||||||
case 'haskell':
|
case 'haskell':
|
||||||
case 'sql':
|
case 'sql':
|
||||||
|
@ -94,10 +100,11 @@ function getAllMagicCommentDirectiveStyles(
|
||||||
return getCommentPattern(['wasm'], magicCommentDirectives);
|
return getCommentPattern(['wasm'], magicCommentDirectives);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// All comment types except lua and wasm
|
// All comment types except lua, wasm and matlab
|
||||||
return getCommentPattern(
|
return getCommentPattern(
|
||||||
Object.keys(commentPatterns).filter(
|
Object.keys(commentPatterns).filter(
|
||||||
(pattern) => !['lua', 'wasm'].includes(pattern),
|
(pattern) =>
|
||||||
|
!['lua', 'wasm', 'tex', 'latex', 'matlab'].includes(pattern),
|
||||||
) as CommentType[],
|
) as CommentType[],
|
||||||
magicCommentDirectives,
|
magicCommentDirectives,
|
||||||
);
|
);
|
||||||
|
|
|
@ -322,3 +322,29 @@ WHERE customer_id IN (
|
||||||
WHERE country = 'USA'
|
WHERE country = 'USA'
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```matlab title="matlab.m"
|
||||||
|
% highlight-start
|
||||||
|
function result = times2(n)
|
||||||
|
result = n * 2;
|
||||||
|
end
|
||||||
|
% highlight-end
|
||||||
|
|
||||||
|
x = 10;
|
||||||
|
% highlight-next-line
|
||||||
|
y = times2(x);
|
||||||
|
```
|
||||||
|
|
||||||
|
```latex title="latex.tex"
|
||||||
|
\begin{document}
|
||||||
|
\section{Triangles}
|
||||||
|
% highlight-next-line
|
||||||
|
\subsection{Pythagoras' Theorem}
|
||||||
|
Pythagoras's theorem is:
|
||||||
|
% highlight-start
|
||||||
|
\begin{equation}
|
||||||
|
c^2 = a^2 + b^2
|
||||||
|
\end{equation}
|
||||||
|
% highlight-end
|
||||||
|
\end{document}
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue