diff --git a/wiki/.gitignore b/wiki/.gitignore index 2d19fc7..eececad 100644 --- a/wiki/.gitignore +++ b/wiki/.gitignore @@ -1 +1,2 @@ *.html +*.txt diff --git a/wiki/Makefile b/wiki/Makefile index afb9c6a..662a26f 100644 --- a/wiki/Makefile +++ b/wiki/Makefile @@ -1,10 +1,10 @@ SRC_MD_FILES != find source -name '*.md' DST_HTML_FILES := $(SRC_MD_FILES:source/%.md=%.html) - +DST_TXT_FILES := $(SRC_MD_FILES:source/%.md=%.txt) PANDOC != command -v pandoc 2> /dev/null PHP != command -v php 2> /dev/null -all: dep-pandoc $(DST_HTML_FILES) index +all: dep-pandoc $(DST_HTML_FILES) $(DST_TXT_FILES) index index: dep-php index.html %.html: %.php @@ -24,9 +24,20 @@ index: dep-php index.html --output $@ \ $< +%.txt: source/%.md link_footnote.lua + $(info building $@) + @$(PANDOC) \ + --from markdown+backtick_code_blocks \ + --to plain \ + --lua-filter ./link_footnote.lua \ + --standalone \ + --output $@ \ + $< + clean: $(info removing generated files) -rm $(DST_HTML_FILES) + -rm $(DST_TXT_FILES) dep-pandoc:: ifndef PANDOC diff --git a/wiki/link_footnote.lua b/wiki/link_footnote.lua new file mode 100644 index 0000000..80307b2 --- /dev/null +++ b/wiki/link_footnote.lua @@ -0,0 +1,18 @@ +links = {} + +function Link (el) + table.insert(links, + pandoc.Para({ + pandoc.Str("[" .. (#links + 1) .. "]"), + pandoc.Space(), + pandoc.Str(el.target), + }) + ) + table.insert(el.content, pandoc.Str("[" .. #links .. "]")) + return el.content +end + +function Pandoc (doc) + table.insert(doc.blocks, pandoc.Div(links)) + return pandoc.Pandoc(doc.blocks, doc.meta) +end \ No newline at end of file