support for images
This commit is contained in:
parent
28c422f1f3
commit
d3245db368
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
clean:
|
clean:
|
||||||
rm -r out/
|
rm -r out/ out.epub
|
||||||
|
|
||||||
example-gpub:
|
example-gpub:
|
||||||
cd example-gpub; zip -r ../example-book.gpub *; cd -
|
cd example-gpub; zip -r ../example-book.gpub *; cd -
|
||||||
|
|
33
README.md
33
README.md
|
@ -26,15 +26,36 @@ awk -f g2e.awk example-gpub/
|
||||||
|
|
||||||
# notes
|
# notes
|
||||||
|
|
||||||
the converter works with gempub archives that have a flat file structure: all the `.gmi` files, including `index.gmi`, have to be in the same directory. see the provided `example-gpub/`.
|
## file structure
|
||||||
|
|
||||||
|
the converter works with gempub archives that have a flat file structure: all the `.gmi` files, including `index.gmi`, have to be in the same directory.
|
||||||
|
|
||||||
|
furthermore, the image assets for the book have to be inside that directory, within a directory called `img/`.
|
||||||
|
|
||||||
|
for example, the structure for `example-gpub` is:
|
||||||
|
|
||||||
|
```
|
||||||
|
example-gpub/
|
||||||
|
metadata.txt
|
||||||
|
book/
|
||||||
|
index.gmi
|
||||||
|
cover.gmi
|
||||||
|
chapter1.gmi
|
||||||
|
chapter2.gmi
|
||||||
|
chapter3.gmi
|
||||||
|
img/
|
||||||
|
screencap_uxn-pong.gif
|
||||||
|
screenshot_uxn-pong-paddle.png
|
||||||
|
screenshot_uxn-pong-paddles-and-ball.png
|
||||||
|
screenshot_uxn-pong-paddles.png
|
||||||
|
```
|
||||||
|
|
||||||
|
note that only `.gmi`, `.png`, `.jpg` and `.gif` files are handled.
|
||||||
|
|
||||||
|
## raw html
|
||||||
|
|
||||||
you can insert raw html using the corresponding `.gmo` syntax: the contents of a line that starts with `+` will be inserted as is.
|
you can insert raw html using the corresponding `.gmo` syntax: the contents of a line that starts with `+` will be inserted as is.
|
||||||
|
|
||||||
# TODO
|
|
||||||
|
|
||||||
* handle non-gmi files in the manifest
|
|
||||||
* handle links to images
|
|
||||||
|
|
||||||
# references
|
# references
|
||||||
|
|
||||||
* [EPUB - Wikipedia](https://en.wikipedia.org/wiki/EPUB#Implementation)
|
* [EPUB - Wikipedia](https://en.wikipedia.org/wiki/EPUB#Implementation)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
hello!
|
hello!
|
||||||
|
|
||||||
|
=> img/screencap_uxn-pong.gif animated pong
|
||||||
|
|
||||||
> not everything
|
> not everything
|
||||||
|
|
||||||
## this is a second-level heading
|
## this is a second-level heading
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# an example book
|
||||||
|
|
||||||
|
a gpub archive that gets converted to an epub file
|
||||||
|
|
||||||
|
=> img/screenshot_uxn-pong-paddles-and-ball.png screenshot of pong
|
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
Binary file not shown.
After Width: | Height: | Size: 892 B |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 963 B |
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
hello!
|
hello!
|
||||||
|
|
||||||
|
=> cover.gmi an example book
|
||||||
=> chapter1.gmi chapter 1: an example
|
=> chapter1.gmi chapter 1: an example
|
||||||
=> chapter2.gmi chapter 2: another example
|
=> chapter2.gmi chapter 2: another example
|
||||||
=> chapter3.gmi chapter 3: yet another
|
=> chapter3.gmi chapter 3: yet another
|
||||||
|
|
32
g2e.awk
32
g2e.awk
|
@ -35,10 +35,13 @@ BEGIN{
|
||||||
|
|
||||||
# setup epub
|
# setup epub
|
||||||
system( "mkdir -p " epubodir "META-INF" )
|
system( "mkdir -p " epubodir "META-INF" )
|
||||||
system( "mkdir -p " epubodir indexdirname )
|
system( "mkdir -p " epubodir indexdirname "img" )
|
||||||
system( "cp -u " tdir "container.xml " epubodir "META-INF/" )
|
system( "cp -u " tdir "container.xml " epubodir "META-INF/" )
|
||||||
system( "cp -u " tdir "mimetype " epubodir )
|
system( "cp -u " tdir "mimetype " epubodir )
|
||||||
system( "cp -u " tdir "style.css " epubodir )
|
system( "cp -u " tdir "style.css " epubodir )
|
||||||
|
# copy images
|
||||||
|
# system( "cp -u " gpubdir indexdirname "img/* " epubodir indexdirname "img/" )
|
||||||
|
|
||||||
|
|
||||||
# read templates
|
# read templates
|
||||||
templatefiles = "find " tdir " -type f -not -name '.*'"
|
templatefiles = "find " tdir " -type f -not -name '.*'"
|
||||||
|
@ -94,6 +97,21 @@ ARGIND==1{ # skip other lines of the index
|
||||||
|
|
||||||
# when finished reading the index:
|
# when finished reading the index:
|
||||||
ARGIND==2 && FNR==1{
|
ARGIND==2 && FNR==1{
|
||||||
|
line = $0
|
||||||
|
# add images to manifest
|
||||||
|
while( "find " gpubdir indexdirname "img/ -type f -regextype awk -iregex \".+(png|jpg|gif)$\"" | getline){
|
||||||
|
path = $0
|
||||||
|
dest = path; sub(gpubdir, "", dest)
|
||||||
|
fortoc = dest
|
||||||
|
system( "cp -u " $0 " " epubodir dest) # copy images
|
||||||
|
mediatype = fortoc~/gif$/ ? "image/gif" : fortoc~/jpg$/ ? "image/jpeg" : "image/png"
|
||||||
|
id = fortoc
|
||||||
|
sub(/^.+\//,"",id)
|
||||||
|
content = content " <item id=\"" id "\" href=\"" fortoc "\" media-type=\"" mediatype "\"/>\n"
|
||||||
|
}
|
||||||
|
$0 = line
|
||||||
|
|
||||||
|
# finalize metadata files
|
||||||
content = content " </manifest>\n\n" spinetoc " </spine>\n\n</package>"
|
content = content " </manifest>\n\n" spinetoc " </spine>\n\n</package>"
|
||||||
printf content > epubodir "content.opf"
|
printf content > epubodir "content.opf"
|
||||||
|
|
||||||
|
@ -175,10 +193,18 @@ sub(/^>[[:space:]]*/,""){
|
||||||
# links?
|
# links?
|
||||||
sub(/^=>[[:space:]]*/,""){
|
sub(/^=>[[:space:]]*/,""){
|
||||||
link = $1
|
link = $1
|
||||||
if(link~/gmi$/) sub(/gmi$/,"xhtml",link)
|
|
||||||
text = $2
|
text = $2
|
||||||
for(i=3;i<=NF;i++) text = text " " $i
|
for(i=3;i<=NF;i++) text = text " " $i
|
||||||
append("<p><a href=\"" link "\">" text "</a></p>")
|
if(link~/gmi$/){
|
||||||
|
sub(/gmi$/,"xhtml",link)
|
||||||
|
append("<p><a href=\"" link "\">" text "</a></p>")
|
||||||
|
}
|
||||||
|
else if(link~/(gif|jpg|png)$/){
|
||||||
|
append("<img src=\"" link "\" alt=\"" text "\" />")
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
append("<p><a href=\"" link "\">" text "</a></p>")
|
||||||
|
}
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue