Add markdown file and directory support#138
Add markdown file and directory support#138brianmatzelle wants to merge 3 commits intobugzmanov:mainfrom
Conversation
Open single .md files or directories containing .md files as books. Single files become one-chapter EPUBs. Directories become multi-chapter EPUBs with TOC (Home/README/index sorted first). Uses pulldown-cmark for GFM-compatible markdown-to-HTML conversion (tables, strikethrough, task lists). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hi @bugzmanov ! I generated this feature with Claude Code, so I could read my project's Markdown wikis with bookokrat. It works great for me locally. Completely understand if you'd rather close this PR though to keep bookokrat centered around .epubs |
When building a multi-chapter EPUB from a markdown directory, href targets like Getting-Started.md now map to the correct chapter file (e.g. chapter3.xhtml), including anchors (Guide.md#setup -> chapter3.xhtml#setup). This enables navigating between wiki pages via internal links. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Strip trailing '/' so "wiki/" matches "wiki" in the book list. Fixes opening markdown directories with a trailing slash. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@brianmatzelle i like this feature! (i'm reading more markdown files than books these days 😩) But design wise i don't like new dependency (pulldown-cmark). And the proposed design makes the processing pipeline a bit weird: What do you think about implementing a markdown parser? that transforts text to custom markdown AST (src/markdown.rs) ? (+ branch has conflicts with main) |
|
I agree that this implementation is a bit weird since it was vibe coded. Sure, I'll look into it with more detail and see what I can do. Less vibe code and more whiteboard, ya know? |
Summary
.mdfiles as one-chapter books (e.g.bookokrat README.md).mdfiles as multi-chapter books with TOC (e.g.bookokrat wiki/)Home.md/README.md/index.mdsorted first, then alphabeticalHow it works
Follows the same pattern as the existing HTML file support — markdown content is converted to HTML via pulldown-cmark, then wrapped in a temporary EPUB that the existing rendering pipeline handles. For directories, each
.mdfile becomes a chapter with a propertoc.ncxfor navigation.No changes to the rendering pipeline, text reader, or PDF infrastructure.
Changes
Cargo.toml— addpulldown-cmarkdependencysrc/book_manager.rs—BookFormat::Markdownvariant, format detection for.mdfiles and markdown directories,markdown_to_html(),create_fake_epub_from_markdown()(single file),create_epub_from_markdown_dir()(multi-chapter), 6 new unit testssrc/main_app.rs— routeBookFormat::Markdownto the EPUB loadersrc/main.rs— update help textTest plan
.mdfiles, format detection for markdown directories, single file loading with HTML conversion verification, multi-chapter directory loading with chapter count and ordering verification, library discovery of.mdfiles, library discovery of markdown directoriesbookokrat path/to/file.mdopens and renders correctlybookokrat path/to/wiki/opens as multi-chapter book with TOC sidebar🤖 Generated with Claude Code