Skip to content

Commit 06be87e

Browse files
committed
Move xml_oneliner_re_from_tab_width to utils
1 parent 2ecaed9 commit 06be87e

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

lib/markdown2.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
dedentlines,
121121
dedent,
122122
memoized,
123+
xml_oneliner_re_from_tab_width,
123124
)
124125

125126
# ---- globals
@@ -852,7 +853,7 @@ def _hash_html_blocks(self, text, raw=False):
852853
# <?foo bar?>
853854
#
854855
# <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="chapter_1.md"/>
855-
_xml_oneliner_re = _xml_oneliner_re_from_tab_width(self.tab_width)
856+
_xml_oneliner_re = xml_oneliner_re_from_tab_width(self.tab_width)
856857
text = _xml_oneliner_re.sub(hash_html_block_sub, text)
857858

858859
return text
@@ -2478,29 +2479,6 @@ class UnicodeWithAttrs(str):
24782479
metadata = None
24792480
toc_html = None
24802481

2481-
2482-
def _xml_oneliner_re_from_tab_width(tab_width):
2483-
"""Standalone XML processing instruction regex."""
2484-
return re.compile(r"""
2485-
(?:
2486-
(?<=\n\n) # Starting after a blank line
2487-
| # or
2488-
\A\n? # the beginning of the doc
2489-
)
2490-
( # save in $1
2491-
[ ]{0,%d}
2492-
(?:
2493-
<\?\w+\b\s+.*?\?> # XML processing instruction
2494-
|
2495-
<\w+:\w+\b\s+.*?/> # namespaced single tag
2496-
)
2497-
[ \t]*
2498-
(?=\n{2,}|\Z) # followed by a blank line or end of document
2499-
)
2500-
""" % (tab_width - 1), re.X)
2501-
_xml_oneliner_re_from_tab_width = memoized(_xml_oneliner_re_from_tab_width)
2502-
2503-
25042482
def _hr_tag_re_from_tab_width(tab_width):
25052483
return re.compile(r"""
25062484
(?:

lib/utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,27 @@ def __call__(self, *args):
212212

213213
def __repr__(self):
214214
"""Return the function's docstring."""
215-
return self.func.__doc__
215+
return self.func.__doc__
216+
217+
218+
219+
def xml_oneliner_re_from_tab_width(tab_width):
220+
"""Standalone XML processing instruction regex."""
221+
return re.compile(r"""
222+
(?:
223+
(?<=\n\n) # Starting after a blank line
224+
| # or
225+
\A\n? # the beginning of the doc
226+
)
227+
( # save in $1
228+
[ ]{0,%d}
229+
(?:
230+
<\?\w+\b\s+.*?\?> # XML processing instruction
231+
|
232+
<\w+:\w+\b\s+.*?/> # namespaced single tag
233+
)
234+
[ \t]*
235+
(?=\n{2,}|\Z) # followed by a blank line or end of document
236+
)
237+
""" % (tab_width - 1), re.X)
238+
xml_oneliner_re_from_tab_width = memoized(xml_oneliner_re_from_tab_width)

0 commit comments

Comments
 (0)