Render ASCII art as SVG diagrams
From a chunky text-art input, render smooth, multi-colored SVG with embedded links.
Express your ideas in either of two input formats, subsets of well-known conventions:
Style graphics globally within your diagram, by specifying CSS files on the command line.
Style individual text strings, by referring to individual CSS rules from markup bracketing your text.
Most fixed-pitch or "monospace" Unicode fonts maintain a 2:1 aspect ratio for characters in the ASCII range,
On Ubuntu, satisfactory fonts are scarce -- perhaps the best is "DejaVu Sans Mono".
Graphical- or rectangle-oriented text editing capability, provided either by special modes within your text editor, or a specialized graphical editor. Your best option may depend upon whether you prefer to create diagrams with graphics expressed in ASCII or UTF-8 -- see the READMEs for some hints.
$ go install github.com/blampe/goat/cmd/goat@latest .------------.
o-->|Hello, world +--*
'------------'
╭────────────┐
○──►│Hello, world├─●
└────────────╯
Any number of .css files may be specified on the command line,
for inclusion within the output file's (single) `` element.
To style all the various SVG drawing elements emitted by GoAT,
a CSS file might contain these rules:
…and produce this SVG image
Note the prefers-color-scheme: dark above.
This switches all paths (in the sense of "lines") between yellow and blue,
because yellow is peculiarly hard to distinguish against a light background,
and its hue-complement blue against a dark background.
To see GoAT use the @media switch to dynamically change the drawing color,
toggle between dark and light either the GitHub UI or your browser's color scheme.
GoAT supports styling of `` elements at the granularity of individual words. A word, or left-to-right sequence of words, is selected for alternate styling by bracketing it within a pair of characters that you the user choose to reserve for the purpose.
For each such pair, GoAT generates an anchor element ... to enclose
the printing elements. The anchor element specifies a list of CSS classes, and their effects cascade down to the wrapped elements.
Returning to our two ASCII and UTF-8 "Hello, world" examples:
The command line
go run ./cmd/goat/ -io ./ascii/_README/hello-world.styled.txt embed:palette/bold.css embed:style/ascii.csswhen executed at the top of the cloned GoAT source tree, combines a text file containing
.---------------.
` o-->| Hello,‗world‗ +--* `
'---------------'
with the CSS content
.bold {
goat-anchor-marks: "··";
font-weight: bold;
}
.italic {
goat-anchor-marks: "``";
font-style: italic;
}
.underline {
goat-anchor-marks: "‗‗"; /* -- resort to UTF-8 */
text-decoration: underline;
}
to produce this SVG image
For further details, see ascii/README.md
The command line
go run ./cmd/goat/ -io ./utf8/_README/hello-world.styled.txt -utf8 embed:palette/bold.css embed:style/utf8.csscombines a text file containing
╭──────────────┐
/ ○──►│ Hello,_world_├──● /
└──────────────╯
with the CSS content
.bold {
goat-anchor-marks: "**";
font-weight: bold;
}
.italic {
goat-anchor-marks: "//";
font-style: italic;
}
.underline {
goat-anchor-marks: "__";
text-decoration: underline;
}
.code {
goat-anchor-marks: "``";
stroke: inherit;
}
produces this SVG image
For further details, see utf8/README.md
GoAT can add web links to text strings within your diagram. By appending to the GoAT command line above also a path to a CSS file containing this:
.underline_href {
goat-anchor-marks: "__";
goat-anchor-href: "https://www.worldometers.info/";
}
we get an SVG that looks like this, with a clickable web URL (the link below is however disabled);
The above example exposes an environmental constraint: GitHub-flavored Markdown disallows "inline" \ elements so the above SVG is "embedded" into the HTML output of the Markdown processor, with the help of an HTML [](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img), element, and web browsers disable outgoing links from anchor elements within "embedded" SVG files.
To preserve your freedom to use some other body font outside of utf8 drawings, by limiting DejaVu Sans Mono (or other "pure-monospace" font) to only utf8 drawings, consider the following techniques for automatically selecting suitable fonts:
.dir-locals.el file.No open issues yet, or sync has not completed.