shithub: sirjofri_de

Download patch

ref: 2c3f4e76a07feb45795ffc5bf387127510a9d4f5
parent: e701bdac999a1137fd0d8081bfcfad8edf644db8
author: sirjofri <sirjofri@sirjofri.de>
date: Sun Jul 30 13:38:49 EDT 2023

adds txt2* conversion scripts

--- /dev/null
+++ b/txt2html
@@ -1,0 +1,133 @@
+#!/bin/awk -f
+
+# if someone wants to use that:
+#   ‥text‥   to print italic
+#   ‥‥text‥‥ to print bold
+function parsed(a){
+	if(dontparse) return a
+	gsub(/‥‥‥[^‥]+‥‥‥/, "<code>&</code>", a)
+	gsub(/‥‥‥/, "", a)
+	gsub(/‥‥[^‥]+‥‥/, "<b>&</b>", a)
+	gsub(/‥‥/, "", a)
+	gsub(/‥[^‥]+‥/, "<i>&</i>", a)
+	gsub(/‥/, "", a)
+	return a
+}
+
+BEGIN {
+	#print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+	#print "<html xmlns=\"http://www.w3.org/1999/xhtml\""
+	#print "      xmlns:epub=\"http://www.idpf.org/2007/ops\""
+	#print "      xml:lang=\"en\">"
+	print "<!-- end defs -->"
+}
+
+firstheader && NR == 1 {
+	Title = parsed($0)
+	#print "<!-- begin header -->"
+	#print "<head>"
+	#printf "	<title>%s</title>\n", Title
+	#print "</head>"
+	#print "<!-- end header -->"
+	#print "<!-- begin body -->"
+	#print "<body>"
+	#printf "<h1>%s</h1>\n", Title
+	next
+}
+
+$1 ~ /^\[\[\[ebook/ {
+	isebookblock = 1
+	next
+}
+
+$1 ~ /^\[\[\[/ {
+	ignore = 1
+	next
+}
+
+$1 ~ /^\]\]\]/ {
+	ignore = 0
+	isebookblock = 0
+	next
+}
+
+ignore {
+	next
+}
+
+isebookblock {
+	print
+	next
+}
+
+$1 ~ /^#+$/ {
+	l = length($1)
+	$1 = ""
+	sub(/^[ \t]*/, "")
+
+	if (isparagraph)
+		print "		</p>"
+	while (issection >= l){
+		printf "	</section><!-- %d -->\n", issection
+		issection--
+	}
+
+	if (l == 1)
+		printf "	<section><!-- %d -->\n", l
+	if (l >= 2)
+		printf "	<section><!-- %d -->\n", l
+
+	printf "		<h%d>%s</h%d>\n\n", l+1, parsed($0), l+1
+	istitle = 1
+	issection = l
+	next
+}
+
+$1 ~ /^-/ {
+	$1 = ""
+	sub(/^[ \t]*/, "")
+	if (!isitem)
+		print "<ul>"
+	printf "<li>%s</li>\n", parsed($0)
+	isitem = 1
+	next
+}
+
+/^$/ {
+	istitle = 0
+	previousempty = 1
+	
+	if (isitem) {
+		print "</ul>"
+		isitem = 0
+	}
+	if (isparagraph) {
+		print "		</p>"
+		isparagraph = 0
+	}
+	next
+}
+
+previousempty {
+	printf "		<p>"
+	print parsed($0)
+	previousempty = 0
+	isparagraph = 1
+	next
+}
+
+!previousempty {
+	printf "		%s\n", parsed($0)
+}
+
+END {
+	print "<!-- END everything -->"
+	if (isparagraph)
+		print "		</p>"
+	while (issection > 0){
+		printf "	</section><!-- %d -->\n", issection
+		issection--
+	}
+	#print "</body>"
+	#print "</html>"
+}
--- /dev/null
+++ b/txt2ms
@@ -1,0 +1,83 @@
+#!/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
+}