浏览代码

Update TOC anchor algorithm to match "https://github.com/thlorenz/anchor-markdown-header" (fixes "#--link-is-deprecated")

Tianon Gravi 7 年之前
父节点
当前提交
3afc117c54
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      toc.sh

+ 4 - 3
toc.sh

@@ -36,10 +36,11 @@ toc="$(
 				prefix = "\t" prefix
 				prefix = "\t" prefix
 			}
 			}
 
 
+			# https://github.com/thlorenz/anchor-markdown-header/blob/56f77a232ab1915106ad1746b99333bf83ee32a2/anchor-markdown-header.js#L20-L30
 			hash = tolower($0)
 			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
 			printf "%s[%s](#%s)\n", prefix, $0, hash
 		}
 		}