Skip to content

Instantly share code, notes, and snippets.

@tarleb
Last active October 30, 2021 12:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tarleb/3bcb5a566fbec7f2d59adcd2b4b88b53 to your computer and use it in GitHub Desktop.
Save tarleb/3bcb5a566fbec7f2d59adcd2b4b88b53 to your computer and use it in GitHub Desktop.
Reimplementation of pandoc-sitenote by @jez as Lua filter
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
if inline_content[1] and inline_content[1].text == '{-}' then
nonu = true
table.remove(inline_content, 1)
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