This gists shows a little idea: use Pandoc to format data into HTML, or any other output format supported by Pandoc. This uses the ability of Pandoc to uses templates, and to receive data as YAML either from a separate file, or within a metadata block contained in the document itself..
It also shows a few scripts to use other data formats than YAML and extract metadata blocks as JSON. Note that multiple metadata blocks can be present within a single document.
The document.md
file contains data in its metadata YAML block and is its own
template:
$ pandoc --template document.md document.md
---
title: The document title
host:
- name: host-1
ip: 172.17.0.1
- name: host-2
ip: 172.17.0.2
---
Some hosts:
- host-1: 172.17.0.1
- host-2: 172.17.0.2
The result is a normal Markdown document that can be processed with Pandoc as usual, e.g. to produce an HTML page.
The data can also come from an external file (here, hosts.yml
):
$ pandoc --template document.md hosts.yml document.md
---
title: The document title
host:
- name: host-1
ip: 172.17.0.1
- name: host-2
ip: 172.17.0.2
---
Some hosts:
- host-1: 172.17.0.1
- host-2: 172.17.0.2
- host-3: 172.17.0.3
Note: here the hosts
key in the metadata provided by document.md
is not
used because Pandoc is left-biased when merging multiple metadata blocks.
Several scripts are provided to use other data format. For instance:
- From
hosts.json
(one object per line) to CSV, - From CSV to a Sqlite database,
- From a Sqlite database to JSON again (a list of objects),
- From a Sqlite database to YAML (using the previous script).
This shows that the data rendered by Pandoc can come from Sqlite with minimal efforts.
It is also possible to extract the data "stored" within a metadata block by
using a dedicated template (here, metadata.tpl
):
$ pandoc --template metadata.tpl document.md
{"title":"The document title","host":[{"ip":"172.17.0.1","name":"host-1"},{"ip":"172.17.0.2","name":"host-2"}]}