summaryrefslogtreecommitdiff
path: root/lib/generate.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-08-25 23:16:25 +0300
committerPaul Buetow <paul@buetow.org>2024-08-25 23:16:25 +0300
commit850dd62850a88832803e13a4ad963a0f455865cc (patch)
treee8c8380694a4e6e37fef8d337321fcbb42f7dd8d /lib/generate.source.sh
parenta7370ba21f9b4be497dcb10f47265d6eb9532819 (diff)
fix markdown internal link ids
Diffstat (limited to 'lib/generate.source.sh')
-rw-r--r--lib/generate.source.sh10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/generate.source.sh b/lib/generate.source.sh
index aabb600..03c33bf 100644
--- a/lib/generate.source.sh
+++ b/lib/generate.source.sh
@@ -34,7 +34,10 @@ generate::make_link () {
# Markdown internal href format, we use it also for HTML
generate::internal_link_id () {
local -r text="$1"; shift
- tr '[:upper:]' '[:lower:]' <<< "$text" | tr ' ' '-' | tr -cd 'A-Za-z0-9-'
+ # Replace uppercase with lowercase
+ # Replace ' and space with dashes
+ # Remove all other characters but alnum
+ tr '[:upper:]' '[:lower:]' <<< "$text" | tr "' " '-' | tr -cd 'A-Za-z0-9-'
}
# Add other docs (e.g. images, videos) from Gemtext to output format.
@@ -211,3 +214,8 @@ generate::draft () {
log INFO 'For HTML preview, open in your browser:'
find "$CONTENT_BASE_DIR/html" -name DRAFT-\*.html
}
+
+generate::test () {
+ local text="I can't believe it!"
+ assert::equals "$(generate::internal_link_id "$text")" 'i-can-t-believe-it'
+}