Skip to content

Commit 856d994

Browse files
committed
move _escape_html() out of class to normal function.
1 parent 6087887 commit 856d994

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Fruit_Jam/Fruit_Jam_Tiny_Wiki/tiny_wiki/markdown.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
# https://github.com/kevinmcaleer/tiny_wiki
66
import re
77

8+
9+
def _escape_html(text):
10+
"""Escape HTML special characters"""
11+
text = text.replace('&', '&')
12+
text = text.replace('<', '&lt;')
13+
text = text.replace('>', '&gt;')
14+
text = text.replace('"', '&quot;')
15+
return text
16+
17+
818
class SimpleMarkdown:
919
"""Lightweight markdown parser optimized for MicroPython"""
1020

@@ -72,7 +82,7 @@ def to_html(self, markdown_text):
7282
continue
7383

7484
if in_code_block:
75-
code_block_lines.append(self._escape_html(line))
85+
code_block_lines.append(_escape_html(line))
7686
i += 1
7787
continue
7888

@@ -142,7 +152,7 @@ def apply_formatting(segment):
142152
code_spans = []
143153

144154
def replace_code_span(match):
145-
code_text = self._escape_html(match.group(1))
155+
code_text = _escape_html(match.group(1))
146156
code_spans.append('<code>{}</code>'.format(code_text))
147157
return '%%CODESPAN{}%%'.format(len(code_spans) - 1)
148158

@@ -181,11 +191,3 @@ def replace_code_span(match):
181191
index = end
182192

183193
return ''.join(result)
184-
185-
def _escape_html(self, text):
186-
"""Escape HTML special characters"""
187-
text = text.replace('&', '&amp;')
188-
text = text.replace('<', '&lt;')
189-
text = text.replace('>', '&gt;')
190-
text = text.replace('"', '&quot;')
191-
return text

0 commit comments

Comments
 (0)