From 3afc117c548a89639790d1cc8c7fdfcca7a0c572 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 21 Nov 2018 17:06:32 -0800 Subject: [PATCH] Update TOC anchor algorithm to match "https://github.com/thlorenz/anchor-markdown-header" (fixes "#--link-is-deprecated") --- toc.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/toc.sh b/toc.sh index acd0d5a913fa0..5256b3b8ed061 100755 --- a/toc.sh +++ b/toc.sh @@ -36,10 +36,11 @@ toc="$( prefix = "\t" prefix } + # https://github.com/thlorenz/anchor-markdown-header/blob/56f77a232ab1915106ad1746b99333bf83ee32a2/anchor-markdown-header.js#L20-L30 hash = tolower($0) - gsub(/['"'"'./`]/, "", hash) - gsub(/[^a-z0-9]+/, "-", hash) - gsub(/^-|-$/, "", hash) + gsub(/ /, "-", hash) + gsub(/[\/?!:\[\]`.,()*"'"'"';{}+=<>~\$|#@&–—]/, "", hash) + gsub(/[。?!,、;:“”【】()〔〕[]﹃﹄“ ”‘’﹁﹂—…-~《》〈〉「」]/, "", hash) printf "%s[%s](#%s)\n", prefix, $0, hash }