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

View File

@ -7,7 +7,6 @@ Many people don't like to read markdown.
## Usage
These are AWK scripts.
The input markdown goes into stdin.
The output document comes out of stdout.
@ -24,12 +23,12 @@ pdflatex README.tex
If the awk option `stylesheet` is given, the HTML document can made prettier with external CSS.
```
awk -v stylesheet='/style.css' -f md2html < README.md
md2html -v stylesheet='/style.css' < README.md
```
## Supported constructs
- Headlines up to level 3
- Headlines up to level 6
- Paragraphs
- Bold, italic and inline monospace
- Image figures if they are in the same folder
@ -40,7 +39,6 @@ awk -v stylesheet='/style.css' -f md2html < README.md
## Not supported
- Tables
- More than 3 levels of nested headlines
- Images from an url
- Inline images
- Unicode characters (im german, maybe i will add it for umlauts)
- Images inline in text
- Unicode characters (im german, maybe i will add at least umlaut support)

16
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]) {
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)

8
md2tex
View File

@ -5,6 +5,7 @@ BEGIN {
tag("documentclass[a4paper]{article}")
# tag("special{papersize=210mm,297mm}")
tag("usepackage[margin=1in]{geometry}")
tag("usepackage[utf8]{inputenc}")
tag("setlength{\\parskip}{\\baselineskip}%")
tag("setlength{\\parindent}{0pt}%")
tag("usepackage{listings}")
@ -82,9 +83,12 @@ function inline(text) {
}
}
/^## / {
/^##* / {
d=length($1)
t="section"
for (i=3; i<=d; i++) t="sub"t
gsub(/^#* /, "", $0)
tag("section{" $0 "}")
tag(t"{" $0 "}")
next
}