about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-20 17:43:07 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-20 17:43:07 +0200
commit65372679266e87b9dc8de8fe29d6f55c41956868 (patch)
tree95782ad01dd657c5a05696855133a5c93eb332fa
parente746fcf957239d5e9210fdc6bad333fa9e1a7364 (diff)
downloadchawan-65372679266e87b9dc8de8fe29d6f55c41956868.tar.gz
add table_rewrite.sh
pandoc can only generate manpage tables from markdown tables, but the
markdown pipe table syntax is horrible. So instead of rewriting our markdown
documentation to use that syntax, just programmatically rewrite it.
-rw-r--r--Makefile2
-rw-r--r--doc/config.md4
-rwxr-xr-xtable_rewrite.sh45
3 files changed, 48 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 942e2f09..d10ccf11 100644
--- a/Makefile
+++ b/Makefile
@@ -51,7 +51,7 @@ clean:
 
 .PHONY: manpage
 manpage:
-	sed '/<!-- TOCSTART -->/,/<!-- TOCEND -->/d' doc/config.md > .obj/cha-config.md
+	sed '/<!-- TOCSTART -->/,/<!-- TOCEND -->/d' doc/config.md | ./table_rewrite.sh > .obj/cha-config.md
 	pandoc --standalone --to man .obj/cha-config.md -o .obj/cha-config.5
 	cp doc/cha.1 "$(OBJDIR)/cha.1"
 
diff --git a/doc/config.md b/doc/config.md
index 2e989bd1..8c8acff6 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -286,8 +286,8 @@ completely.</td>
 </tr>
 
 <tr>
-<td>no-format-mode
-<td>["bold", "italic", "underline", "reverse", "strike", "overline", "blink"]
+<td>no-format-mode</td>
+<td>["bold", "italic", "underline", "reverse", "strike", "overline", "blink"]</td>
 <td>Disable specified formatting modes.</td>
 </tr>
 
diff --git a/table_rewrite.sh b/table_rewrite.sh
new file mode 100755
index 00000000..dcf51edb
--- /dev/null
+++ b/table_rewrite.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+format_table() {
+	first_row=""
+	table_lines=""
+	while read line
+	do	first_row="$first_row$line"
+		if test "$line" = "</tr>"
+		then	break
+		fi
+	done
+	while read line
+	do	if test "$line" = "</table>"
+		then	break
+		fi
+		table_lines="$table_lines $line"
+	done
+	printf '%s' "$first_row" | sed \
+		-e 's/<tr>/|/g' \
+		-e 's/<\/tr>/|\n/g' \
+		-e 's/<\/t[hd]> *<t[hd]>/|/g' \
+		-e 's/<\/\?t[hd]>//g' \
+		-e 's/^ *//g;s/ *$//g'
+	printf '%s\n' "$first_row" | sed \
+		-e 's/<tr>/|/g' \
+		-e 's/<\/tr>/|\n/g' \
+		-e 's/<\/t[hd]> *<t[hd]>/|/g' \
+		-e 's/<\/\?t[hd]>//g' \
+		-e 's/[^|]/-/g' \
+		-e 's/^ *//g;s/ *$//g'
+	printf '%s\n' "$table_lines" | sed \
+		-e 's/<tr>/|/g' \
+		-e 's/<\/tr>/|\n/g' \
+		-e 's/<\/t[hd]> *<t[hd]>/|/g' \
+		-e 's/<\/\?t[hd]>//g' \
+		-e 's/^ *//g;s/ *$//g'
+}
+
+while read line
+do	if test "$line" = "<table>"
+	then	format_table
+	else
+		printf '%s\n' "$line"
+	fi
+done