Simple markdown templating using shell commands
cat
files, please use https://github.com/campoy/embedmd instead.
Binaries
See Releases
Source
$ go get -v github.com/jpillora/md-tmpl
$ mk-tmpl
Usage: md-tmpl [options] [files...]
Options:
--preview, -p Enables preview mode. Displays all commands encountered.
--write, -w Write file instead of printing to standard out
--help, -h
Insert templates in the form:
<!--tmpl,options:command --><!--/tmpl-->
where command
is a shell command and option
s are listed below
chomp
- trims any trailing newline generated bycommand
code
- wraps the output ofcommand
in triple backticks
Create a foo.md
with a template tag
_Updated on <!--tmpl,chomp:date --><!--/tmpl-->_
Then you execute the templates and rewrite foo.md
with:
$ md-tmpl -w foo.md
Now, foo.md
should be:
_Updated on <!--tmpl,chomp:date -->Sun 31 Mar 2019 00:41:18 AEDT<!--/tmpl-->_
And appear will test display on Github, like:
Updated on Sun 31 Mar 2019 00:41:18 AEDT
- Dynamic examples (
cat examples/foo
) - Usage text (
prog --help
) - Update timestamps (
date
)
- Malicious tags. Commands are run by piping strings straight into
bash
. If you think someone has slipped arm -rf /
in one of your markdown files, you can view all nested commands with the--preview, -p
option. - Currently it has only been tested on Markdown hosted on Github (GFM).
- You cannot use
>
in your commands as it marks the end of the command by closing the tag, use>
instead.
Copyright © 2019 Jaime Pillora <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.