Improve multi-language support

This commit is contained in:
Nero 2022-07-02 20:55:45 +00:00
parent 121ebca9ae
commit 6c831dc78f
3 changed files with 27 additions and 9 deletions

18
md2html
View file

@ -7,6 +7,7 @@ BEGIN {
prefix = "html/body/"
print("<!DOCTYPE html>")
level("html/head")
meta["lang"]="en"
toc=0
}
@ -46,7 +47,11 @@ function level(new) {
for (i = common; i < length(a); i++) {
if (a[i]) {
printf("%0" indent "s<%s>\n", "", a[i])
if (a[i]=="body") {
printf("%0" indent "s<%s lang=%s>\n", "", a[i], meta["lang"])
} else {
printf("%0" indent "s<%s>\n", "", a[i])
}
indent = indent + 2
}
}
@ -188,6 +193,9 @@ awk '
BEGIN {
indent = 4
level("summary")
lang="en"
tocname["en"]="Table of contents"
tocname["de"]="Inhaltsverzeichnis"
}
function oneliner(tag, str, args) {
@ -242,6 +250,14 @@ function inline(text) {
return text
}
/<body lang=/ {
lang=$0
gsub(/^.*lang=\"*/,"",lang)
gsub(/[^a-z].*$/,"",lang)
level("summary")
oneliner("h2", tocname[lang])
}
/<h[2-6] / {
id=$0
gsub(/^.*id=\"/,"",id)