7272function Span (el )
7373 if el .classes and el .classes :includes (" arithmatex" ) then
7474 local text = pandoc .utils .stringify (el .content )
75- text = text :gsub (" ^%s*%[" , " " ):gsub (" %]%s*$" , " " ) -- 去 []
75+ -- 更加激进地清理公式前后的各种包装符号
76+ text = text :gsub (" ^%s*[\\ %[%(%$%]]+" , " " ):gsub (" [\\ %]%)%$%s]+$" , " " )
7677 text = unescape_math (text )
77- return pandoc .Math (" InlineMath" , text )
78+ -- 确保是单 $ 包裹
79+ return pandoc .RawInline (" markdown" , " $" .. text .. " $" )
7880 end
7981end
8082
@@ -85,7 +87,9 @@ function Div(el)
8587 local text = pandoc .utils .stringify (el .content )
8688 text = text :gsub (" ^%s*[$]+" , " " ):gsub (" [$]+%s*$" , " " )
8789 text = unescape_math (text )
88- return pandoc .Math (" DisplayMath" , text )
90+ -- 修复 $$ 与内容之间的换行。
91+ -- 如果直接写 "\n\n" 会导致多余空行,这里使用 "\n"
92+ return pandoc .RawBlock (" markdown" , " $$\n " .. text .. " \n $$" )
8993 end
9094
9195 -- 识别 callout 类型
@@ -137,6 +141,12 @@ function Div(el)
137141 return pandoc .RawBlock (" markdown" , full_md )
138142 end
139143
144+ -- 处理多余的容器(如 .grid 或 .v-pre 等非语义化 Div)
145+ -- 如果 Div 只有渲染意义而用户不希望在 Markdown 中保留 ::: {.grid}
146+ if el .classes and (el .classes :includes (" grid" ) or el .classes :includes (" v-pre" )) then
147+ return el .content
148+ end
149+
140150 return el
141151end
142152
0 commit comments