A light weight pre-processor for Pandoc. Target use case is JSON object documents rendered via Pandoc templates.
This is a proof-of-concept Go package which makes it easy to extend your Go application to incorporate Pandoc template processing. It includes the Go package and an example command line tool (cli).
The command line implementation is a proof of concept Pandoc pre-processor in Go. An example usage would be to process example.json JSON document using a Pandoc template called example.tpml.
pdtmpl example.tmpl < example.json > example.html
Here’s some simple use examples of the three functions supplied in the pdtmpl package.
Given a JSON Object document as a slice of bytes render formated output based on the Pandoc template example.tmpl
"example.json")
src, err := ioutil.ReadFile(if err != nil {
// ... handle error
}// options passed to Pandoc
string{}
opt := []"example.tmpl", opt)
src, err = pdtmpl.Apply(src, if err != nil {
// ... handle error
}"%s", src) fmt.Fprintf(os.Stdout,
Using an io.Reader
to retrieve the JSON content, process with the example.tmpl
template and write standard output
"example.json")
f, err := Open(if err != nil {
// ... handle error
}defer f.Close()
// options passed to Pandoc
string{}
opt := []"example.tmpl", opt)
src, err := pdtmpl.ReadAll(f, if err != nil {
// ... handle error
}"%s", src) fmt.Fprintf(os.Stdout,
Using an io.Reader
and io.Writer
to read JSON source from standard input and write the processed pandoc templated standard output.
// options passed to Pandoc
string{}
opt := []"example.tmpl", opt)
err := pdtmpl.ApplyIO(os.Stdin, os.Stdout, if err != nil {
// ... handle error
}
pdtmpl
make
make install
git clone https://github.com/rsdoiel/pdtmpl
cd pdtmpl
make
make install
NOTE: This recipe assumes’ you are familar with setting up a Go development environment (e.g. You’ve set GOPATH environment appropriately). See the go website for details about setting up and compiler programs.
BSD 3-Clause License
Copyright (c) 2022, R. S. Doiel All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.