Skip to content

Commit

Permalink
Fix rendering of default field values in reference docs. (pantsbuild#…
Browse files Browse the repository at this point in the history
…13891)

Readme renders some markdown even inside <pre>/<code> tags,
including, as it turns out, * and _. So we turn them into
the corresponding HTML entities.

[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
benjyw authored Dec 15, 2021
1 parent 1a39d31 commit 0740725
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions build-support/bin/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ def munge_option(option_data):
else:
# It should already be a string, but might as well be safe.
default_str = to_help_str(default_help_repr)
escaped_default_str = html.escape(default_str, quote=False)
escaped_default_str = (
html.escape(default_str, quote=False).replace("*", "&ast;").replace("_", "&lowbar;")
)
if "\n" in default_str:
option_data["marked_up_default"] = f"<pre>{escaped_default_str}</pre>"
else:
Expand All @@ -354,7 +356,11 @@ def process_targets_input(cls, help_info: dict[str, Any]) -> dict[str, dict[str,
for target in target_info.values():
for field in target["fields"]:
# Combine the `default` and `required` properties.
default_str = html.escape(str(field["default"]))
default_str = (
html.escape(str(field["default"]))
.replace("*", "&ast;")
.replace("_", "&lowbar;")
)
field["default_or_required"] = (
"required" if field["required"] else f"default: <code>{default_str}</code>"
)
Expand Down

0 comments on commit 0740725

Please sign in to comment.