pd-ref-filter.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. -- Generate string
  2. local function split_prepend_ref(inputstr)
  3. local t = '['
  4. for str in inputstr:gmatch('([^,]+)') do
  5. if t ~= '[' then
  6. t = t..';'
  7. end
  8. t = t..'@'..str:gsub('^%s*', ''):gsub('%s*$', '')
  9. end
  10. t = t..']'
  11. return t
  12. end
  13. if FORMAT:match 'markdown' then
  14. function Link(elem)
  15. if elem.attributes.reference then
  16. return pandoc.RawInline('markdown', split_prepend_ref(elem.attributes.reference))
  17. -- return pandoc.RawInline('markdown', '{+@' ..elem.attributes.reference .. '}')
  18. else
  19. return elem
  20. end
  21. end
  22. end
  23. if FORMAT:match 'markdown' then
  24. function Math(elem)
  25. if elem.mathtype == "DisplayMath" then
  26. if elem.text:find("\\label") then
  27. for label in elem.text:gmatch("\\label{(.-)}") do
  28. elem.text = elem.text:gsub("\\label{"..label.."}", "")
  29. return pandoc.RawInline('markdown', "$$"..elem.text.."$$".." {#"..label.."}")
  30. end
  31. end
  32. end
  33. -- tprint(elem, 4)
  34. end
  35. end
  36. -- Print contents of `tbl`, with indentation.
  37. -- `indent` sets the initial level of indentation.
  38. function tprint(tbl, indent)
  39. if not indent then indent = 0 end
  40. for k, v in pairs(tbl) do
  41. formatting = string.rep(" ", indent) .. k .. ": "
  42. if type(v) == "table" then
  43. print(formatting)
  44. tprint(v, indent+1)
  45. elseif type(v) == 'boolean' then
  46. print(formatting .. tostring(v))
  47. else
  48. print(formatting .. v)
  49. end
  50. end
  51. end