* Match \pagebreak in commonmark_x+sourcepos
@ 2022-11-28 19:42 Duncan Murdoch
0 siblings, 0 replies; only message in thread
From: Duncan Murdoch @ 2022-11-28 19:42 UTC (permalink / raw)
To: pandoc-discuss
R Markdown normally uses Pandoc Markdown with the raw_tex extension, so
text like
\pagebreak
is recognized as Latex, and translated to a different format by the
pagebreak.lua filter here:
https://github.com/rstudio/rmarkdown/blob/main/inst/rmarkdown/lua/pagebreak.lua
That filter relies on the fact that the \pagebreak has already become a
single RawBlock.
This filter doesn't work with commonmark_x+sourcepos, because that
reader outputs this from \pagebreak in the source:
Div
( "" , [] , [ ( "data-pos" , "test.knit.md@27:3-28:1" ) ] )
[ Para
[ Span
( ""
, []
, [ ( "data-pos" , "test.knit.md@27:3-27:4" ) ]
)
[ Str "\\" ]
, Span
( ""
, []
, [ ( "data-pos" , "test.knit.md@27:4-27:13" ) ]
)
[ Str "pagebreak" ]
]
]
So it appears the test I need to use is to look for a Para containing
two Spans whose content is "\\" and "pagebreak", and replace that with
whatever is appropriate for the output. This function works, but I
wonder if it could be simplified:
function Para (el)
if #el.content == 2 and
el.content[1].content == pandoc.Span('\\').content and
(el.content[2].content == pandoc.Span('pagebreak').content or
el.content[2].content == pandoc.Span('newpage').content) then
return newpage(FORMAT)
end
end
Do I really need to construct those Spans to do the test? I'm happy it
works, but it seems like there should be simpler right hand sides in the
comparisons.
Duncan Murdoch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-28 19:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 19:42 Match \pagebreak in commonmark_x+sourcepos Duncan Murdoch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).