diff --git a/Makefile b/Makefile
index 6efa8b7..5c189d9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
clean:
- rm -r out/
+ rm -r out/ out.epub
example-gpub:
cd example-gpub; zip -r ../example-book.gpub *; cd -
diff --git a/README.md b/README.md
index 71952f1..30967ce 100644
--- a/README.md
+++ b/README.md
@@ -26,15 +26,36 @@ awk -f g2e.awk example-gpub/
# 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.
-# TODO
-
-* handle non-gmi files in the manifest
-* handle links to images
-
# references
* [EPUB - Wikipedia](https://en.wikipedia.org/wiki/EPUB#Implementation)
diff --git a/example-gpub/book/chapter1.gmi b/example-gpub/book/chapter1.gmi
index f6010bd..01403ba 100644
--- a/example-gpub/book/chapter1.gmi
+++ b/example-gpub/book/chapter1.gmi
@@ -2,6 +2,8 @@
hello!
+=> img/screencap_uxn-pong.gif animated pong
+
> not everything
## this is a second-level heading
diff --git a/example-gpub/book/cover.gmi b/example-gpub/book/cover.gmi
new file mode 100644
index 0000000..cf4445e
--- /dev/null
+++ b/example-gpub/book/cover.gmi
@@ -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
diff --git a/example-gpub/book/img/screencap_uxn-pong.gif b/example-gpub/book/img/screencap_uxn-pong.gif
new file mode 100644
index 0000000..410f914
Binary files /dev/null and b/example-gpub/book/img/screencap_uxn-pong.gif differ
diff --git a/example-gpub/book/img/screenshot_uxn-pong-paddle.png b/example-gpub/book/img/screenshot_uxn-pong-paddle.png
new file mode 100644
index 0000000..d7b011e
Binary files /dev/null and b/example-gpub/book/img/screenshot_uxn-pong-paddle.png differ
diff --git a/example-gpub/book/img/screenshot_uxn-pong-paddles-and-ball.png b/example-gpub/book/img/screenshot_uxn-pong-paddles-and-ball.png
new file mode 100644
index 0000000..81257e5
Binary files /dev/null and b/example-gpub/book/img/screenshot_uxn-pong-paddles-and-ball.png differ
diff --git a/example-gpub/book/img/screenshot_uxn-pong-paddles.png b/example-gpub/book/img/screenshot_uxn-pong-paddles.png
new file mode 100644
index 0000000..717f80c
Binary files /dev/null and b/example-gpub/book/img/screenshot_uxn-pong-paddles.png differ
diff --git a/example-gpub/book/index.gmi b/example-gpub/book/index.gmi
index a0afd33..75ca361 100644
--- a/example-gpub/book/index.gmi
+++ b/example-gpub/book/index.gmi
@@ -2,6 +2,7 @@
hello!
+=> cover.gmi an example book
=> chapter1.gmi chapter 1: an example
=> chapter2.gmi chapter 2: another example
=> chapter3.gmi chapter 3: yet another
diff --git a/g2e.awk b/g2e.awk
index 100262e..d98642a 100644
--- a/g2e.awk
+++ b/g2e.awk
@@ -35,10 +35,13 @@ BEGIN{
# setup epub
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 "mimetype " epubodir )
system( "cp -u " tdir "style.css " epubodir )
+ # copy images
+# system( "cp -u " gpubdir indexdirname "img/* " epubodir indexdirname "img/" )
+
# read templates
templatefiles = "find " tdir " -type f -not -name '.*'"
@@ -94,6 +97,21 @@ ARGIND==1{ # skip other lines of the index
# when finished reading the index:
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 "