BEGIN { toc_str = "
/) in_pre = 1
if (!in_pre && $0 ~ /\{\{TOC\}\}/) {
has_toc = 1
toc_lines[n] = 1
}
if ($0 ~ /<\/pre>/) in_pre = 0
if (match($0, /]*>/)) {
tag_len = RLENGTH
title_start = RSTART + tag_len
title_str = substr($0, title_start)
title_end = index(title_str, " 0) {
title = substr(title_str, 1, title_end - 1)
gsub(/<[^>]+>/, "", title)
# extract id
id_start = match($0, /id="[^"]*"/)
if (id_start > 0) {
id_str = substr($0, id_start + 4)
id_end = index(id_str, "\"")
id = substr(id_str, 1, id_end - 1)
# what tag? level
level = substr($0, match($0, /" title "\n"
} else if (level == "3") {
toc_str = toc_str "- " title "
\n"
}
}
}
}
}
END {
toc_str = toc_str "