+82
-8
lines changedFilter options
+82
-8
lines changed Original file line number Diff line number Diff line change
@@ -30,10 +30,18 @@ markdown.markdown(src, extensions=[TableExtension(use_align_attribute=True)])
30
30
31
31
In addition, tests were moved to the modern test environment.
32
32
33
+
### Backslash unescaping moved to Treeprocessor (#1131).
34
+
35
+
Unescaping backslash escapes has been moved to a Treeprocessor. However, it is
36
+
recognized that various third-party extensions may be calling the old class at
37
+
`postprocessors.UnescapePostprocessor`. Therefore, the old class remains in the
38
+
code base, but has been deprecated and will be removed in a future release. The
39
+
new class `treeprocessors.UnescapeTreeprocessor` should be used instead.
40
+
33
41
### Previously deprecated objects have been removed
34
42
35
43
Various objects were deprecated in version 3.0 and began raising deprecation
36
-
warnings (see the [version 3.0 release notes] for details). Any of those object
44
+
warnings (see the [version 3.0 release notes] for details). Any of those objects
37
45
which remained in version 3.3 have been removed from the code base in version 3.4
38
46
and will now raise errors. A summary of the objects are provided below.
39
47
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
16
16
from . import Extension
17
17
from ..treeprocessors import Treeprocessor
18
18
from ..util import code_escape, parseBoolValue, AMP_SUBSTITUTE, HTML_PLACEHOLDER_RE, AtomicString
19
-
from ..postprocessors import UnescapePostprocessor
19
+
from ..treeprocessors import UnescapeTreeprocessor
20
20
import re
21
21
import html
22
22
import unicodedata
@@ -84,8 +84,8 @@ def _html_sub(m):
84
84
85
85
def unescape(text):
86
86
""" Unescape escaped text. """
87
-
c = UnescapePostprocessor()
88
-
return c.run(text)
87
+
c = UnescapeTreeprocessor()
88
+
return c.unescape(text)
89
89
90
90
91
91
def nest_toc_tokens(toc_list):
@@ -289,10 +289,10 @@ def run(self, doc):
289
289
toc_tokens.append({
290
290
'level': int(el.tag[-1]),
291
291
'id': el.attrib["id"],
292
-
'name': unescape(stashedHTML2text(
292
+
'name': stashedHTML2text(
293
293
code_escape(el.attrib.get('data-toc-label', text)),
294
294
self.md, strip_entities=False
295
-
))
295
+
)
296
296
})
297
297
298
298
# Remove the data-toc-label attribute as it is no longer needed
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@ def build_postprocessors(md, **kwargs):
37
37
postprocessors = util.Registry()
38
38
postprocessors.register(RawHtmlPostprocessor(md), 'raw_html', 30)
39
39
postprocessors.register(AndSubstitutePostprocessor(), 'amp_substitute', 20)
40
-
postprocessors.register(UnescapePostprocessor(), 'unescape', 10)
41
40
return postprocessors
42
41
43
42
@@ -122,6 +121,10 @@ def run(self, text):
122
121
return text
123
122
124
123
124
+
@util.deprecated(
125
+
"This class will be removed in the future; "
126
+
"use 'treeprocessors.UnescapeTreeprocessor' instead."
127
+
)
125
128
class UnescapePostprocessor(Postprocessor):
126
129
""" Restore escaped chars """
127
130
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
19
19
License: BSD (see LICENSE.md for details).
20
20
"""
21
21
22
+
import re
22
23
import xml.etree.ElementTree as etree
23
24
from . import util
24
25
from . import inlinepatterns
@@ -29,6 +30,7 @@ def build_treeprocessors(md, **kwargs):
29
30
treeprocessors = util.Registry()
30
31
treeprocessors.register(InlineProcessor(md), 'inline', 20)
31
32
treeprocessors.register(PrettifyTreeprocessor(md), 'prettify', 10)
33
+
treeprocessors.register(UnescapeTreeprocessor(md), 'unescape', 0)
32
34
return treeprocessors
33
35
34
36
@@ -429,3 +431,28 @@ def run(self, root):
429
431
# Only prettify code containing text only
430
432
if not len(code) and code.text is not None:
431
433
code.text = util.AtomicString(code.text.rstrip() + '\n')
434
+
435
+
436
+
class UnescapeTreeprocessor(Treeprocessor):
437
+
""" Restore escaped chars """
438
+
439
+
RE = re.compile(r'{}(\d+){}'.format(util.STX, util.ETX))
440
+
441
+
def _unescape(self, m):
442
+
return chr(int(m.group(1)))
443
+
444
+
def unescape(self, text):
445
+
return self.RE.sub(self._unescape, text)
446
+
447
+
def run(self, root):
448
+
""" Loop over all elements and unescape all text. """
449
+
for elem in root.iter():
450
+
# Unescape text content
451
+
if elem.text and not elem.tag == 'code':
452
+
elem.text = self.unescape(elem.text)
453
+
# Unescape tail content
454
+
if elem.tail:
455
+
elem.tail = self.unescape(elem.tail)
456
+
# Unescape attribute values
457
+
for key, value in elem.items():
458
+
elem.set(key, self.unescape(value))
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
9
9
<p>Right bracket: ]</p>
10
10
<p>Left paren: (</p>
11
11
<p>Right paren: )</p>
12
-
<p>Greater-than: ></p>
12
+
<p>Greater-than: ></p>
13
13
<p>Hash: #</p>
14
14
<p>Period: .</p>
15
15
<p>Bang: !</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
1
+
# -*- coding: utf-8 -*-
2
+
"""
3
+
Python Markdown
4
+
5
+
A Python implementation of John Gruber's Markdown.
6
+
7
+
Documentation: https://python-markdown.github.io/
8
+
GitHub: https://github.com/Python-Markdown/markdown/
9
+
PyPI: https://pypi.org/project/Markdown/
10
+
11
+
Started by Manfred Stienstra (http://www.dwerg.net/).
12
+
Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
13
+
Currently maintained by Waylan Limberg (https://github.com/waylan),
14
+
Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).
15
+
16
+
Copyright 2007-2022 The Python Markdown Project (v. 1.7 and later)
17
+
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
18
+
Copyright 2004 Manfred Stienstra (the original version)
19
+
20
+
License: BSD (see LICENSE.md for details).
21
+
"""
22
+
23
+
from markdown.test_tools import TestCase
24
+
25
+
26
+
class TestSmarty(TestCase):
27
+
28
+
default_kwargs = {'extensions': ['smarty']}
29
+
30
+
def test_escaped_attr(self):
31
+
self.assertMarkdownRenders(
32
+
'',
33
+
'<p><img alt="x"x" src="x" /></p>'
34
+
)
35
+
36
+
# TODO: Move rest of smarty tests here.
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4