Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added markdown_it_renderer.py
Empty file.
25 changes: 23 additions & 2 deletions templates/base.j2
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ StackOverflow link on why to avoid \(..\) and \[..\] when markdown is in the loo
<script>
MathJax = {
tex: {
inlineMath: [['$', '$']],
displayMath: [['$$', '$$']]
inlineMath: [],
displayMath: [],
processEnvironments: false,
procesRefs: false,
processEscapes: false,
},
options: {
skipHtmlTags: [
Expand All @@ -70,6 +73,24 @@ MathJax = {
],
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process',
renderActions: {
find: [10, function (doc) {
for (const node of document.querySelectorAll('.math.inline')) {
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], false);
let text = node;
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
}
for (const node of document.querySelectorAll('.math.block')) {
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], true);
let text = node;
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
}
}, '']
}
},
};

Expand Down
34 changes: 34 additions & 0 deletions test/test_latex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from markdown_it import MarkdownIt
from mdit_py_plugins.dollarmath import dollarmath_plugin
import sys
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, select_autoescape

import html
# can be removed if we make `print_docs` an installable module
sys.path.append(str(Path(__file__).parent.parent))

md = (
MarkdownIt('commonmark' ,{'breaks':True,'html':True})
.use(dollarmath_plugin)
.enable('table')
)

env = Environment(
loader=FileSystemLoader('templates', 'utf-8'),
autoescape=select_autoescape(['html', 'xml'])
)

def write_pure_md_file(source, dest, name):
with open(source) as infile:
body = md.render(infile.read())

with open(dest, 'w') as out:
out.write(env.get_template('pure_md.j2').render(
active_path = '',
name = name,
body = body,
))


write_pure_md_file('test/latex.md', 'latex.html', 'LaTeX test')