ref: 069cd7b7ff6a865a25074245fb200fb924edfdf0
dir: /txt2ms/
#!/bin/awk -f # if someone wants to use that: # ‥text‥ to print italic # ‥‥text‥‥ to print bold # it might be better to just use \fI and \fB directly function parsed(a){ if(dontparse) return a gsub(/‥‥[^‥]+‥‥/, "\\fB&\\fR", a) gsub(/‥‥/, "", a) gsub(/‥[^‥]+‥/, "\\fI&\\fR", a) gsub(/‥/, "", a) return a } BEGIN { print ".de XS\n.ds LQ \"\"\n.nr |i (\\\\$1i-1i)/3u\n.ie '\\\\$1'0' .tm TOC:.XL \\\\$1 \\\\*(LQ\\\\$2\\\\*(LQ \\\\n%\n.el .tm TOC:.XL \\\\$1 \\\\*(LQ\\h'\\\\n(|iu'\\\\*(SN\\0\\0\\\\$2\\\\*(LQ \\\\n%\n.." print ".tm TOC:.de XL\n.tm TOC:.nr |i \\\\\\\\$1\n.tm TOC:.ta \\\\\\\\n(LLuR\n.tm TOC:.ie \\\\\\\\$1>1 \\\\\n.tm TOC:\\\\{\\\\\n.tm TOC:\\\\\\\\$2 \\\\a\\\\|\\\\|\\\\\\\\$3\n.tm TOC:.vs 15pt\n.tm TOC:.\\\\}\n.tm TOC:.el \\\\\n.tm TOC:\\\\{\\\\\n.tm TOC:\\\\fB\\\\\\\\$2 \\\\|\\\\|\\\\\\\\$3\\\\fR\n.tm TOC:.vs 25pt\n.tm TOC:.\\\\}\n.tm TOC:.." print ".tm TOC:.LP" } firstheader && NR == 1 { printf ".TL\n%s\n", parsed($0) nextline = 1 } $1 ~ /^\[\[\[ms/ { ismsblock = 1 next } $1 ~ /^\]\]\]ms/ { ismsblock = 0 next } $1 ~ /^\[\[\[/ { ignore = 1 next } $1 ~ /^\]\]\]/ { ignore = 0 next } ignore { next } $1 ~ /^#+$/ { l = length($1) $1 = "" sub(/^[ \t]*/, "") printf ".NH %d\n.LG\n%s\n.NL\n", l, parsed($0) printf ".XS %d \"%s\"\n", l, parsed($0) istitle = 1 nextline = 1 } $1 ~ /^-/ { $1 = "" sub(/^[ \t]*/, "") printf ".IP •\n%s\n", parsed($0) nextline = 1 } /^$/ { if(istitle) printf ".LP" else printf ".PP" istitle = 0 } { if(nextline == 0) print parsed($0) else nextline = 0 }