问题
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