summaryrefslogtreecommitdiff
path: root/_extensions/js/ingress/ingress.lua
blob: 1f584b6b74bb8cfdf5177aece8844dba0e866275 (plain)
  1. -- Translate div class .lead to custo LaTeX environment \ingress{}
  2. local function escape_latex(str)
  3. local replacements = {
  4. ["\\"] = "\\textbackslash{}",
  5. ["{"] = "\\{",
  6. ["}"] = "\\}",
  7. ["$"] = "\\$",
  8. ["&"] = "\\&",
  9. ["#"] = "\\#",
  10. ["_"] = "\\_",
  11. ["%"] = "\\%",
  12. ["^"] = "\\textasciicircum{}",
  13. ["~"] = "\\textasciitilde{}"
  14. }
  15. return (str:gsub(".", function(c)
  16. return replacements[c] or c
  17. end))
  18. end
  19. function Div(el)
  20. if el.classes:includes('lead') then
  21. local content = pandoc.utils.stringify(el.content)
  22. local escaped_content = escape_latex(content)
  23. return pandoc.RawBlock('latex', '\\ingress{' .. escaped_content .. '}')
  24. end
  25. end