Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ARG VERSION
ADD LICENSE /slidefactory/
ADD fonts/ /slidefactory/fonts/
ADD theme/ /slidefactory/theme/
ADD filters/ /slidefactory/filters/
ADD slidefactory.py /slidefactory/

# Remove possible temporary files
Expand Down Expand Up @@ -90,6 +91,12 @@ RUN wget https://github.com/jgm/pandoc/releases/download/2.19.2/pandoc-2.19.2-1-
dpkg -i tmp.deb && \
rm -f tmp.deb

# Pagefind (static search index builder, used by the `pages` sub-command)
RUN wget https://github.com/Pagefind/pagefind/releases/download/v1.5.2/pagefind-v1.5.2-x86_64-unknown-linux-musl.tar.gz -O tmp.tar.gz && \
tar xzf tmp.tar.gz -C /usr/bin pagefind && \
chmod 755 /usr/bin/pagefind && \
rm -f tmp.tar.gz

# Chromium
RUN apt-get update -qy && \
apt-get install -qy --no-install-recommends \
Expand Down
33 changes: 33 additions & 0 deletions filters/duplicate_heading_ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# ------------------------------------------------------------------------- #
# Function: Pandoc JSON filter that gives each slide heading its own `id` #
# attribute, matching the identifier pandoc's reveal.js writer #
# already puts on the wrapping <section>. #
# ------------------------------------------------------------------------- #
#
# Pandoc's reveal.js writer moves a Header's identifier onto the wrapping
# <section> and omits it from the <hN> tag itself. Pagefind's automatic
# per-slide search anchors only recognize (non-empty) heading elements that
# carry their own id, so without this every search hit would link to the
# deck's first slide instead of the one that actually matched.
#
# Any other key-value attribute on a Header (unlike the identifier) is
# passed straight through onto both the <section> and the <hN> tag, so
# adding a plain "id" key-value pair here - separate from the special
# identifier field - is enough to make pandoc's own writer put a real `id`
# directly on the heading tag, with no HTML post-processing required.
from pandocfilters import toJSONFilter, Header


def duplicate_heading_id(key, value, format, meta):
if key != 'Header':
return None
level, attr, inlines = value
identifier, classes, keyvals = attr
if identifier and not any(k == 'id' for k, v in keyvals):
keyvals = keyvals + [['id', identifier]]
return Header(level, [identifier, classes, keyvals], inlines)


if __name__ == '__main__':
toJSONFilter(duplicate_heading_id)
Loading