# gemtext2html # convierte un archivo en gemtext a html de acuerdo a la spec # excepción: enlaces a imagen (jpg, png, gif) se vuelven # # modo de uso: # awk -f gemtext2html.awk archivo.gmi > archivo.html # BEGIN{ # para poder abrir y cerrar " ) } else if( modo_parrafo ){ # cierra el párrafo modo_parrafo = 0 appendContenido( "

" ) } # borra flecha del inicio sub("^=>","",$0) # ahora $1 es el path, $2 a $NF el texto # concatena todo el texto texto = $2 for(i=3; i<=NF; i++){ texto = texto" "$i } # si el path es imagen if( match($1, /(png|jpg|gif)$/) ){ # crea imagen $0=""texto"" } # si el path no es imagen else{ # convierte enlace de .gmi a .html ! sub(".gmi$",".html",$1) # crea link $0=""texto"
" } } appendContenido( $0 ) } /^* /{ # lista if(!modo_pre){ if(!modo_lista){ # inicia la lista if(modo_parrafo){ modo_parrafo = 0 appendContenido( "

" ) } modo_lista = 1 appendContenido( "" ) } else if( modo_parrafo ){ # cierra el párrafo modo_parrafo = 0 appendContenido( "

" ) } # abre preformatted modo_pre = 1 appendContenido( "
" )
	}
}

/^> /{ # blockquote
	if(!modo_pre){
		sub(">[[:blank:]]+","
",$0) sub("$","
",$0) bloque = 1 } appendContenido( $0 ) } /^# /{ # h1 if(!modo_pre){ sub("#[[:blank:]]+","",$0) #prefijo sub("$","",$0) #sufijo bloque = 1 if( !en_section ){ # si no se ha iniciado una sección antes appendContenido( "
" ) en_section = 1 } else{ appendContenido( "
" ) } appendContenido( "

"$0"

" ) # agrega header a navegación appendNav( "
  • "$0"
  • " ) } else{ appendContenido( $0 ) } } /^## /{ # h2 if(!modo_pre){ sub("##[[:blank:]]+","

    ",$0) sub("$","

    ",$0) bloque = 1 } appendContenido( $0 ) } /^### /{ # h3 if(!modo_pre){ sub("###[[:blank:]]+","

    ",$0) sub("$","

    ",$0) bloque = 1 } appendContenido( $0 ) } END{ print nav print "" print contenido # cierra tags que pudiero n haber quedado abiertas if(modo_pre) print "
    " else if(modo_parrafo) print "

    " else if(modo_lista) print "" print "" print "" print "" print "" print "" }