diff --git a/md2html b/md2html
index ab5c6d1..11c42b4 100755
--- a/md2html
+++ b/md2html
@@ -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
}