Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ You can add the following configurations to your `conf.py` file:
* `markdown_docinfo`: Adds metadata to the top of each document containing author, copyright, and version.
* `markdown_http_base`: If set, all references will link to this prefix address
* `markdown_uri_doc_suffix`: If set, all references will link to documents with this suffix.
* `markdown_file_suffix`: Sets the file extension for generated markdown files (default: `.md`).
* `markdown_bullet`: Sets the bullet marker.

For example, if your `conf.py` file have the following configuration:
Expand Down
1 change: 1 addition & 0 deletions sphinx_markdown_builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup(app):
app.add_builder(MarkdownBuilder)
app.add_config_value("markdown_http_base", "", "html", str)
app.add_config_value("markdown_uri_doc_suffix", ".md", "html", str)
app.add_config_value("markdown_file_suffix", ".md", "html", str)
app.add_config_value("markdown_anchor_sections", False, "html", bool)
app.add_config_value("markdown_anchor_signatures", False, "html", bool)
app.add_config_value("markdown_docinfo", False, "html", bool)
Expand Down
1 change: 1 addition & 0 deletions sphinx_markdown_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, app: Sphinx, env: BuildEnvironment = None):

def init(self):
self.sec_numbers = {}
self.out_suffix = self.config.markdown_file_suffix

def _get_source_mtime(self, doc_name: str):
source_name = self.env.doc2path(doc_name)
Expand Down
35 changes: 33 additions & 2 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"autodoc_typehints=signature",
"-D",
"markdown_bullet=-",
"-D",
"markdown_file_suffix=.html.md",
],
]
BUILD_PATH_OPTIONS = [BUILD_PATH, os.path.join(BUILD_PATH, "overrides")]
Expand All @@ -56,8 +58,8 @@ def _chmod_output(build_path: str, apply_func):

for root, dirs, files in os.walk(build_path):
for file_name in files:
_, ext = os.path.splitext(file_name)
if ext == ".md":
# Check if file ends with .md
if file_name.endswith(".md"):
p = Path(root, file_name)
p.chmod(apply_func(p.stat().st_mode))

Expand Down Expand Up @@ -94,3 +96,32 @@ def test_builder_access_issue(flags: Iterable[str], build_path: str):
run_sphinx(build_path, *flags)
finally:
_chmod_output(build_path, lambda mode: mode | flag)


def test_custom_file_suffix():
"""Test that markdown_file_suffix configuration generates files with correct suffix"""
build_path = os.path.join(BUILD_PATH, "test_suffix")
suffix = ".html.md"

# Clean and build
_rm_build_path(build_path)
run_sphinx(build_path, "-a", "-D", f"markdown_file_suffix={suffix}")

# Verify files have the correct suffix
markdown_dir = os.path.join(build_path, "markdown")
assert os.path.exists(markdown_dir), f"Markdown output directory not found: {markdown_dir}"

# Check that at least one file with the custom suffix exists
found_custom_suffix = False
for root, dirs, files in os.walk(markdown_dir):
for file in files:
if file.endswith(suffix):
found_custom_suffix = True
break
if found_custom_suffix:
break

assert found_custom_suffix, f"No files with suffix '{suffix}' found in {markdown_dir}"

# Clean up
_rm_build_path(build_path)
Loading