Skip to content

Commit 2bae67b

Browse files
committed
Fix incorrect markdown escaping
1 parent 1610a30 commit 2bae67b

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Pydantic's HISTORY.md](https://github.com/pydantic/pydantic/blob/main/HISTORY.md), and this project *mostly* adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## `1!0.1.0a29`
8+
9+
### Fixed
10+
11+
* Fixed incorrect Markdown escaping in `macros/styles.md.jinja`.
12+
713
## `1!0.1.0a28`
814

915
### Added

src/hexdoc/_templates/macros/formatting.jinja

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{# FormatTree handler #}
22
{% macro styled(value, safe, separator, styles) -%}
33
{%- if value is string -%}
4-
{%- for line in value.splitlines() -%}
5-
{{- line|safe if safe else line -}}
6-
{%- if not loop.last -%}{{ separator }}{%- endif -%}
7-
{%- endfor -%}
4+
{%- call styles.plain_text() -%}
5+
{%- for line in value.splitlines() -%}
6+
{{- line|safe if safe else line -}}
7+
{%- if not loop.last -%}{{ separator }}{%- endif -%}
8+
{%- endfor -%}
9+
{%- endcall -%}
810
{%- elif value is not none -%}
911
{%- call styles[value.style.macro](value.style) -%}
1012
{%- for child in value.children -%}

src/hexdoc/_templates/macros/styles.html.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{% macro plain_text() -%}
2+
{{ caller() }}
3+
{%- endmacro %}
4+
15
{# CommandStyle #}
26

37
{% macro command_obfuscated(style) -%}

src/hexdoc/_templates/macros/styles.md.jinja

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{% macro plain_text() -%}
2+
{{ caller()|replace("*", "\\*") }}
3+
{%- endmacro %}
4+
15
{# CommandStyle #}
26

37
{% macro command_obfuscated(style) -%}
@@ -52,9 +56,9 @@
5256
{# ParagraphStyle #}
5357

5458
{% macro paragraph_paragraph(style) -%}
55-
{{ caller() }}\n
59+
{{ caller()~"\n" }}
5660
{%- endmacro %}
5761

5862
{% macro paragraph_list_item(style) -%}
59-
{{ " " * style.level }}* {{ caller() }}\n
63+
{{ " " * style.level }}- {{ caller()~"\n" }}
6064
{%- endmacro %}

src/hexdoc/_templates/macros/styles.txt.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{% macro plain_text() -%}
2+
{{ caller() }}
3+
{%- endmacro %}
4+
15
{# CommandStyle #}
26

37
{% macro command_obfuscated(style) -%}

test/patchouli/test_text.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,28 @@ def flatten_html(html: str):
4646
return "".join(line.lstrip() for line in html.splitlines())
4747

4848

49-
def hexdoc_block(value: FormatTree):
49+
def hexdoc_block(value: FormatTree, ext: str = "html"):
5050
loader = PackageLoader("hexdoc", "_templates")
5151
env = create_jinja_env_with_loader(loader)
5252
template = env.from_string(
5353
"""\
54-
{%- import "macros/formatting.html.jinja" as fmt with context -%}
54+
{%- import "macros/formatting.{ext}.jinja" as fmt with context -%}
5555
{{- fmt.styled(value) -}}
56-
"""
56+
""".replace("{ext}", ext)
5757
)
5858
return template.render(value=value)
5959

6060

61+
def test_markdown_escape():
62+
tree = format_with_mocks(
63+
"all ↗ makes the result $(bold)* 2 + 1/$, all → makes it $(bold)* 2/$, and all ↘ for $(bold)/ 10/$."
64+
)
65+
assert (
66+
hexdoc_block(tree, "md")
67+
== "all ↗ makes the result **\\* 2 + 1**, all → makes it **\\* 2**, and all ↘ for **/ 10**.\n"
68+
)
69+
70+
6171
def test_link():
6272
tree = format_with_mocks("$(l:http://google.com)A$(/l)")
6373
assert (

0 commit comments

Comments
 (0)