shithub: sirjofri_de

ref: 1626d4873c0b1cac2ffddc23c435b6524b942a8a
dir: /txt2ms/

View raw version
#!/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(/‥‥‥[^‥]+‥‥‥/, "\\f(CW&\\fR", a)
	gsub(/‥‥‥/, "", 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.."
	istitle = 1
}

firstheader && NR == 1 {
	printf ".TL\n%s\n", parsed($0)
	nextline = 1
}

$1 ~ /^\[\[\[ms/ {
	ismsblock = 1
	next
}

$1 ~ /^\[\[\[/ {
	ignore = 1
	next
}

$1 ~ /^\]\]\]/ {
	ismsblock = 0
	ignore = 0
	next
}

ignore {
	next
}

ismsblock {
	print
	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
}