diff --git a/Makefile b/Makefile index f1610019042cbb2b5db4b4c241c9c463d805cb57..badebe2a05fdac9b88700c92c481b7b202e2644c 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,8 @@ motivation.html : motivation.md _layouts/slides.html %.html : %.md _layouts/page.html pandoc -s -t html \ --template=_layouts/page \ - --filter=tools/blockquote2div.py \ + --filter=tools/filters/blockquote2div.py \ + --filter=tools/filters/id4glossary.py \ $(INCLUDES) \ -o $@ $< diff --git a/tools/blockquote2div.py b/tools/filters/blockquote2div.py similarity index 100% rename from tools/blockquote2div.py rename to tools/filters/blockquote2div.py diff --git a/tools/filters/id4glossary.py b/tools/filters/id4glossary.py new file mode 100755 index 0000000000000000000000000000000000000000..686cfa1d99f87b93c8a1d2a2ac03c488846dd7c8 --- /dev/null +++ b/tools/filters/id4glossary.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +"""Pandoc filter to convert add ids to glossary entries. + +Usage: + + pandoc source.md --filter=id4glossary.py --output=output.html +""" +import pandocfilters as pf + +def normalize_keyword(keyword): + """Normalize keyword for became id + + - Replace white space with '-' + - Convert to lowercase""" + return keyword.lower().replace(' ', '-') + +def keyword2html(keyword_node): + """Return HTML version of keyword with id.""" + keyword = pf.stringify(keyword_node) + id = normalize_keyword(keyword) + return [{"t": "Span", + "c": [[id, [],[]], + keyword_node]}] + +def id4glossary(key, value, format, meta): + """Add id to keywords at glossary.""" + if "subtitle" in meta and pf.stringify(meta['subtitle']) == 'Reference': + if key == "DefinitionList": + for definition in value: + definition[0] = keyword2html(definition[0]) + return {"t": key, + "c": value} + +if __name__ == '__main__': + pf.toJSONFilter(id4glossary)