summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-04-03 11:02:27 -0300
committerEuAndreh <eu@euandre.org>2025-04-03 11:02:27 -0300
commitc833fc9f64ca5170bd3693b412376b36bcd5277c (patch)
treeb06f337adaf7d27a38400731cb4a14ff706227c4
parentSetup project skeleotn (diff)
downloadadoc-c833fc9f64ca5170bd3693b412376b36bcd5277c.tar.gz
adoc-c833fc9f64ca5170bd3693b412376b36bcd5277c.tar.xz
src/adoc: Import code from blog
-rwxr-xr-xsrc/adoc45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/adoc b/src/adoc
index e69de29..85d2387 100755
--- a/src/adoc
+++ b/src/adoc
@@ -0,0 +1,45 @@
+#!/bin/sh
+set -euo pipefail
+
+
+usage() {
+ echo 'Usage: adoc [-x] [-s] [-n INDENT_LEN] [FILENAME.adoc]'
+}
+
+FILENAME="${1:-}"
+eval "$(assert-arg -- "$FILENAME" 'FILENAME.adoc')"
+
+
+plaintext_links() {
+ awk -v BASE="$(basename "$FILENAME" .adoc)".html '
+ { print }
+ /^----$/ {
+ in_block = !in_block
+ if (in_block) {
+ next
+ }
+ file = BASE "." count++ ".txt"
+ print "[role=plaintext]"
+ print "link:" file "[plaintext]"
+ }' "$1"
+}
+
+runtidy() {
+ statusconv 1:0 tidy \
+ -quiet \
+ -indent \
+ --indent-attributes yes \
+ --show-body-only yes \
+ --show-warnings no \
+ --tidy-mark no \
+ --wrap 120
+}
+
+indent_4_blocks() {
+ printf '<div><div><div><div>%s</div></div></div></div>' "$(cat -)" |
+ runtidy |
+ head -n -4 |
+ tail -n +5
+}
+
+plaintext_links "$FILENAME" | asciidoctor -s - | indent_4_blocks