- Awk 48.7%
- Shell 36.3%
- Vim Script 12.9%
- Makefile 2.1%
| contrib/vim | add vim syntax | |
| src | busybox awk compatibility | |
| LICENSE | first | |
| Makefile | use .mwd extension and rename md2md | |
| README.md | busybox awk compatibility | |
mawkdown
A lightweight, line-oriented(ish) text markup tool with shell powers, implemented in awk.
Installation
PREFIX=~/.local make install with PREFIX of choice.
Usage
You probably shouldn't, but mawkdown -q ",",’ page.mwd > page.html.
Lines that begin with $ are passed to the shell, and the output of the command is included in the HTML output, as-is.
You can use this to insert things like lists of posts, current date, or anything you can do with the shell.
The current file is passed as $MWD_FILE to the shell, but this can be overridden with an environment variable of the same name.
Using this, you can make templates:
# template.mwd
<!doctype html>
...
$ awk '1ドル == "#" && 2ドル == "title:" { print "<title>" substr(0,ドル 10) "</title>"; exit }' "$MWD_FILE"
...
<main>
$ mawkdown "$MWD_FILE"
</main>
...
Then do MWD_FILE=main.mwd mawkdown template.mwd, or MWD_FILE=$< mawkdown template.mwd > $@ in your Makefile.
If you run mawkdown without arguments, you can type text manually and see the resulting output.
See mawkdown -h for the options.
The md2mwd tool can partially convert markdown to mawkdown.
Cheat sheet
# A comment
# Can be used for metadata read by other tools
# title: A title to read later
= Level 1 heading
== Level 2 heading
=== Level 3 heading
==== Level 4 heading
===== Level 5 heading
====== Level 6 heading
Paragraph.
Same paragraph.
New paragraph.
Call shell and include the output:
$ awk '1ドル == "#" && 2ドル == "title:" { print "<h1>" substr(0,ドル 10) "</h1>"; exit }' "$MWD_FILE"
My blog posts:
<ul>
$ find pages/blog -name '*.mwd' | while read -r l; do printf '<li><a href="/%s">%s</a></li>\n' "${l%.*}.html" "$(awk '1ドル=="#"&&2ドル=="title:"{1ドル=2ドル="";print substr(0,ドル 3)}' $l)"; done
# If it gets too long, put it in a separate script:
$ ./scripts/list_blog_posts
</ul>
$ printf 'What could /possibly/ go wrong?' | mawkdown
- Unordered list
- A second list item
+ Ordered list
+ Another list item
Inline markup includes /emphasis/, *strong*, `code/fixed-width`, |mark|,
_unarticulated annotation_, and [https://owl.is|hyperlinks].
Formatting characters can be escaped with \/backslash\/.
There are also footnotes^1; they can contain any alphanumeric characters^uggla2025.
^1 Here is a footnote text.
^uggla2025 And another one.
> A blockquote,
> spanning several...
> lines.
` Preformatted text.
` No /formatting/ applies in *here*.
<img alt="Standard HTML also works; angle brackets are counted but no further validation is performed.">
Tests
Run make test.
Compatibility
POSIX is clear that awk should work on "characters", but some awks do not support multi-byte encodings such as UTF-8, and mawkdown will probably not work well with those.
I don't know about Mac awk or how to test it.
Future plans
No not really.
Why?
I just think awk is neat, and it feels good to have only stable and ubiquitous POSIX tools as dependencies for my website.