pikchr-cmd

Pikchr Command-Line Tool

This preprocessor tool reads text from the standard input, replacing suitably-delimited Pikchr (a PIC-like diagram language) diagram descriptions with inline Scalable Vector Graphics (SVG), and writes to the standard output. It’s intended to be composed with your favorite Markdown processor, but can be used standalone or with other markup languages or workflows too.

This tool uses the C reference implementation of Pikchr by Richard Hipp which is included here for convenience (as permitted by its generous license).

Markdown+Pikchr Source pikchr Preprocessor (main.c) Markdown+SVG Intermediate Any Markdown Formatter HTML+SVG Output  C API Pikchr Formatter (pikchr.c)
``` pikchr @usage requote delimiters x-current-color
arrow right 225% "Markdown+Pikchr" "Source"
Tool: box rad 5px "pikchr" mono "Preprocessor" "(main.c)" mono fit
arrow same "Markdown+SVG" "Intermediate"
box same "Any Markdown" "Formatter" fit height Tool.height
arrow same "HTML+SVG" "Output"
arrow <-> down from Tool.south " C API" ljust
box same "Pikchr" "Formatter" "(pikchr.c)" mono fit
```

GitHub doesn’t allow inline SVGs, so here’s the above diagram as an external image reference (see Example 3 below):

Example 1: Pipeline

$ pikchr < file.md | Markdown.pl > file.html

Example 2: Intermediate file

$ pikchr < README.md.in > README.md
$ Markdown.pl < README.md > README.html

Example 3: Compile the diagram in README.md.in that is tagged with modifier “@usage” to a separate SVG file called usage.svg

$ pikchr -q -b -N @usage < README.md.in > usage.svg

Delimiters

A Pikchr diagram starts with a line beginning with any of the following strings without indentation:

and ends with the next line that is any of the following strings without indentation (or the end of the file):

Anything not between a pair of start and end delimiters is copied to the standard output unchanged.

Note that generic Markdown fenced code blocks can begin with three or more consecutive TILDE (~) or backtick (`) characters optionally indented by up to three spaces, and continue to a fence of the same type (tilde or backtick), optionally indented by up to three spaces, and at least as long. For simplicity, when looking for Pikchr diagrams, this tool doesn’t require the end delimiter to be of the same type or to be at least as long as the start delimiter. This tool doesn’t recognize indented start and end delimiters in order to easily accommodate displaying Pikchr code itself by using an indented fenced code block.

Start Delimiter Modifiers

Any number of whitespace-delimited modifier strings can follow the start delimiter prefix on the same line. Modifiers can change the behavior of the Pikchr formatter for just that diagram. Unrecognized modifiers are ignored, but can be matched by the -N command-line option (use -h to see all of the available options). The following modifiers are recognized:

Building

$ git clone https://github.com/zenomt/pikchr-cmd
$ cd pikchr-cmd
$ make all
$ ./pikchr -h

Command Line Options

The following command line options are recognized: