add latex support
This commit is contained in:
parent
cec4c65edf
commit
3d522f7f24
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,3 +1,5 @@
|
|||
__pycache__/
|
||||
music/
|
||||
/music/
|
||||
*.ttf
|
||||
/static/fonts
|
||||
/static/katex.min.css
|
||||
|
|
|
|||
8
Makefile
8
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 & \
|
||||
|
|
|
|||
21
build.py
21
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)}
|
||||
---
|
||||
<div class="container">
|
||||
<article class="panel">
|
||||
|
|
|
|||
12
shell.nix
12
shell.nix
|
|
@ -7,6 +7,17 @@ pkgs.mkShell {
|
|||
python311Packages.mutagen
|
||||
python311Packages.flask
|
||||
python311Packages.beautifulsoup4
|
||||
(python311Packages.buildPythonPackage rec {
|
||||
pname = "markdown-katex";
|
||||
version = "202406.1035";
|
||||
src = pkgs.fetchurl {
|
||||
url = "https://files.pythonhosted.org/packages/f4/34/780748d7d78fb4024dd1a290844374dd0d9830da35593c534638a4e9e54e/markdown_katex-202406.1035-py2.py3-none-any.whl";
|
||||
hash = "sha256-wXE+hYVN3stkGtliQ6i2zWc2e/G/jTm0OzaA1/KxiE0=";
|
||||
};
|
||||
format = "wheel";
|
||||
doCheck = false;
|
||||
})
|
||||
python311Packages.latex2mathml
|
||||
(python311Packages.buildPythonPackage rec {
|
||||
pname = "minify-html";
|
||||
version = "0.15.0";
|
||||
|
|
@ -27,5 +38,6 @@ pkgs.mkShell {
|
|||
python311
|
||||
nginx
|
||||
inotify-tools
|
||||
nodePackages.katex
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue