Skip to content

Add markdown file and directory support#138

Open
brianmatzelle wants to merge 3 commits intobugzmanov:mainfrom
brianmatzelle:feature/markdown-support
Open

Add markdown file and directory support#138
brianmatzelle wants to merge 3 commits intobugzmanov:mainfrom
brianmatzelle:feature/markdown-support

Conversation

@brianmatzelle
Copy link
Copy Markdown
Contributor

@brianmatzelle brianmatzelle commented Apr 13, 2026

Summary

  • Open single .md files as one-chapter books (e.g. bookokrat README.md)
  • Open directories containing .md files as multi-chapter books with TOC (e.g. bookokrat wiki/)
  • Markdown directories get proper chapter ordering: Home.md/README.md/index.md sorted first, then alphabetical
  • Uses pulldown-cmark for GFM-compatible conversion (tables, strikethrough, task lists)
  • Markdown files and directories appear in the library browser alongside EPUBs and PDFs

How 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 .md file becomes a chapter with a proper toc.ncx for navigation.

No changes to the rendering pipeline, text reader, or PDF infrastructure.

Changes

  • Cargo.toml — add pulldown-cmark dependency
  • src/book_manager.rsBookFormat::Markdown variant, format detection for .md files and markdown directories, markdown_to_html(), create_fake_epub_from_markdown() (single file), create_epub_from_markdown_dir() (multi-chapter), 6 new unit tests
  • src/main_app.rs — route BookFormat::Markdown to the EPUB loader
  • src/main.rs — update help text

Test plan

  • All 385 existing tests pass (zero regressions)
  • 6 new unit tests covering: format detection for .md files, 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 .md files, library discovery of markdown directories
  • Manual testing: bookokrat path/to/file.md opens and renders correctly
  • Manual testing: bookokrat path/to/wiki/ opens as multi-chapter book with TOC sidebar

🤖 Generated with Claude Code

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>
@brianmatzelle
Copy link
Copy Markdown
Contributor Author

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

brianmatzelle and others added 2 commits April 13, 2026 15:47
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>
@bugzmanov
Copy link
Copy Markdown
Owner

@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: Markdown → HTML → EPUB → HTML → Markdown AST → render. too many extra steps that looks unnecessary.

What do you think about implementing a markdown parser? that transforts text to custom markdown AST (src/markdown.rs) ?
Potentially i would reuse that feature to support markdown-based comments in the future :)

(+ branch has conflicts with main)

@brianmatzelle
Copy link
Copy Markdown
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants