Skip to content

Commit be43a65

Browse files
committed
Format minified front matter with literal blocks
1 parent ee1f1e1 commit be43a65

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

.verify-helper/scripts/inject_minified_docs.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
import yaml
1414

1515

16+
class _LiteralDumper(yaml.SafeDumper):
17+
"""Dump multiline strings using literal style so code stays readable."""
18+
19+
20+
def _str_presenter(dumper, data):
21+
if isinstance(data, str) and "\n" in data:
22+
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style='|')
23+
return dumper.represent_scalar("tag:yaml.org,2002:str", data)
24+
25+
26+
# Register custom string representer
27+
_LiteralDumper.add_representer(str, _str_presenter)
28+
29+
1630
def inject_minified_to_markdown(markdown_file, minified_code=None, minified_bundled_code=None):
1731
"""Inject minified code into markdown file's front matter using proper YAML parsing."""
1832
try:
@@ -62,9 +76,14 @@ def inject_minified_to_markdown(markdown_file, minified_code=None, minified_bund
6276
if not updated:
6377
return False
6478

65-
# Re-serialize YAML front matter
66-
# Use default_flow_style=False to keep lists as blocks, allow_unicode=True for special chars
67-
new_front_matter_str = yaml.dump(front_matter, default_flow_style=False, allow_unicode=True, sort_keys=False)
79+
# Re-serialize YAML front matter with literal blocks for multiline strings
80+
new_front_matter_str = yaml.dump(
81+
front_matter,
82+
Dumper=_LiteralDumper,
83+
default_flow_style=False,
84+
allow_unicode=True,
85+
sort_keys=False,
86+
)
6887

6988
# Write updated content
7089
new_content = f'---{new_front_matter_str}---{body}'

0 commit comments

Comments
 (0)