Compare commits

...

3 Commits

Author SHA1 Message Date
sejo 2a68f9970a generate valid epub 2021-12-14 13:10:39 -06:00
sejo b9b847b4b4 gemtext to html conversion 2021-12-14 11:59:48 -06:00
sejo 1c89aaf9a4 progress on <pre> 2021-12-13 22:07:36 -06:00
8 changed files with 114 additions and 33 deletions

View File

@ -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>

98
g2e.awk
View File

@ -34,11 +34,11 @@ BEGIN{
}
# setup epub
system( "mkdir -p " epubodir "OEBPS" )
system( "mkdir -p " epubodir "META-INF" )
system( "mkdir -p " epubodir indexdirname )
system( "cp -u " tdir "container.xml " epubodir "META-INF/" )
system( "cp -u " tdir "mimetype " epubodir )
system( "cp -u " tdir "style.css " epubodir "OEBPS" )
system( "cp -u " tdir "style.css " epubodir )
# read templates
templatefiles = "find " tdir " -type f -not -name '.*'"
@ -81,58 +81,118 @@ ARGIND==1 && /^=>/{
ch["id"] = id
ch["name"] = name
ch["num"]++
content = content " <item id=\"" id "\" href=\"" id ".xhtml\" media-type=\"application/xhtml+xml\"/>\n"
ch["dir"] = indexdirname
content = content " <item id=\"" id "\" href=\"" indexdirname id ".xhtml\" media-type=\"application/xhtml+xml\"/>\n"
spinetoc = spinetoc " <itemref idref=\"" id "\" />\n"
toc = toc write_template( "toc-navmap.ncx", ch )
toc = toc write_template( "toc-navpoint.ncx", ch )
next
}
ARGIND==1{ # skip other lines of the index
next
}
# when finished reading the index:
ARGIND==2 && FNR==1{
content = content " </manifest>\n\n" spinetoc " </spine>\n\n</package>"
printf content > epubodir "OEBPS/content.opf"
printf content > epubodir "content.opf"
toc = toc "</ncx>"
printf toc > epubodir "OEBPS/toc.ncx"
toc = toc " </navMap>\n</ncx>"
printf toc > epubodir "toc.ncx"
}
# content files
function finishfile(){
# finish writing the previous content file
out = out "\t</main>\n </body>\n</html>"
out = out " </body>\n</html>"
printf out > nameout
}
function append(line){
out = out "\t\t" line "\n"
}
ARGIND>2 && FNR==1{
finishfile()
out = out "\t" line "\n"
}
# setup the writing for this content file
ARGIND>1 && FNR==1 {
FNR==1 {
if(ARGIND>2) finishfile()
id=FILENAME
match(id,/[^/]+.gmi$/)
filenamestart = RSTART
match(id,/.gmi$/)
name = substr(id,filenamestart,RSTART-filenamestart)
nameout = epubodir "OEBPS/" name ".xhtml"
nameout = epubodir indexdirname name ".xhtml"
sub(/#{1,3}\s+/,"", $0)
m["title"] = $0
out = write_template("header.xhtml",m)
is_pre = 0
is_list = 0
test = "hola"
next
}
ARGIND>1 && match($0,/^#{1,3}+/){
# gemtext to html conversion
# pre-formatted
/^```/{
is_pre = !is_pre
if(is_pre) append("<pre>")
else append("</pre>")
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}+/){
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()
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
<rootfile full-path="content.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
</container>

View File

@ -3,11 +3,8 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>{title}<title>
<link rel="stylesheet" href="style.css" type="text/css" />
<title>{title}</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>
<body>
<header>
<h1>{title}</h1>
<header>
<main>
<h1>{title}</h1>

View File

@ -0,0 +1,18 @@
body{
padding: 1em;
font-family:sans-serif;
}
pre{
background-color: #fee;
padding:1em;
overflow-x: auto;
}
blockquote{
font-style: italic;
}
th,td{
border-style:ridge;
padding:5px;
}

View File

@ -22,3 +22,4 @@ including those that conform to the relaxed constraints of OPS 2.0 -->
<text>{author}</text>
</docAuthor>
<navMap>

View File

@ -1,6 +0,0 @@
<navMap>
<navPoint class="chapter" id="{id}" playOrder="{num}">
<navLabel><text>{name}</text></navLabel>
<content src="{id}.xhtml"/>
</navPoint>
</navMap>

View File

@ -0,0 +1,4 @@
<navPoint id="id-{id}" playOrder="{num}">
<navLabel><text>{name}</text></navLabel>
<content src="{dir}{id}.xhtml"/>
</navPoint>