(node: Any, out: Text)
| 95 | |
| 96 | |
| 97 | def _append_inline(node: Any, out: Text) -> None: |
| 98 | t = node.type |
| 99 | if t == "text": |
| 100 | out.append(node.content) |
| 101 | elif t == "softbreak": |
| 102 | out.append("\n") |
| 103 | elif t == "hardbreak": |
| 104 | out.append("\n") |
| 105 | elif t == "strong": |
| 106 | piece = Text() |
| 107 | for child in node.children or []: |
| 108 | _append_inline(child, piece) |
| 109 | piece.stylize("bold") |
| 110 | out.append_text(piece) |
| 111 | elif t == "em": |
| 112 | piece = Text() |
| 113 | for child in node.children or []: |
| 114 | _append_inline(child, piece) |
| 115 | piece.stylize("italic") |
| 116 | out.append_text(piece) |
| 117 | elif t == "code_inline": |
| 118 | out.append(node.content, style=INLINE_CODE_STYLE) |
| 119 | elif t == "link": |
| 120 | href = node.attrGet("href") or "" |
| 121 | piece = Text() |
| 122 | for child in node.children or []: |
| 123 | _append_inline(child, piece) |
| 124 | if href.startswith("mailto:"): |
| 125 | email = href[len("mailto:") :] |
| 126 | plain = piece.plain |
| 127 | if plain and plain != email and plain != href: |
| 128 | piece.stylize(f"link {href}") |
| 129 | out.append_text(piece) |
| 130 | else: |
| 131 | out.append(email, style=f"link {href}") |
| 132 | return |
| 133 | if href: |
| 134 | plain = piece.plain |
| 135 | if plain and plain != href: |
| 136 | piece.stylize(f"link {href}") |
| 137 | out.append_text(piece) |
| 138 | else: |
| 139 | out.append(href, style=f"link {href}") |
| 140 | else: |
| 141 | out.append_text(piece) |
| 142 | elif t == "image": |
| 143 | href = node.attrGet("src") or "" |
| 144 | out.append(href) |
| 145 | elif t in ("html_inline", "html_block"): |
| 146 | out.append(node.content) |
| 147 | else: |
| 148 | content = getattr(node, "content", "") |
| 149 | if content: |
| 150 | out.append(content) |
| 151 | |
| 152 | |
| 153 | def _append_with_cont_indent(target: Text, source: Text, cont_indent: str) -> None: |
no outgoing calls
no test coverage detected