Consider this markdown file:
#
This is text below a h1 header
##
This is text below a h2 header
#
This is text below a h1 header
##
This is text below a h2 header
I wonder if it would be possible to grab content below a h1 header and put it in a latex environment A and content below a h2 header in environment B using a lua filter.
Something like this:
function Header(el)
local beginEnv, endEnv
if ( el.level == 1 ) then
beginEnv = "\\begin{A}"
endEnv = "\\end{A}"
elseif ( el.level == 2 ) then
beginEnv = "\\begin{B}"
endEnv = "\\end{B}"
end
-- grab all of the content below the respective header
-- in the case of the h1 header it should be: "This is text below a h1 header"
-- in the case of the h2 header it should be: "This is text below a h2 header"
local contentBelowHeader = ???
table.insert( contentBelowHeader, 1, pandoc.RawBlock("latex", beginEnv .. "\n" ))
table.insert( contentBelowHeader, pandoc.RawBlock("latex", "\n" .. endEnv ))
return el
end
The output should be something like (tex file):
...
\begin{A}
This is text below a h1 header
\end{A}
\begin{B}
This is text below a h2 header
\end{B}
\begin{A}
This is text below a h1 header
\end{A}
\begin{B}
This is text below a h2 header
\end{B}
...