Generate id atteributes for headings

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

29
md2html
View File

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