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