Created
January 24, 2026 21:33
-
-
Save ickc/9007d41a73535f6c52d6e41d734f6435 to your computer and use it in GitHub Desktop.
convert all epubs to md/txt via pandoc/ebook-convert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # batch convert EPUB files to Markdown and plaintext via Pandoc and Calibre's ebook-convert | |
| version: '3' | |
| vars: | |
| OUT_DIR: dist | |
| tasks: | |
| pandoc-md: | |
| desc: 'Convert a specific EPUB file to Markdown (Usage: task convert FILE=book.epub)' | |
| summary: | | |
| Converts an EPUB to Markdown using Pandoc. | |
| Requires: pandoc | |
| cmds: | |
| - mkdir -p {{.OUT_DIR}} | |
| - pandoc '{{.FILE}}' -f epub-native_spans-native_divs -t markdown-fenced_code_attributes-header_attributes-inline_code_attributes-link_attributes-native_divs-native_spans-raw_attribute-raw_html-table_attributes -o '{{.OUT_DIR}}/pandoc.md' | |
| preconditions: | |
| - sh: "command -v pandoc" | |
| msg: "Pandoc is not installed. Please install it first." | |
| - sh: "test -f '{{.FILE}}'" | |
| msg: "File {{.FILE}} not found." | |
| pandoc-txt: | |
| desc: 'Convert a specific EPUB file to plaintext (Usage: task convert FILE=book.epub)' | |
| summary: | | |
| Converts an EPUB to plaintext using Pandoc. | |
| Requires: pandoc | |
| cmds: | |
| - mkdir -p {{.OUT_DIR}} | |
| - pandoc '{{.FILE}}' -t plain -o '{{.OUT_DIR}}/pandoc.txt' | |
| preconditions: | |
| - sh: "command -v pandoc" | |
| msg: "Pandoc is not installed. Please install it first." | |
| - sh: "test -f '{{.FILE}}'" | |
| msg: "File {{.FILE}} not found." | |
| pandoc-mds: | |
| desc: Convert all EPUB files in the current directory to markdown | |
| cmds: | |
| - for: { var: FILES, split: "\n" } | |
| task: pandoc-md | |
| vars: { FILE: "{{.ITEM}}" } | |
| vars: | |
| FILES: | |
| sh: ls *.epub | |
| pandoc-txts: | |
| desc: Convert all EPUB files in the current directory to plaintext | |
| cmds: | |
| - for: { var: FILES, split: "\n" } | |
| task: pandoc-txt | |
| vars: { FILE: "{{.ITEM}}" } | |
| vars: | |
| FILES: | |
| sh: ls *.epub | |
| ebook-convert-md: | |
| desc: 'Convert a specific EPUB file to Markdown (Usage: task convert FILE=book.epub)' | |
| summary: | | |
| Converts an EPUB to plaintext using ebook-convert and saves it with a .md extension. | |
| Calibre does not support Markdown output directly. | |
| Requires: ebook-convert | |
| cmds: | |
| - mkdir -p {{.OUT_DIR}} | |
| - ebook-convert '{{.FILE}}' '{{.OUT_DIR}}/ebook-convert.txt' --txt-output-format markdown | |
| - mv -f '{{.OUT_DIR}}/ebook-convert.txt' '{{.OUT_DIR}}/epub-convert.md' | |
| preconditions: | |
| - sh: "command -v ebook-convert" | |
| msg: "ebook-convert is not installed. Please install it first." | |
| - sh: "test -f '{{.FILE}}'" | |
| msg: "File {{.FILE}} not found." | |
| ebook-convert-txt: | |
| desc: 'Convert a specific EPUB file to plaintext (Usage: task convert FILE=book.epub)' | |
| summary: | | |
| Converts an EPUB to plaintext using ebook-convert. | |
| Requires: ebook-convert | |
| cmds: | |
| - mkdir -p {{.OUT_DIR}} | |
| - ebook-convert '{{.FILE}}' '{{.OUT_DIR}}/ebook-convert-plain.txt' | |
| preconditions: | |
| - sh: "command -v ebook-convert" | |
| msg: "ebook-convert is not installed. Please install it first." | |
| - sh: "test -f '{{.FILE}}'" | |
| msg: "File {{.FILE}} not found." | |
| ebook-convert-mds: | |
| desc: Convert all EPUB files in the current directory to markdown | |
| cmds: | |
| - for: { var: FILES, split: "\n" } | |
| task: ebook-convert-md | |
| vars: { FILE: "{{.ITEM}}" } | |
| vars: | |
| FILES: | |
| sh: ls *.epub | |
| ebook-convert-txts: | |
| desc: Convert all EPUB files in the current directory to plaintext | |
| cmds: | |
| - for: { var: FILES, split: "\n" } | |
| task: ebook-convert-txt | |
| vars: { FILE: "{{.ITEM}}" } | |
| vars: | |
| FILES: | |
| sh: ls *.epub | |
| pandoc: | |
| desc: Run all Pandoc conversions | |
| cmds: | |
| - task: pandoc-mds | |
| - task: pandoc-txts | |
| ebook-convert: | |
| desc: Run all ebook-convert conversions | |
| cmds: | |
| - task: ebook-convert-mds | |
| - task: ebook-convert-txts | |
| all: | |
| desc: Run all conversions (Pandoc + ebook-convert) | |
| cmds: | |
| - task: pandoc | |
| - task: ebook-convert | |
| clean: | |
| desc: Clean the output directory | |
| cmds: | |
| - rm -rf {{.OUT_DIR}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment