r-lib / downlit

Syntax Highlighting and Automatic Linking
https://downlit.r-lib.org
Other
90 stars 22 forks source link

consider --standalone output #123

Open tjmahr opened 3 years ago

tjmahr commented 3 years ago

According to the pandoc documentation, yaml metadata is only written to markdown output if --standalone is used:

When pandoc is used with -t markdown to create a Markdown document, a YAML metadata block will be produced only if the -s/--standalone option is used. All of the metadata will appear in a single block at the beginning of the document.

As a result, downlit::downlit_md_path() discards YAML metadata when run on markdown files. This prevents me from performing markdown -> downlit -> markdown conversions.

The result of setting --standalone is:

When the -s/--standalone option is used, pandoc uses a template to add header and footer material that is needed for a self-standing document. To see the default template that is used, just type pandoc -D *FORMAT*

If I call system2(rmarkdown::pandoc_exec(), "-D gfm") or system2(rmarkdown::pandoc_exec(), "-D markdown_github"), I get a barebones template which should not otherwise affect the md output.

$if(titleblock)$
$titleblock$

$endif$
$for(header-includes)$
$header-includes$

$endfor$
$for(include-before)$
$include-before$

$endfor$
$if(toc)$
$table-of-contents$

$endif$
$body$
$for(include-after)$

$include-after$
$endfor$
JosiahParry commented 6 months ago

I am running into similar issue here except in the context of HTML. I am using downlit to add autolinking to a rendered html document. It is only a partial html file but downlit adds the <html><body> tags

This is an excerpt of my current code. The output of pandoc does not have the tags, but using downlit adds them.

# render the section alone
rmarkdown::render(
  tmp,
  rmarkdown::github_document(),
  out_md
)

tmp_out <- tempfile(fileext = ".html")

# convert to html
pandoc::pandoc_convert(
  out_md,
  to = "html",
  output = tmp_out,
  standalone = FALSE
) 

# apply auto-linking
downlit::downlit_html_path(
  tmp_out,
  tmp_out,
  downlit::classes_pandoc()
)