Create Custom Rmarkdown KnitR Markdown Flavor

So my work utilizes their own flavor of markdown and it would be really helpful if I could create Rmarkdown reports and have it knit to this specific flavor of markdown.

Would this be a task that R can handle (should handle? KnitR) or would this be a PR to a tool like pandoc?

Even if I could generate a Github Flavored Markdown and then have a script that goes in a changes specific things that would be awesome. Just trying to get some initial direction I should go in.

You can already generate GitHub Flavoured Markdown with

output: github_document

I believe.

This SO thread might also be of interest:

If I understand correctly you want knitr to generate from a RMD a specific .md file containing your specific flavor ? You don't need to go upto html generation ?
If so the trail would be in knit and how it parse chunk and insert them back into the file. No pandoc involved.

If you want to generate html or pdf, it is using pandoc to convert md to those format. So it would require that pandoc know your specific flavor.

Do you have more details or example on this ?

Hope it helps.

Yeah, so the general workflow would be something like write the .Rmarkdown and knit it to a specific flavor of markdown and then also knit it to a pdf with a specific LaTeX template (something I already know how to do). So since I don't need .html, you're saying I would need to write a specific function for KnitR and not pandoc?

I think there is still several approach.

have pandoc convert to your markdown flavor
It just supposition but you can also create custom output in PANDOC using LUA filters

Pandoc has a modular design: it consists of a set of readers, which parse text in a given format and produce a native representation of the document (an abstract syntax tree or AST), and a set of writers, which convert this native representation into a target format. Thus, adding an input or output format requires only adding a reader or writer. Users can also run custom pandoc filters to modify the intermediate AST.

See also custom writers.

Also check that pandoc does not already support your flavor through its variants and different options.

If you manage to do that, with the right configuration you could use rmarkdown and build a custom output format.

have knitr knit to your flavor

I think this would be possible, but I am not sure knitr exports all the tool required for that. It won't be documented, and you need to read the code.

Note sure what is the best way to tackle. It is no so clear what it involves when dealing with specific flavoir.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.