Skip to content

Commit ff1b8c1

Browse files
authored
Merge pull request #166 from rok/fix_benchx_search_docs
DOC: escape raw HTML placeholders breaking docs search and rendering
2 parents 3c45de7 + 766cb10 commit ff1b8c1

5 files changed

Lines changed: 28 additions & 18 deletions

File tree

‎docs/use-cases/UC-01-short-slug.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Benchmark Use Case Template
2-
31
## UC-01: Run a single parametrized benchmark
42

53
| | |

‎docs/use-cases/UC_NN_TEMPLATE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ shape stays comparable across documents.
1212

1313
---
1414

15-
## UC-NN: <title>
15+
## UC-NN: &lt;title&gt;
1616

1717
| | |
1818
|---|---|

‎docs/user_stories/TEMPLATE.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ you need.
1111

1212
---
1313

14-
# <Project name> user stories
14+
# &lt;Project name&gt; user stories
1515

16-
**Project:** <name, link>
17-
**Current benchmarking setup:** <one or two sentences: what you run, how often,
16+
**Project:** &lt;name, link&gt;
17+
**Current benchmarking setup:** &lt;one or two sentences: what you run, how often,
1818
where results go — e.g. "nightly ASV runs on two dedicated machines, results
19-
published as a static site">
20-
**Contact:** <name/handle for follow-up questions>
19+
published as a static site"&gt;
20+
**Contact:** &lt;name/handle for follow-up questions&gt;
2121

2222
## Who uses benchmarks here
2323

@@ -29,9 +29,9 @@ infra operator, …). One line each on what they care about.
2929

3030
Use as many as apply. Format:
3131

32-
### <Short title>
32+
### &lt;Short title&gt;
3333

34-
> As a <role>, I want <goal>, so that <why it matters>.
34+
> As a &lt;role&gt;, I want &lt;goal&gt;, so that &lt;why it matters&gt;.
3535
3636
**Today:** How this works right now, in a sentence or two.
3737
**Pain:** Where the current experience falls short, if it does.

‎docs/user_stories/openblas_user_stories.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# <OpenBLAS> user stories
1+
# OpenBLAS user stories
22

33
**Project:** [OpenBLAS](https://github.com/OpenMathLib/OpenBLAS)
44
**Current benchmarking setup:** One set of benchmarks is on `codspeed`, runs in each PR;

‎tools/gen_docs.py‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,21 @@
3232

3333
# --------------------------------------------------------------------------- utilities
3434

35+
_CODE_SPAN_OR_TAG = re.compile(r"(`[^`\n]*`)|(<(?!https?://|mailto:)(/?[a-zA-Z][^>\n]*)>)")
36+
37+
38+
def esc_prose(text: str) -> str:
39+
"""Escape angle-bracket placeholders outside inline code so Markdown does not parse them as HTML tags."""
40+
def repl(m: re.Match) -> str:
41+
if m.group(1) is not None:
42+
return m.group(1)
43+
return f"&lt;{m.group(3)}&gt;"
44+
return _CODE_SPAN_OR_TAG.sub(repl, text)
45+
46+
3547
def esc(text: str) -> str:
3648
"""Make a description safe inside a Markdown table cell."""
37-
return text.replace("|", "\\|").replace("\n", " ").strip()
49+
return esc_prose(text).replace("|", "\\|").replace("\n", " ").strip()
3850

3951

4052
def code(value) -> str:
@@ -368,11 +380,11 @@ def render_object(s: dict, page: "SchemaPage", path: list[str], level: int, out:
368380
out.append(f"{hashes} `{'.'.join(sub_path)}` {{ #{anchor(sub_path)} }}")
369381
out.append("")
370382
if sub.get("description"):
371-
out.append(sub["description"].strip())
383+
out.append(esc_prose(sub["description"].strip()))
372384
out.append("")
373385
if sub.get("$comment"):
374386
out.append('!!! note "Implementer note"')
375-
out.append(" " + sub["$comment"].strip().replace("\n", "\n "))
387+
out.append(" " + esc_prose(sub["$comment"].strip()).replace("\n", "\n "))
376388
out.append("")
377389
if has_table(sub):
378390
render_object(sub, page, sub_path, min(level + 1, 6), out)
@@ -405,11 +417,11 @@ def render(self, repo_url: str | None) -> str:
405417
out.append("Older versions: " + ", ".join(f"[{v}]({self.name}/{v}/schema.json)" for v in self.older))
406418
out.append("")
407419
if s.get("description"):
408-
out.append(s["description"].strip())
420+
out.append(esc_prose(s["description"].strip()))
409421
out.append("")
410422
if s.get("$comment"):
411423
out.append('!!! note "Implementer note"')
412-
out.append(" " + s["$comment"].strip().replace("\n", "\n "))
424+
out.append(" " + esc_prose(s["$comment"].strip()).replace("\n", "\n "))
413425
out.append("")
414426
out.append("## Properties")
415427
out.append("")
@@ -428,11 +440,11 @@ def render(self, repo_url: str | None) -> str:
428440
out.append(f"### `{name}` {{ #{anchor(['def', name])} }}")
429441
out.append("")
430442
if isinstance(d, dict) and d.get("description"):
431-
out.append(d["description"].strip())
443+
out.append(esc_prose(d["description"].strip()))
432444
out.append("")
433445
if isinstance(d, dict) and d.get("$comment"):
434446
out.append('!!! note "Implementer note"')
435-
out.append(" " + d["$comment"].strip().replace("\n", "\n "))
447+
out.append(" " + esc_prose(d["$comment"].strip()).replace("\n", "\n "))
436448
out.append("")
437449
if has_table(d):
438450
render_object(d, self, [name], 3, out)

0 commit comments

Comments
 (0)