Skip to content

Adding support for reveal.js - #17

Open
osorensen wants to merge 5 commits into
leovan:mainfrom
osorensen:fix/revealjs-rendering
Open

osorensen wants to merge 5 commits into
leovan:mainfrom
osorensen:fix/revealjs-rendering

Conversation

@osorensen

Copy link
Copy Markdown

Thanks for a nice package. I was making a Revealjs presentation and realized that some additional functionality had to be added for the algorithms to show properly.

This PR contains the necessary additions to the source code that I need to make for this to work properly, including an example.

pandoc.Div(source_code) was being called with a plain Lua string.
Pandoc treats that string as ordinary prose text, which collapses all
whitespace (newlines, indentation, repeated spaces) down to single
spaces before the HTML writer emits it. The algorithm's original line
structure is lost in the rendered <div class="pseudocode"> element.

Wrap the source in a pandoc.RawBlock("html", ...) instead (with the
minimal HTML-entity escaping pandoc would otherwise have applied),
so the exact source text -- including line breaks and indentation --
reaches pseudocode.js unchanged.
…errors

The render call previously ran exactly once, synchronously, at the
point this inline script executes in the page. In a revealjs
presentation that timing is not guaranteed to line up with Reveal's
own initialization, and a rendering failure was silently swallowed
(the block just stayed blank with no indication anything went wrong).

Guard each container with a data-pseudocode-rendered flag and also
re-run the render pass on Reveal's "ready" and "slidechanged" events.
This mirrors the pattern reveal.js's own bundled MathJax/KaTeX plugins
use (see plugin/math/math.js and plugin/math/katex.js) to re-typeset
content relative to slide readiness.

Also wrap the render call in try/catch and print any error onto the
slide/page in place of the algorithm, instead of failing silently, so
a malformed pseudocode block is visibly broken rather than just
missing with no diagnostic.
There was no example demonstrating the extension in a revealjs
presentation. Add examples/revealjs/revealjs.qmd (with the standard
_extensions symlink used by the other example directories) with the
algorithm on a non-title slide, and link it from the README's example
list alongside the existing single/book/beamer/cross-reference
examples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant