|
5 | 5 | # https://github.com/kevinmcaleer/tiny_wiki |
6 | 6 | import re |
7 | 7 |
|
| 8 | + |
| 9 | +def _escape_html(text): |
| 10 | + """Escape HTML special characters""" |
| 11 | + text = text.replace('&', '&') |
| 12 | + text = text.replace('<', '<') |
| 13 | + text = text.replace('>', '>') |
| 14 | + text = text.replace('"', '"') |
| 15 | + return text |
| 16 | + |
| 17 | + |
8 | 18 | class SimpleMarkdown: |
9 | 19 | """Lightweight markdown parser optimized for MicroPython""" |
10 | 20 |
|
@@ -72,7 +82,7 @@ def to_html(self, markdown_text): |
72 | 82 | continue |
73 | 83 |
|
74 | 84 | if in_code_block: |
75 | | - code_block_lines.append(self._escape_html(line)) |
| 85 | + code_block_lines.append(_escape_html(line)) |
76 | 86 | i += 1 |
77 | 87 | continue |
78 | 88 |
|
@@ -142,7 +152,7 @@ def apply_formatting(segment): |
142 | 152 | code_spans = [] |
143 | 153 |
|
144 | 154 | def replace_code_span(match): |
145 | | - code_text = self._escape_html(match.group(1)) |
| 155 | + code_text = _escape_html(match.group(1)) |
146 | 156 | code_spans.append('<code>{}</code>'.format(code_text)) |
147 | 157 | return '%%CODESPAN{}%%'.format(len(code_spans) - 1) |
148 | 158 |
|
@@ -181,11 +191,3 @@ def replace_code_span(match): |
181 | 191 | index = end |
182 | 192 |
|
183 | 193 | return ''.join(result) |
184 | | - |
185 | | - def _escape_html(self, text): |
186 | | - """Escape HTML special characters""" |
187 | | - text = text.replace('&', '&') |
188 | | - text = text.replace('<', '<') |
189 | | - text = text.replace('>', '>') |
190 | | - text = text.replace('"', '"') |
191 | | - return text |
|
0 commit comments