diff --git a/.gitignore b/.gitignore index 36e99fc..c14e1fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ __pycache__/ -music/ +/music/ *.ttf +/static/fonts +/static/katex.min.css diff --git a/Makefile b/Makefile index f4d8eb3..e4f1696 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ OUT=/tmp/2h FLAGS= CTF=$(patsubst %.md,$(OUT)/%.html,$(wildcard ctf/**/*.md)) +KATEX_PATH=$(shell nix path-info nixpkgs#nodePackages.katex)/lib/node_modules/katex/dist + all: $(OUT) $(OUT)/ctf $(CTF) $(OUT): pages templates static rootstatic build.py static/songlist.json build.py static/highlight.css @@ -23,6 +25,12 @@ static/songlist.json: music build.py static/highlight.css: build.py python build.py highlight $(FLAGS) +static/katex.min.css: + ln -sf "$(KATEX_PATH)"/katex.min.css static/katex.min.css + +static/fonts: + ln -sf "$(KATEX_PATH)"/fonts static/fonts + server: all @trap 'kill 0' SIGINT; \ flask run & \ diff --git a/build.py b/build.py index d3476a0..ba94f1d 100644 --- a/build.py +++ b/build.py @@ -114,19 +114,32 @@ def format_tags(tags): def md_to_html(path): import markdown from markdown.extensions.codehilite import CodeHiliteExtension - from markdown.extensions.tables import TableExtension import frontmatter input = frontmatter.load(path) + import markdown_katex.extension + import markdown_katex.wrapper + ext = ['fenced_code', 'toc', 'tables', 'markdown_katex'] + markdown_katex.extension.KATEX_STYLES = '' + sheets = ['/static/highlight.css'] if minimal: - ext = ['fenced_code', 'toc', TableExtension()] + import latex2mathml.converter + def convert(t, _): + return latex2mathml.converter.convert(t) + markdown_katex.wrapper.tex2html = convert else: - ext = ['fenced_code', CodeHiliteExtension(css_class='hl'), 'toc', TableExtension()] + real = markdown_katex.wrapper.tex2html + def convert(*args): + sheets.append('/static/katex.min.css') + markdown_katex.wrapper.tex2html = real + return real(*args) + markdown_katex.wrapper.tex2html = convert + ext.append(CodeHiliteExtension(css_class='hl')) if 'toc' in input: input.content = '[TOC]\n' + input.content html = markdown.markdown(input.content, extensions=ext) return f'''--- title: {repr(input['title'])} -sheets: ["/static/highlight.css"] +sheets: {repr(sheets)} ---