public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Duncan Murdoch <murdoch.duncan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Match \pagebreak in commonmark_x+sourcepos
Date: Mon, 28 Nov 2022 14:42:19 -0500	[thread overview]
Message-ID: <a6394f2c-d25b-d8d3-bb7b-66d3b550202b@gmail.com> (raw)

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


                 reply	other threads:[~2022-11-28 19:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6394f2c-d25b-d8d3-bb7b-66d3b550202b@gmail.com \
    --to=murdoch.duncan-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).