dot

packages and services management
Log | Files | Refs | README

commit f9f05e9a29c6ad495ae622aab2dd462f02c26b0f
parent 781bc69cf74394c848d2776d4bbc5ad2364f120f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 10 Apr 2017 17:07:53 +0200

added madown

Diffstat:
M.profile | 4++--
Abin/madown | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+), 2 deletions(-)

diff --git a/.profile b/.profile @@ -38,8 +38,8 @@ PS3=': ' # core alias p='io-path' -alias l='ls -lhF' -alias la='ls -lhFA' +alias l='ls -lhp' +alias la='ls -lhpA' alias cl='printf "\033[H\033[2J"' alias ..='cd ..' alias j='jobs' diff --git a/bin/madown b/bin/madown @@ -0,0 +1,107 @@ +awk ' + +BEGIN { + head = 1; + tag = "p"; +} + + +# --- head --------------------------------------------------------------------- + + +head == 1 && /^[\t ]*$/ { + head = 0; + RS = "([\t ]*\n){2,}"; + next; +} + +head == 1 && /^Title: / { + sub(/^Title: /, ""); + printf("<h1>%s</h1>\n", $0); + next; +} + +head == 1 { + next; +} + + +# --- h2 - headings ------------------------------------------------------------ + + +!tag && /\n_+$/ { + sub(/\n_+_/, ""); + tag = "h2"; +} + + +# --- h3 - subheadings --------------------------------------------------------- + + +!tag && /^\| / { + sub(/^\| /, ""); + tag = "h3"; +} + + +# --- div - tags --------------------------------------------------------------- + + + +!tag && /^\{.*\}$/ { + sub(/^\{ */, ""); sub(/ *\}$/, ""); + tag = "div style=\"font-weight: bold;\""; +} + + +# --- ul - unordered lists ----------------------------------------------------- + + +!tag && /^- / && previous != "li" { + print "<ul>"; +} + +!tag && /^- / { + sub(/^- /, ""); + tag = "li"; +} + +tag != "li" && previous == "li" { + print "</ul>"; +} + + +# --- p - paragraphs ----------------------------------------------------------- + + +!tag { + tag = "p"; +} + + +# ------------------------------------------------------------------------------ + + +{ + # strip remaining newlines + gsub(/[\t ]*\n/, " "); + + # escape html sequences + gsub(/&/, "&amp;"); + gsub(/</, "&lt;"); + gsub(/>/, "&gt;"); + + # literal + while (sub(/`/, "<code>")) + sub(/`/, "</code>"); + + # bold + while (sub(/*/, "<strong>")) + sub(/*/, "</strong>"); + + printf("<%s>%s</%s>\n", tag, $0, tag); + + previous = tag; + tag = ""; +} +'