% SUBTEXT by C. Duckworth % This file generates README.md when you run `make readme'. .h1 Subtext, a layered document preperation system This repo contains the source of my groff-aesthetic document preparator .code subtext . It's unique in that it's an .code awk(1p) script that compiles a source file to a shell script that you can pipe to .code sh(1p) . Doing things in this multi-layered way allows me to ..ul .li Build a rich writing environment using only off-the-shelf POSIX tools .li Use the same input to generate multiple outputs .li A cool third thing .. so I can truly write-once, run anywhere (or whatever the kids are saying these days). Plus, it looks kinda like .code roff(1) without having to remember all the arcane two-letter requests and macros. .h2 Quickstart An easy and quick way to start with $$(code subtext) is to build this .a href="/subtext/tree/readme.st" README : ..code make readme .. Of course, I'd recommend reading readme.st in this repo to get a feel for the syntax as well. I've tried to use all the ways to inject control codes to illustrate it. However, this .em quick start is not really a good explanation of what's going on. For that, keep reading. .h2 The layers of subtext, the subtextual layers % I keep writing "subtext", so I'm going to define it here #subtext(){ code subtext; } There are three main layers of $$(subtext): the .b awk layer, .b shell layer, and, for lack of something better to call it, the .b text layer. These layers don't really reflect the order of expansions, but rather how I think they feel to the user and how they're reflected in syntax. .subtext is inherently a line-based markup language, and each of these layers has its own line marker. .h3 Awk layer: $$(code %) The first thing that happens to any $$(subtext) source file is a pass through .code subtext.awk . While this awk script passes most things through to the next layers, there are two special directives at this layer you can use: ..dl .dt $$(code %) ..dd << /dd Comment the current line. .code % only works at the start of a line for comments. /dd . .dt $$(code %so FILE) ..dd << /dd Insert FILE verbatim at the line where this directive appears. FILE is searched in $$(code $ST_SOPATH), which by default is the current directory. /dd .. I went ahead and reserved $$(code %)-lines for future directives that need to be done at awk-time. % NB: The octothorpe on the line below this comment must be escaped or quoted. % I'm thinking about escaping #'s as well .. but I think doing that would % take extra code I'm not sure I want to bother with, namely working with % a character's context. I like the idea that subtext.awk is a pretty-dumb % filter, and making it parse shell syntax does not seem like a good time. .h3 Shell layer: $$(code \#) So what does $$(subtext) do? It takes an input file or stream and converts it to a shell script which you can then pipe through $$(code "sh(1)"). But it doesn't .i just do that. .subtext also outputs various functions and variables and what-not to set up the environment in which the source document is expanded. Starting a line with $$(code \#) puts the rest of the line in the code part, enabling you to set a title, say, with $$(code "#title='Some title'") or define a function for a commonly-used thing in your file. For this README, I've written .code #subtext()(code subtext) so I save about five characters every time. .h3 Text layer: $$(code .) The "text layer" of subtext is actually expanded to a shell here-doc so that you can use stuff like .code \$(...) to call shell functions. But don't worry – I've made it easier to not shoot yourself in the foot. One $ is changed to \\$ in the expansion, and more than one $ is changed to one less. So \$\$$ becomes \$$, etc. if you really want to put the process number in your output. Oh, and ` are all escaped. Those were a bad idea from go. In addition, lines beginning with .code . expand to .code \$(...) , and lines beginning with .code ..COMMAND [ARGS] expand to .code \$(COMMAND ARGS << .. and close the here-doc with .code .. on a line by itself. You can add the .code << END-MARKER yourself if you want to specify your own end-marker. Basically, this means you can write ..code << /code \.h1 My cool article .nl Here is a cool article. It is \.i really cool. .nl Here's what someone said about it: .nl \..blockquote cite="A fan" Wow, what a cool article! \.. /code The above translates to % NB: I don't have `section' written in html.st.sh, and I don't really % want to bother here ... but I made @ an alias for html_el, % so it all works ^_^ ..@ section 'style="border:1px solid;padding:0.5em"' << //bq .h1 My cool article Here is a cool article. It is .i really cool. Here's what someone said about it: ..blockquote cite="A fan" Wow, what a cool article! .. //bq Since this README was generated from subtext source, look at readme.st to get a better feel for the syntax. .h2 Using $$(subtext) .i todo .h2 Issues .h3 Debugging Because shell's debugging tools are pretty bad, and because of the multiple layers involved with .subtext , it can be pretty hard to debug. It would be nice to figure out a way around this. .h3 Shell quoting issues If you've programmed in shell at all, you'll know that quoting is ... difficult, to say the least. Because .subtext expands to shell forms, it's vulnerable to similar issues – especially on .code . lines. .h2 Contributing Send me an email or whatever :) This project is licensed under the BSD-3 license. See COPYING for details.