💾 Archived View for gem.hexandcounter.org › gemlog › posts › md2gmi.gmi captured on 2022-04-29 at 11:18:18. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-03-01)

-=-=-=-=-=-=-

Markdown to Gemini Text Chapters

I was looking for a way to convert a single Markdown document to one Gemini document per chapter, turning links to chapters into links to other files. There was no obvious way to do so using Pandoc as it only supports a single output document file, but an answer on Stackoverflow mentioned a trick.

trick on stackoverflow

So the steps goes something like this (and you probably should put this in a Makefile or something):

1. Use Pandoc to convert your document to EPUB.

2. Unzip the EPUB somewhere to get a pile of XHTML files.

3. Convert each individual file from XHTML to GMI.

4. Replace ".xhtml" in all files with ".gmi" to make the inter-chapter links correct.

Or something like the following, more or less. Except that I am not sure how to do step 3 in the best way. Possibly using Pandoc or possibly using some other script someone wrote, or a combination.

pandoc -o document.epub document.md
unzip document.epub
for c in EPUB/text/*.xhtml; do pandoc -o $(basename $c .xhtml).md $c; done
  (handwaves converting *.md to *.gmi)
for f in *.gmi; do sed -i s/.xhtml/.gmi/ $f; done

With this you can, for instance, write your own gamebooks in Markdown and turn into a collection of static Gemini text files on your capsule.

Pangamebook

If there is ever support in Pandoc for creating multiple output documents all this should be possible in a single command-line, including the Pangamebook filtering to number and shuffle chapters, if you want that.

Pandoc feature request for multiple file outputs

tags: #gemtext #markdown #foss #gamebooks #pandoc

Gemlog

Home