Skip to content

Commit

Permalink
Add a test using a markdownit renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser committed Mar 3, 2023
1 parent 097cc09 commit 69ae7f8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
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')

0 comments on commit 69ae7f8

Please sign in to comment.