summaryrefslogtreecommitdiff
path: root/.obsidian/plugins/obsidian-enhancing-export/lua/math_block.lua
blob: 380d96a977d729b40e9fd25e929536062ac19881 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
traverse = 'topdown'

math_block_text = nil
function process(el)

   -- MathBlock start or end
   if el.t == 'Str' and el.text == '$$' then
     if math_block_text == nil then            -- start
       math_block_text = ''
     else                                      -- end
       local math_block = pandoc.Math('DisplayMath', '\n' .. math_block_text .. '\n')
       math_block_text = nil
       return math_block
     end
     return {}
   end

  if math_block_text then
    if (el.t == 'RawInline' or el.t == 'RawBlock') and el.format == 'tex' then
      math_block_text = math_block_text .. el.text
      return {}
    elseif el.t == 'Str' then
      math_block_text = math_block_text .. el.text
      return {}
    elseif el.t == 'SoftBreak' or el.t == 'BulletList' then
      return {}
    end
  end
  return el
end

function RawInline(el) 
  return process(el)
end

function RawBlock(el) 
  return process(el)
end

function Str(el)
  return process(el)
end

function SoftBreak(el)
  return process(el)
end

function Header(el)
  return process(el)
end

function Para(el)
  return process(el)
end

function Plain(el)
  return process(el)
end

function BulletList(el)
  return process(el)
end