Skip to content

Add a singlemarkdown builder#49

Open
AdrianAtZyte wants to merge 39 commits intoliran-funaro:mainfrom
AdrianAtZyte:singlemarkdown
Open

Add a singlemarkdown builder#49
AdrianAtZyte wants to merge 39 commits intoliran-funaro:mainfrom
AdrianAtZyte:singlemarkdown

Conversation

@AdrianAtZyte
Copy link
Copy Markdown

@AdrianAtZyte AdrianAtZyte commented Mar 24, 2026

Attempt at reviving #37.

Includes a few additional changes and a bit of clean up, including:

  • Made admonitions use the same header + body in blockquote formatting that I noticed is used for .. contents. I think that’s a much nicer rendering. But this change it out of scope, and quite opinionated, so I am more than willing to drop that.
  • Added support for the tip admonition.
  • A singlemarkdown_flavor option that, if set to llm, generates a file without fluff not required by LLMs (e.g. toctrees and anchors).
  • Added expected files for the entire rendering of the test sources, for both flavors.
  • Increased the header levels for singlemarkdown, so that only the documentation title uses level 1.
  • Made only work with singlemarkdown as well.
  • Silenced some warnings about unknown directives.
  • Removed the changelog test content from the original PR.

I did merging instead of rebasing, I hope that’s OK. I know the contribution guidelines say to rebase, but assuming the reason is keeping the main history clean, I hope you can achieve that by squash-merging instead.

Resolves #37.

akaihola and others added 24 commits October 31, 2025 20:38
This commit adds a functional SingleFileMarkdownBuilder that generates a single consolidated Markdown file from Sphinx documentation rather than separate files for each document.

Key changes:
- Complete implementation of SingleFileMarkdownBuilder with custom write_documents() method
- Add custom SingleMarkdownTranslator to properly handle document anchors and styling
- Add table of contents and document anchors to improve navigation in the single file
- Simplify cross-references by using document anchors within the same file
- Reformat test file to follow code style without functional changes

The builder can be used with: sphinx-build -M singlemarkdown ./docs ./build
The output will be a single file at ./build/singlemarkdown/<root_doc>.md
…tion errors

- Refactor setup function in __init__.py with proper type hints and return metadata
- Update singlemarkdown.py to follow Sphinx extension pattern by removing duplicate builder registration
- Follow pattern from Sphinx's singlehtml.py implementation
- Ensure proper extension loading through app.setup_extension
This commit adds the missing render_partial method to the SingleFileMarkdownBuilder class,
which resolves the 'no-member' errors in the singlemarkdown.py file.

The implementation:
- Creates a proper render_partial method based on Sphinx's similar functionality
- Uses StringOutput instead of StringIO for proper document rendering
- Ensures correct type handling for method return values
- Updates write_documents method to use StringOutput for consistency

Fixes E1101: Instance of 'SingleFileMarkdownBuilder' has no 'render_partial' member (no-member)
- Add proper type annotations to class attributes and method parameters/return types
- Fix potential type incompatibilities with appropriate casts
- Add pyright-specific comments to suppress false positives
- Improve variable naming and eliminate unused variables
- Replace implicit variable assignments with explicit ones using underscore
…nnotations

- Add extensive unit tests for SingleFileMarkdownBuilder methods
- Create separate test file for SingleMarkdownTranslator
- Improve Path handling in tests using pathlib
- Add proper type annotations for MarkdownWriter variable
- Test error handling and edge cases for better coverage
- Add parametrized tests to test singlemarkdown with various configuration options
- Test handling of missing build directories
- Test handling of file permission issues
- Match the integration test pattern from test_builder.py
- Enhance error handling and coverage
@AdrianAtZyte AdrianAtZyte mentioned this pull request Mar 25, 2026
2 tasks
@AdrianAtZyte AdrianAtZyte marked this pull request as draft March 26, 2026 15:43
@AdrianAtZyte AdrianAtZyte marked this pull request as ready for review March 26, 2026 15:56
@AdrianAtZyte AdrianAtZyte marked this pull request as draft March 26, 2026 17:01
@AdrianAtZyte AdrianAtZyte marked this pull request as ready for review March 30, 2026 13:45
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