dot

packages and services management
Log | Files | Refs | README

commit 42f9e60efb737f6c348d830d3ef56c8529d786bd
parent 7c93840f45206b45526812de235776df8417f1c7
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon, 17 Jul 2017 21:14:41 +0200

txt: convert lightweight text format to html

Diffstat:
Abin/txt | 40++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+), 0 deletions(-)

diff --git a/bin/txt b/bin/txt @@ -0,0 +1,40 @@ +awk ' + +!ELEMENT && /^\t/ { + print "<pre>" + do { + sub("^\t", "", $0) + print + } while (getline && $0 !~ /^[^\t]/) + print "</pre>" + ELEMENT = "" +} + +!ELEMENT && /^$/ { next } + +ELEMENT && /^$/ { + print "</" ELEMENT ">" + ELEMENT = "" + next +} + +match($0, /^=+ /) { + sub(/^=* */, "", $0) + sub(/ *=*$/, "", $0) + lv = RLENGTH - 1 + id = match($0, /^[0-9.]*/) ? substr($0, 1, RLENGTH) : "" + print "<h" lv " id=\"" id "\">" $0 "</h" lv ">" + ELEMENT = "" + next +} + +# other rules go here + +!ELEMENT { + print "<p>\n" $0 + ELEMENT = "p" + next +} + +{ print } +'