MCPcopy
hub / github.com/vinta/awesome-python / _render_inline

Function _render_inline

website/readme_parser.py:66–93  ·  view source on GitHub ↗

Render inline AST nodes to HTML or plain text.

(children: list[SyntaxTreeNode], *, html: bool)

Source from the content-addressed store, hash-verified

64
65
66def _render_inline(children: list[SyntaxTreeNode], *, html: bool) -> str:
67 """Render inline AST nodes to HTML or plain text."""
68 parts: list[str] = []
69 for child in children:
70 match child.type:
71 case "text":
72 parts.append(str(escape(child.content)) if html else child.content)
73 case "html_inline":
74 if html:
75 parts.append(str(escape(child.content)))
76 case "softbreak":
77 parts.append(" ")
78 case "code_inline":
79 parts.append(f"<code>{escape(child.content)}</code>" if html else child.content)
80 case "link":
81 inner = _render_inline(child.children, html=html)
82 if html:
83 href = str(escape(_href(child)))
84 parts.append(f'<a href="{href}" target="_blank" rel="noopener">{inner}</a>')
85 else:
86 parts.append(inner)
87 case "em":
88 inner = _render_inline(child.children, html=html)
89 parts.append(f"<em>{inner}</em>" if html else inner)
90 case "strong":
91 inner = _render_inline(child.children, html=html)
92 parts.append(f"<strong>{inner}</strong>" if html else inner)
93 return "".join(parts)
94
95
96def render_inline_html(children: list[SyntaxTreeNode]) -> str:

Callers 2

render_inline_htmlFunction · 0.85
render_inline_textFunction · 0.85

Calls 1

_hrefFunction · 0.85

Tested by

no test coverage detected