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"<{ m .group (3 )} >"
44+ return _CODE_SPAN_OR_TAG .sub (repl , text )
45+
46+
3547def 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
4052def 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