Easiest way to replace placeholders (variables) in markdown text?

怎甘沉沦 提交于 2021-02-07 14:20:30

问题


I have need for an open format to write stories in a generic way (with placeholder/variables). To make the stories case specific I would like to set a list of key/value pairs and apply them when publishing. I also want to separate styling from content so I can easily publish to web, pdf etc.

Example: @varname@ is a great place.

I chose Markdown to solve the content/styling separation but I do not know an easy way to parameterize certain parts of the text and have them filled in when I generate the html/pdf outputs with a tool like pandoc.

Any suggestions? Can this be done with markdown or is there a suitable markdown extension?


回答1:


Personally, I'd use something like sed, or even funnelweb, but you could do it with a pandoc filter, either in haskell or (probably easier) with the pandocfilters python library available here




回答2:


For the web, you could use Jekyll templates with Liquid. Complex expressions surrounded by double braces {{}} are interpreted when converting to HTML. Example (from the link):

{{ site.time | date_to_string }}

07 Nov 2008

I think it's possible to define custom variables, too.



来源:https://stackoverflow.com/questions/24499398/easiest-way-to-replace-placeholders-variables-in-markdown-text

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