Skip to content

Commit f70cd1e

Browse files
authored
Merge branch 'main' into feat/mdformat-extensions
2 parents 1117143 + c18abc1 commit f70cd1e

32 files changed

Lines changed: 549 additions & 193 deletions

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88
<!-- insertion marker -->
9+
## [1.4.0](https://github.com/mkdocstrings/griffe2md/releases/tag/1.4.0) - 2026-03-06
10+
11+
<small>[Compare with 1.3.4](https://github.com/mkdocstrings/griffe2md/compare/1.3.4...1.4.0)</small>
12+
13+
### Features
14+
15+
- Improve spacing in templates directly ([58e7126](https://github.com/mkdocstrings/griffe2md/commit/58e7126435573b18b040a2f22c71d29d99126c38) by Timothée Mazzucotelli). [Issue-19](https://github.com/mkdocstrings/griffe2md/issues/19)
16+
17+
### Code Refactoring
18+
19+
- Don't format code with mdformat by default ([6b8928f](https://github.com/mkdocstrings/griffe2md/commit/6b8928f00119c4b149e597690fe03f2e053ce077) by Timothée Mazzucotelli). [Issue-19](https://github.com/mkdocstrings/griffe2md/issues/19)
20+
- Mark configuration typed dict as non-total ([3636cab](https://github.com/mkdocstrings/griffe2md/commit/3636cab3bd6546482b11393b29c2cb8445dd7a7f) by Timothée Mazzucotelli).
21+
922
## [1.3.4](https://github.com/mkdocstrings/griffe2md/releases/tag/1.3.4) - 2026-02-20
1023

1124
<small>[Compare with 1.3.3](https://github.com/mkdocstrings/griffe2md/compare/1.3.3...1.3.4)</small>

config/ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ignore = [
5353
"ARG005", # Unused lambda argument
5454
"FBT001", # Boolean positional arg in function definition
5555
"PLR2004", # Magic value used in comparison
56+
"RUF001", # String contains ambiguous `–` (EN DASH)
5657
"S101", # Use of assert detected
5758
]
5859

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ classifiers = [
3131
dependencies = [
3232
"griffelib>=2.0",
3333
"jinja2>=3.1.2",
34+
# TODO: Make this an optional dependency at some point.
3435
"mdformat>=0.7.16",
3536
# YORE: EOL 3.10: Remove line.
3637
"tomli>=2.0; python_version < '3.11'",
@@ -85,6 +86,7 @@ maintain = [
8586
ci = [
8687
"duty>=1.6",
8788
"griffe>=2.0",
89+
"inline-snapshot>=0.6",
8890
"pytest>=8.2",
8991
"pytest-cov>=5.0",
9092
"pytest-randomly>=3.15",

src/griffe2md/_internal/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def get_parser() -> argparse.ArgumentParser:
3737
"""
3838
parser = argparse.ArgumentParser(prog="griffe2md")
3939
parser.add_argument("package", help="The package to output Markdown docs for.")
40+
parser.add_argument(
41+
"-f",
42+
"--format-md",
43+
action="store_true",
44+
help="Whether to format the resulting Markdown using `mdformat`.",
45+
)
4046
parser.add_argument("-o", "--output", default=None, help="File to write to. Default: stdout.")
4147
parser.add_argument(
4248
"--mdformat-extensions",

src/griffe2md/_internal/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def prepare_env(env: Environment | None = None) -> Environment:
116116
return env
117117

118118

119-
def render_object_docs(obj: Object, config: ConfigDict | None = None, *, format_md: bool = True) -> str:
119+
def render_object_docs(obj: Object, config: ConfigDict | None = None, *, format_md: bool = False) -> str:
120120
"""Render docs for a given object.
121121
122122
Parameters:
@@ -143,7 +143,7 @@ def render_object_docs(obj: Object, config: ConfigDict | None = None, *, format_
143143
return rendered
144144

145145

146-
def render_package_docs(package: str, config: ConfigDict | None = None, *, format_md: bool = True) -> str:
146+
def render_package_docs(package: str, config: ConfigDict | None = None, *, format_md: bool = False) -> str:
147147
"""Render docs for a given package.
148148
149149
Parameters:
@@ -176,7 +176,7 @@ def write_package_docs(
176176
config: ConfigDict | None = None,
177177
output: IO | str | None = None,
178178
*,
179-
format_md: bool = True,
179+
format_md: bool = False,
180180
) -> None:
181181
"""Write docs for a given package to a file or stdout.
182182

src/griffe2md/_internal/rendering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def do_order_members(
261261

262262
def do_heading(content: str, heading_level: int) -> str:
263263
"""Render a Markdown heading."""
264-
return f"\n{'#' * heading_level} {content}\n\n"
264+
return f"{'#' * heading_level} {content}"
265265

266266

267267
def do_split_path(path: str, full_path: str) -> list[tuple[str, str]]:
@@ -497,4 +497,4 @@ def do_as_modules_section(modules: Sequence[Module], *, check_public: bool = Tru
497497

498498

499499
def _newline_to_br(text: str) -> str:
500-
return text.replace("\n\n", "<br>").replace("\n", " ")
500+
return text.replace("\n\n", "<br>").strip().replace("\n", " ")

src/griffe2md/templates/attribute.md.jinja

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
{%- endif -%}
1010

1111
{%- with obj = attribute, attribute_name = attribute.path if show_full_path else attribute.name -%}
12-
{%- if not root or config.show_root_heading %}
12+
{%- if not root or config.show_root_heading -%}
1313

14-
{% filter heading(heading_level) -%}
14+
{%- filter heading(heading_level) -%}
1515
{%- if config.separate_signature -%}
1616
`{{ attribute_name }}`
17-
{%- else -%}
17+
18+
{% else -%}
1819
`{{- attribute_name }}{% if attribute.annotation -%}: {{ attribute.annotation }}{%- endif -%}`
19-
{%- endif -%}
20+
21+
{% endif -%}
2022
{%- endfilter -%}
2123

2224
{%- if config.separate_signature -%}
@@ -27,11 +29,12 @@
2729
{%- if attribute.value %} = {{ attribute.value|safe }}{%- endif -%}
2830
{%- endfilter %}
2931
```
30-
{%- endif %}
32+
33+
{% endif -%}
3134

3235
{%- else -%}
33-
{%- if config.show_root_toc_entry %}
34-
{% filter heading(heading_level) -%}
36+
{%- if config.show_root_toc_entry -%}
37+
{%- filter heading(heading_level) -%}
3538
{%- endfilter -%}
3639
{%- endif -%}
3740
{%- set heading_level = heading_level - 1 -%}
@@ -40,4 +43,4 @@
4043
{%- with docstring_sections = attribute.docstring.parsed -%}
4144
{%- include "docstring.md.jinja" with context -%}
4245
{%- endwith -%}
43-
{%- endwith -%}
46+
{%- endwith %}

src/griffe2md/templates/children.md.jinja

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,5 @@ order_members(config.members_order, members_list) -%}
148148
{%- endif -%}
149149

150150
{%- endfor -%}
151-
152151
{%- endif -%}
153-
154152
{%- endif -%}

src/griffe2md/templates/class.md.jinja

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99
{%- endif -%}
1010

1111
{%- with obj = class, class_name = class.path if show_full_path else class.name -%}
12-
{%- if not root or config.show_root_heading %}
12+
{%- if not root or config.show_root_heading -%}
1313

14-
{% filter heading(heading_level) -%}
14+
{%- filter heading(heading_level) -%}
1515
{%- if config.separate_signature -%}
1616
`{{ class_name }}`
17-
{%- elif config.merge_init_into_class and "__init__" in class.members -%}
17+
18+
{% elif config.merge_init_into_class and "__init__" in class.members -%}
1819
{%- with function = class.members["__init__"] -%}
1920
`{{ class_name }}{% include "signature.md.jinja" with context %}`
20-
{%- endwith -%}
21+
22+
{% endwith -%}
2123
{%- else -%}
2224
`{{ class_name }}`
23-
{%- endif -%}
25+
26+
{% endif -%}
2427
{%- endfilter -%}
2528

2629
{%- if config.separate_signature and config.merge_init_into_class -%}
@@ -64,4 +67,4 @@ Bases: {% for expression in class.bases -%}
6467
{%- set root = False -%}
6568
{%- set heading_level = heading_level + 1 -%}
6669
{%- include "children.md.jinja" with context -%}
67-
{%- endwith -%}
70+
{%- endwith %}
Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
{%- if docstring_sections -%}
2-
{% for section in docstring_sections %}
3-
{% if config.show_docstring_description and section.kind.value == "text" -%}
4-
{{ section.value }}
2+
{%- for section in docstring_sections -%}
3+
{%- if config.show_docstring_description and section.kind.value == "text" -%}
4+
{{- section.value }}
5+
56
{% elif config.show_docstring_attributes and section.kind.value == "attributes" -%}
6-
{% include "docstring/attributes.md.jinja" with context -%}
7+
{%- include "docstring/attributes.md.jinja" with context %}
8+
79
{% elif config.show_docstring_parameters and section.kind.value == "parameters" -%}
8-
{% include "docstring/parameters.md.jinja" with context -%}
10+
{%- include "docstring/parameters.md.jinja" with context %}
11+
912
{% elif config.show_docstring_other_parameters and section.kind.value == "other parameters" -%}
10-
{% include "docstring/other_parameters.md.jinja" with context -%}
13+
{%- include "docstring/other_parameters.md.jinja" with context %}
14+
1115
{% elif config.show_docstring_raises and section.kind.value == "raises" -%}
12-
{% include "docstring/raises.md.jinja" with context -%}
16+
{%- include "docstring/raises.md.jinja" with context %}
17+
1318
{% elif config.show_docstring_warns and section.kind.value == "warns" -%}
14-
{% include "docstring/warns.md.jinja" with context -%}
19+
{%- include "docstring/warns.md.jinja" with context %}
20+
1521
{% elif config.show_docstring_yields and section.kind.value == "yields" -%}
16-
{% include "docstring/yields.md.jinja" with context -%}
22+
{%- include "docstring/yields.md.jinja" with context %}
23+
1724
{% elif config.show_docstring_receives and section.kind.value == "receives" -%}
18-
{% include "docstring/receives.md.jinja" with context -%}
25+
{%- include "docstring/receives.md.jinja" with context %}
26+
1927
{% elif config.show_docstring_returns and section.kind.value == "returns" -%}
20-
{% include "docstring/returns.md.jinja" with context -%}
28+
{%- include "docstring/returns.md.jinja" with context %}
29+
2130
{% elif config.show_docstring_examples and section.kind.value == "examples" -%}
22-
{% include "docstring/examples.md.jinja" with context -%}
23-
{% elif config.show_docstring_description and section.kind.value == "admonition" -%}
24-
{% include "docstring/admonition.md.jinja" with context -%}
25-
{% endif %}
26-
{% endfor %}
31+
{%- include "docstring/examples.md.jinja" with context -%}
32+
33+
{%- elif config.show_docstring_description and section.kind.value == "admonition" -%}
34+
{%- include "docstring/admonition.md.jinja" with context %}
35+
36+
{% endif -%}
37+
{%- endfor -%}
2738
{%- endif -%}

0 commit comments

Comments
 (0)