Passing R Markdown YAML parameters without processing to back-end custom template

yaml

#1

Working on a new R Markdown template for the hrbrthemes package.

I want to bake-in support for Open Graph & Twitter meta tags with something like this (I’m not fully settled on the hierarchy but that doesn’t really matter for this q):

---
title: "The Ipsum R Markdown Experience"
ipsum_meta:
  twitter_card: "Summary info for the Twitter Card"
  twitter_site: "@sitehandle"
  twitter_creator: "@creatorhandle"
  og_url: "https://example.com/open/graph/finalURLfor/this"
  og_description: "A modest size description of the content"
  og_image: "https://example.com/open/graph/imageURLfor/this"
output: 
  hrbrthemes::ipsum:
    toc: true
---

on the custom HTML template site I’m trying to do:

$if(ipsum_meta)$
$if(ipsum_meta.twitter_card)$<meta name="twitter:card" content="$ipsum_meta.twitter_card$" />$endif$
$if(ipsum_meta.twitter_site)$<meta name="twitter:site" content="$ipsum_meta.twitter_site$" />$endif$
$if(ipsum_meta.twitter_creator)$<meta name="twitter:creator" content="$ipsum_meta.twitter_creator$" />$endif$
$if(ipsum_meta.og_url)$<meta property="og:url" content="$ipsum_meta.og_url$" />$endif$
$if(title)$<meta property="og:title" content="$ipsum_meta.title$" />$endif$
$if(ipsum_meta.og_description)$<meta property="og:description" content="$ipsum_meta.og_description$" />$endif$
$if(ipsum_meta.og_image)$<meta property="og:image" content="$ipsum_meta.og_image$" />$endif$
$endif$

but the @-bits and URLs end up looking like:

<meta name="twitter:card" content="Summary info for the Twitter Card" />
<meta name="twitter:site" content="&lt;span class=" citation" data-cites="sitehandle">@sitehandle</span>&quot; /&gt;
<meta name="twitter:creator" content="&lt;span class=" citation" data-cites="creatorhandle">@creatorhandle</span>&quot; /&gt;
<meta property="og:url" content="&lt;a href=" https: example.com open graph finalURLfor this" class="uri">https://example.com/open/graph/finalURLfor/this</a>&quot; /&gt;
<meta property="og:title" content />
<meta property="og:description" content="A modest size description of the content" />
<meta property="og:image" content="&lt;a href=" https: example.com open graph imageURLfor this" class="uri">https://example.com/open/graph/imageURLfor/this</a>&quot; /&gt;

and I just really need a pointer to the magic spells that tell the various components in the pass-down process to not process those strings. Google and SO have been no real help but I cld also be not searching well.

I shld note that what I’m ultimately trying to avoid is folks having to do:

---
title: "The Ipsum R Markdown Experience"
ipsum_meta:
  twitter_card: "Summary info for the Twitter Card"
  twitter_site: "\\@sitehandle"
  twitter_creator: "\\@creatorhandle"
  og_url: "https\\://example.com/open/graph/finalURLfor/this"
  og_description: "A modest size description of the content"
  og_image: "https\\://example.com/open/graph/imageURLfor/this"
output: 
  hrbrthemes::ipsum:
    toc: true
---

That works and leads me to believe that this is some pandoc PreEscape-ing vs rmarkdown pre-processing, but I’m just seeing if others ran into this.


#2

Tangentially-related at best: I’m not a big fan of pandoc’s templating macros so I toyed with the idea of processing an external yaml metadata file with R, and injecting the result (in the context of latex manuscripts, but the same idea would apply to ).


#3

Said macro “language” leaves much to be desired.

I’m of a similar mind that there’s likely going to be required interim processing to avoid ugly escaping.


#4

:pray: let us know what you end up doing. I love parameterised reports, but pandoc is giving me a heck of a time of late!


#5

From the manual, https://pandoc.org/MANUAL.html#metadata-blocks

all string scalars will be interpreted as Markdown.

This explains '@'s being changed to citations etc. Further it says:

Fields with names ending in an underscore will be ignored by pandoc. (They may be given a role by external processors.)

This might help, but is not very elegant… Another option could be to use the fact that

The pipe character (|) can be used to begin an indented block that will be interpreted literally, without need for escaping.

And prepend a | before each metadata field in the output format pre-processor (haven’t tested this)


#6

Thx. That does help quite a bit (and definitely looks pandoc-ish vs
something more easily r markdown code-workaround-able).I’m going to try the
| a bit later today.