aboutsummaryrefslogtreecommitdiffstats
path: root/gemtext2html.awk
diff options
context:
space:
mode:
authorsejo <sejo@texto-plano.xyz>2021-05-19 19:24:20 -0500
committersejo <sejo@texto-plano.xyz>2021-05-19 19:24:20 -0500
commit7d9e6528b245e2918c9f2481f25ad1e631472394 (patch)
tree161b0b4344622fbb4488a37a274364ba1b8ae38e /gemtext2html.awk
parent82b994447214af187f05083f1fff33a78f92b1a8 (diff)
downloadsitio-7d9e6528b245e2918c9f2481f25ad1e631472394.tar.gz
appendContenido y nav
Diffstat (limited to 'gemtext2html.awk')
-rw-r--r--gemtext2html.awk70
1 files changed, 46 insertions, 24 deletions
diff --git a/gemtext2html.awk b/gemtext2html.awk
index fd45139..f6f259c 100644
--- a/gemtext2html.awk
+++ b/gemtext2html.awk
@@ -5,6 +5,7 @@
# modo de uso:
# awk -f gemtext2html.awk archivo.gmi > archivo.html
#
+
BEGIN{
# para poder abrir y cerrar <ul>, <pre>, <p>:
modo_lista = 0
@@ -18,45 +19,59 @@ BEGIN{
print "<head>"
print "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
print "<meta content='initial-scale=1.0, maximum-scale=1.0, user-scalable=yes' name='viewport'/>"
+
+ contenido = "<main>"
+ nav = "<nav><ul>"
+}
+
+function appendContenido( t ){
+ contenido = contenido t
}
+function appendNav( t ){
+ nav = nav t
+}
+
NR == 1{
titulo = $0
sub("#[[:blank:]]+","",titulo) #prefijo
- print "<title>"titulo" - codeVGA</title>"
+ print "<title>"titulo"</title>"
print "</head>"
print "<body>"
+ print "<header>"
+ print "<h1>"titulo"</h1>"
+ print "</header>"
}
$0 !~ /^(=>|```|#{1,3} |* |>|[[:blank:]]*$)/{ # líneas de texto (no "especiales")
if(!modo_pre){
if(!modo_parrafo){
modo_parrafo = 1
- print "<p>"
+ appendContenido( "<p>" )
}
else # nueva línea en el mismo párrafo
- print "<br/>"
+ appendContenido( "<br/>" )
}
- print $0
+ appendContenido( $0 )
}
/^[[:blank:]]*$/ { # línea vacía
if( !modo_pre ) {
if( modo_lista ){ # cierra la lista
modo_lista = 0
- print "</ul>"
+ appendContenido( "</ul>" )
}
else if( modo_parrafo ){ # cierra el párrafo
modo_parrafo = 0
- print "</p>"
+ appendContenido( "</p>" )
}
else if( bloque ) # si lo previo fue header o blockquote
bloque = 0;
else
- print "<br/>"
+ appendContenido( "<br/>" )
}
else
- print $0
+ appendContenido( $0 )
}
@@ -64,11 +79,11 @@ $0 !~ /^(=>|```|#{1,3} |* |>|[[:blank:]]*$)/{ # líneas de texto (no "especiales
if(!modo_pre){
if( modo_lista ){ # cierra la lista
modo_lista = 0
- print "</ul>"
+ appendContenido( "</ul>" )
}
else if( modo_parrafo ){ # cierra el párrafo
modo_parrafo = 0
- print "</p>"
+ appendContenido( "</p>" )
}
# borra flecha del inicio
sub("^=>","",$0)
@@ -94,7 +109,7 @@ $0 !~ /^(=>|```|#{1,3} |* |>|[[:blank:]]*$)/{ # líneas de texto (no "especiales
$0="<a href='"$1"'>"texto"</a><br/>"
}
}
- print $0
+ appendContenido( $0 )
}
/^* /{ # lista
@@ -102,36 +117,36 @@ $0 !~ /^(=>|```|#{1,3} |* |>|[[:blank:]]*$)/{ # líneas de texto (no "especiales
if(!modo_lista){ # inicia la lista
if(modo_parrafo){
modo_parrafo = 0
- print "</p>"
+ appendContenido( "</p>" )
}
modo_lista = 1
- print "<ul>"
+ appendContenido( "<ul>" )
}
sub("*[[:blank:]]+","<li>",$0)
sub("$","</li>",$0)
}
- print $0
+ appendContenido( $0 )
}
/^```/{ # preformatted
if(modo_pre){
# cierra preformatted
modo_pre = 0
- print "</pre>"
+ appendContenido( "</pre>" )
}
else{
if( modo_lista ){ # cierra la lista
modo_lista = 0
- print "</ul>"
+ appendContenido( "</ul>" )
}
else if( modo_parrafo ){ # cierra el párrafo
modo_parrafo = 0
- print "</p>"
+ appendContenido( "</p>" )
}
# abre preformatted
modo_pre = 1
- print "<pre>"
+ appendContenido( "<pre>" )
}
}
@@ -141,16 +156,16 @@ $0 !~ /^(=>|```|#{1,3} |* |>|[[:blank:]]*$)/{ # líneas de texto (no "especiales
sub("$","</blockquote>",$0)
bloque = 1
}
- print $0
+ appendContenido( $0 )
}
/^# /{ # h1
if(!modo_pre){
- sub("#[[:blank:]]+","<h1>",$0) #prefijo
- sub("$","</h1>",$0) #sufijo
+ sub("#[[:blank:]]+","",$0) #prefijo
+ sub("$","",$0) #sufijo
bloque = 1
}
- print $0
+ appendContenido( "<h1 id='"$0"'>"$0"</h1>" )
}
/^## /{ # h2
@@ -159,7 +174,7 @@ $0 !~ /^(=>|```|#{1,3} |* |>|[[:blank:]]*$)/{ # líneas de texto (no "especiales
sub("$","</h2>",$0)
bloque = 1
}
- print $0
+ appendContenido( $0 )
}
/^### /{ # h3
@@ -168,10 +183,13 @@ $0 !~ /^(=>|```|#{1,3} |* |>|[[:blank:]]*$)/{ # líneas de texto (no "especiales
sub("$","</h3>",$0)
bloque = 1
}
- print $0
+ appendContenido( $0 )
}
END{
+ print nav
+ print "</ul></nav>"
+ print contenido
# cierra tags que pudiero n haber quedado abiertas
if(modo_pre)
print "</pre>"
@@ -180,6 +198,10 @@ END{
else if(modo_lista)
print "</ul>"
+ print "</main>"
+ print "<footer>"
+ # TODO footer
+ print "</footer>"
print "</body>"
print "</html>"
}
Un proyecto texto-plano.xyz