-
-
Save op8867555/882d4cd4c526091a57803ea81bf3a5a6 to your computer and use it in GitHub Desktop.
Reimplementation of pandoc-sitenote by @jez as Lua filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local counter = 0 | |
function make_label(nonu) | |
local label_class = 'margin-toggle' .. (nonu and '' or ' sidenote-number') | |
local label_sym = nonu and '⊕' or '' | |
local label_html = string.format( | |
'<label for="sn-%d" class="%s">%s</label>', | |
counter, | |
label_class, | |
label_sym | |
) | |
return pandoc.RawInline('html', label_html) | |
end | |
function make_checkbox(nonu) | |
local input_html = string.format( | |
'<input type="checkbox" id="sn-%d" class="margin-toggle"/>', | |
counter | |
) | |
return pandoc.RawInline("html", input_html) | |
end | |
--- Convert footnotes into sidenotes | |
function Note (note) | |
local inline_content = pandoc.utils.blocks_to_inlines( | |
note.content, | |
{pandoc.LineBreak()} | |
) | |
local nonu = false | |
local first, first_idx = pandoc.List(inline_content):find_if(function (x) return x.t ~= 'Space' and x.t ~= 'SoftBreak' end, 1) | |
if first and first.text == '{-}' then | |
nonu = true | |
table.remove(inline_content, first_idx) | |
end | |
local label = make_label(nonu) | |
local input = make_checkbox(nonu) | |
local note_type_class = nonu and "marginnote" or "sidenote" | |
local note = pandoc.Span( | |
inline_content, | |
pandoc.Attr('', {note_type_class}, {}) | |
) | |
counter = counter + 1 | |
return {label, input, note} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment