Defining custom Markdown syntax in RMarkdown / pander

▼魔方 西西 提交于 2020-02-25 06:29:46

问题


In Markdown / RMarkdown, **this** is translated to bold, _this_ is cursive etc.

Is it possible to create a custom syntax? For example, that -this- (a word between two dashes) gets translated to something I define myself (via css for html and latex for pdf)?


回答1:


Document parsing is done by pandoc. For this kind of customization, one would have to customize pandoc's Markdown reader (written in Haskell), and then use the self-compiled binary for knitting.

One way to get close to having custom elements is to use spans ([like so]{.example}) or raw LaTeX (\foo{text}) in combination with Lua filters. You can then convert specific spans to any output you like. See, e.g., this answer about how to support \textcolor for HTML output.

See also this beautiful technique by John MacFarlane, the author of pandoc.



来源:https://stackoverflow.com/questions/58697467/defining-custom-markdown-syntax-in-rmarkdown-pander

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!