aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/anchors.jq
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-06 10:56:22 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-06 10:56:22 -0500
commit989b8065b45e52a8df2a803b1a72e0d0a7c35536 (patch)
treeffd7d779cf35dc13396aef3b1871a7bc954af350 /doc/manual/anchors.jq
parent08b8657978de0d56064aad9c3e925b64d91b28a2 (diff)
parente9fc1e4fdb0ab5adb6b163c3db361b86a4f5c69b (diff)
Merge branch 'path-info' into ca-drv-exotic
Diffstat (limited to 'doc/manual/anchors.jq')
-rwxr-xr-xdoc/manual/anchors.jq31
1 files changed, 31 insertions, 0 deletions
diff --git a/doc/manual/anchors.jq b/doc/manual/anchors.jq
new file mode 100755
index 000000000..72309779c
--- /dev/null
+++ b/doc/manual/anchors.jq
@@ -0,0 +1,31 @@
+"\\[\\]\\{#(?<anchor>[^\\}]+?)\\}" as $empty_anchor_regex |
+"\\[(?<text>[^\\]]+?)\\]\\{#(?<anchor>[^\\}]+?)\\}" as $anchor_regex |
+
+
+def transform_anchors_html:
+ . | gsub($empty_anchor_regex; "<a name=\"" + .anchor + "\"></a>")
+ | gsub($anchor_regex; "<a href=\"#" + .anchor + "\" id=\"" + .anchor + "\">" + .text + "</a>");
+
+
+def transform_anchors_strip:
+ . | gsub($empty_anchor_regex; "")
+ | gsub($anchor_regex; .text);
+
+
+def map_contents_recursively(transformer):
+ . + {
+ Chapter: (.Chapter + {
+ content: .Chapter.content | transformer,
+ sub_items: .Chapter.sub_items | map(map_contents_recursively(transformer)),
+ }),
+ };
+
+
+def process_command:
+ .[0] as $context |
+ .[1] as $body |
+ $body + {
+ sections: $body.sections | map(map_contents_recursively(if $context.renderer == "html" then transform_anchors_html else transform_anchors_strip end)),
+ };
+
+process_command