Generate id atteributes for headings

This commit is contained in:
Nero 2022-06-26 00:24:23 +00:00
parent c856e612af
commit 071c9af7bb

27
md2html
View File

@ -130,25 +130,20 @@ function inline(text) {
next next
} }
/^# / { /^##* / {
d=length($1)
gsub(/^#* /, "", $0) gsub(/^#* /, "", $0)
if (!meta["title"]) meta["title"] = $0 if (d==1 && !meta["title"]) meta["title"] = $0
level(prefix) id1=$0
oneliner("h1", $0) gsub(/[^a-zA-Z0-9]/, "", id1)
next hash[d]=id1
id = ""
for (i = 2; i <= d; i++) {
id = id hash[i]
} }
if (id != "") id = " id=\"" escape(id) "\""
/^## / {
gsub(/^#* /, "", $0)
level(prefix) level(prefix)
oneliner("h2", $0) oneliner("h"d, $0, id)
next
}
/^### / {
gsub(/^#* /, "", $0)
level(prefix)
oneliner("h3", $0)
next next
} }