gemtext to html conversion
This commit is contained in:
parent
1c89aaf9a4
commit
b9b847b4b4
|
@ -2,6 +2,8 @@
|
|||
|
||||
hello!
|
||||
|
||||
> not everything
|
||||
|
||||
## this is a second-level heading
|
||||
|
||||
yay!
|
||||
|
@ -21,3 +23,8 @@ awk -f g2e.awk example-gpub/
|
|||
```
|
||||
|
||||
so meta!
|
||||
|
||||
=> chapter2.gmi a link to chapter 2
|
||||
=> https://compudanzas.net compudanzas
|
||||
|
||||
+ <p><strong>hello</strong></p>
|
||||
|
|
58
g2e.awk
58
g2e.awk
|
@ -127,9 +127,13 @@ FNR==1 {
|
|||
out = write_template("header.xhtml",m)
|
||||
is_pre = 0
|
||||
is_list = 0
|
||||
test = "hola"
|
||||
next
|
||||
}
|
||||
|
||||
# gemtext to html conversion
|
||||
|
||||
# pre-formatted
|
||||
/^```/{
|
||||
is_pre = !is_pre
|
||||
if(is_pre) append("<pre>")
|
||||
|
@ -137,18 +141,58 @@ FNR==1 {
|
|||
next
|
||||
}
|
||||
|
||||
is_pre{
|
||||
append($0)
|
||||
next
|
||||
}
|
||||
|
||||
# empty lines
|
||||
/^$/{
|
||||
if(is_list){ append("</ul>"); is_list = 0 }
|
||||
next
|
||||
}
|
||||
|
||||
# lists
|
||||
sub(/^\*[[:space:]]*/,""){
|
||||
if(!is_list){ append("<ul>"); is_list = 1 }
|
||||
append("<li>" $0 "</li>")
|
||||
next
|
||||
}
|
||||
|
||||
# headers
|
||||
match($0,/^#{1,3}+/){
|
||||
if(!is_pre){
|
||||
sub(/^#{1,3}[[:space:]]+/,"",$0)
|
||||
append( "<h" RLENGTH ">" $0 "</h" RLENGTH ">")
|
||||
}
|
||||
else append($0)
|
||||
sub(/^#{1,3}[[:space:]]+/,"",$0)
|
||||
append( "<h" RLENGTH ">" $0 "</h" RLENGTH ">")
|
||||
next
|
||||
}
|
||||
|
||||
# blockquote
|
||||
sub(/^>[[:space:]]*/,""){
|
||||
append("<blockquote>" $0 "</blockquote>")
|
||||
next
|
||||
}
|
||||
|
||||
# links?
|
||||
sub(/^=>[[:space:]]*/,""){
|
||||
link = $1
|
||||
if(link~/gmi$/) sub(/gmi$/,"xhtml",link)
|
||||
text = $2
|
||||
for(i=3;i<=NF;i++) text = text " " $i
|
||||
append("<p><a href=\"" link "\">" text "</a></p>")
|
||||
next
|
||||
}
|
||||
|
||||
# raw html +
|
||||
sub(/^\+[[:space:]]*/,""){
|
||||
append($0)
|
||||
next
|
||||
}
|
||||
|
||||
# paragraphs
|
||||
{
|
||||
append("<p>" $0 "</p>")
|
||||
}
|
||||
|
||||
END{
|
||||
finishfile()
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue