Skip to content

Commit afd7ef0

Browse files
committed
fix: Replace newlines with <br> tags in table descriptions
Issue-16: #16
1 parent 30be75d commit afd7ef0

File tree

13 files changed

+16
-11
lines changed

13 files changed

+16
-11
lines changed

src/griffe2md/_internal/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def prepare_env(env: Environment | None = None) -> Environment:
111111
env.filters["split_path"] = rendering.do_split_path
112112
env.filters["stash_crossref"] = lambda ref, length: ref
113113
env.filters["from_private_package"] = rendering.from_private_package
114+
env.filters["newline_to_br"] = rendering._newline_to_br
114115

115116
return env
116117

src/griffe2md/_internal/rendering.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,7 @@ def do_as_modules_section(modules: Sequence[Module], *, check_public: bool = Tru
498498
if not check_public or module.is_public or from_private_package(module)
499499
],
500500
)
501+
502+
503+
def _newline_to_br(text: str) -> str:
504+
return text.replace("\n\n", "<br>").replace("\n", " ")

src/griffe2md/templates/docstring/attributes.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Name | Type | Description
66
---- | ---- | -----------
77
{%- for attribute in section.value %}
8-
[`{{ attribute.name }}`](#{{ obj.path }}.{{ attribute.name }}) | {% if attribute.annotation -%}{%- with expression = attribute.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ attribute.description }}
8+
[`{{ attribute.name }}`](#{{ obj.path }}.{{ attribute.name }}) | {% if attribute.annotation -%}{%- with expression = attribute.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ attribute.description|newline_to_br }} }}
99
{%- endfor -%}
1010

1111
{%- elif config.docstring_section_style == "list" %}

src/griffe2md/templates/docstring/classes.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Name | Description
66
---- | -----------
77
{%- for class in section.value %}
8-
[`{{ class.name }}`](#{{ obj.path }}.{{ class.name }}) | {{ class.description }}
8+
[`{{ class.name }}`](#{{ obj.path }}.{{ class.name }}) | {{ class.description|newline_to_br }}
99
{%- endfor -%}
1010

1111
{%- elif config.docstring_section_style == "list" %}

src/griffe2md/templates/docstring/functions.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Name | Description
66
---- | -----------
77
{%- for function in section.value %}
8-
[`{{ function.name }}`](#{{ obj.path }}.{{ function.name }}) | {{ function.description }}
8+
[`{{ function.name }}`](#{{ obj.path }}.{{ function.name }}) | {{ function.description|newline_to_br }}
99
{%- endfor -%}
1010

1111
{%- elif config.docstring_section_style == "list" %}

src/griffe2md/templates/docstring/modules.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Name | Description
66
---- | -----------
77
{%- for module in section.value %}
8-
[`{{ module.name }}`](#{{ obj.path }}.{{ module.name }}) | {{ module.description }}
8+
[`{{ module.name }}`](#{{ obj.path }}.{{ module.name }}) | {{ module.description|newline_to_br }}
99
{%- endfor -%}
1010

1111
{%- elif config.docstring_section_style == "list" %}

src/griffe2md/templates/docstring/other_parameters.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Name | Type | Description
66
---- | ---- | -----------
77
{%- for parameter in section.value %}
8-
`{{ parameter.name }}` | {% if parameter.annotation -%}{%- with expression = parameter.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ parameter.description }}
8+
`{{ parameter.name }}` | {% if parameter.annotation -%}{%- with expression = parameter.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ parameter.description|newline_to_br }}
99
{%- endfor -%}
1010

1111
{%- elif config.docstring_section_style == "list" %}

src/griffe2md/templates/docstring/parameters.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Name | Type | Description | Default
66
---- | ---- | ----------- | -------
77
{%- for parameter in section.value %}
8-
`{{ parameter.name }}` | {% if parameter.annotation -%}{%- with expression = parameter.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ parameter.description }} | {% if parameter.default -%}{%- with expression = parameter.default -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- else -%}*required*{%- endif %}
8+
`{{ parameter.name }}` | {% if parameter.annotation -%}{%- with expression = parameter.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ parameter.description|newline_to_br }} | {% if parameter.default -%}{%- with expression = parameter.default -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- else -%}*required*{%- endif %}
99
{%- endfor -%}
1010

1111
{%- elif config.docstring_section_style == "list" %}

src/griffe2md/templates/docstring/raises.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Type | Description
66
---- | -----------
77
{% for raises in section.value %}
8-
{%- if raises.annotation -%}{%- with expression = raises.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif -%} | {{ raises.description }}
8+
{%- if raises.annotation -%}{%- with expression = raises.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif -%} | {{ raises.description|newline_to_br }}
99
{% endfor %}
1010

1111
{%- elif config.docstring_section_style == "list" %}

src/griffe2md/templates/docstring/receives.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% if name_column -%}Name | {% endif -%}Type | Description
77
{% if name_column -%}---- | {% endif -%}---- | -----------
88
{% for receives in section.value %}
9-
{%- if name_column -%}{%- if receives.name -%}`{{ receives.name }}`{%- endif %} | {% endif %}{% if receives.annotation -%}{%- with expression = receives.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ receives.description }}
9+
{%- if name_column -%}{%- if receives.name -%}`{{ receives.name }}`{%- endif %} | {% endif %}{% if receives.annotation -%}{%- with expression = receives.annotation -%}<code>{%- include "expression.md.jinja" with context -%}</code>{%- endwith -%}{%- endif %} | {{ receives.description|newline_to_br }}
1010
{% endfor %}
1111

1212
{%- elif config.docstring_section_style == "list" %}

0 commit comments

Comments
 (0)