File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
tests/test_syntax/extensions Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Original file line Diff line number Diff line change @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17
* Remove legacy import needed only in Python 2 (#1403 )
17
* Remove legacy import needed only in Python 2 (#1403 )
18
* Fix typo that left the attribute ` AdmonitionProcessor.content_indent ` unset
18
* Fix typo that left the attribute ` AdmonitionProcessor.content_indent ` unset
19
(#1404 )
19
(#1404 )
20
+ * Fix edge-case crash in ` codehilite ` with an empty ` code ` tag (#1405 ).
20
* Improve and expand type annotations in the code base (#1401 ).
21
* Improve and expand type annotations in the code base (#1401 ).
21
22
22
## [ 3.5.1] -- 2023-10-31
23
## [ 3.5.1] -- 2023-10-31
Original file line number Original file line Diff line number Diff line change @@ -270,8 +270,11 @@ def run(self, root: etree.Element) -> None:
270
for block in blocks :
270
for block in blocks :
271
if len (block ) == 1 and block [0 ].tag == 'code' :
271
if len (block ) == 1 and block [0 ].tag == 'code' :
272
local_config = self .config .copy ()
272
local_config = self .config .copy ()
273
+ text = block [0 ].text
274
+ if text is None :
275
+ continue
273
code = CodeHilite (
276
code = CodeHilite (
274
- self .code_unescape (block [ 0 ]. text ),
277
+ self .code_unescape (text ),
275
tab_length = self .md .tab_length ,
278
tab_length = self .md .tab_length ,
276
style = local_config .pop ('pygments_style' , 'default' ),
279
style = local_config .pop ('pygments_style' , 'default' ),
277
** local_config
280
** local_config
Original file line number Original file line Diff line number Diff line change 21
21
22
from markdown .test_tools import TestCase
22
from markdown .test_tools import TestCase
23
from markdown .extensions .codehilite import CodeHiliteExtension , CodeHilite
23
from markdown .extensions .codehilite import CodeHiliteExtension , CodeHilite
24
+ from markdown import extensions , treeprocessors
24
import os
25
import os
26
+ import xml .etree .ElementTree as etree
25
27
26
try :
28
try :
27
import pygments # noqa
29
import pygments # noqa
@@ -762,3 +764,22 @@ def testFormatterLangStrEmptyLang(self):
762
)
764
)
763
]
765
]
764
)
766
)
767
+
768
+ def testDoesntCrashWithEmptyCodeTag (self ):
769
+ expected = '<h1>Hello</h1>\n <pre><code></code></pre>'
770
+ self .assertMarkdownRenders (
771
+ '# Hello' ,
772
+ expected ,
773
+ extensions = [CodeHiliteExtension (), _ExtensionThatAddsAnEmptyCodeTag ()]
774
+ )
775
+
776
+
777
+ class _ExtensionThatAddsAnEmptyCodeTag (extensions .Extension ):
778
+ def extendMarkdown (self , md ):
779
+ md .treeprocessors .register (_AddCodeTagTreeprocessor (), 'add-code-tag' , 40 )
780
+
781
+
782
+ class _AddCodeTagTreeprocessor (treeprocessors .Treeprocessor ):
783
+ def run (self , root : etree .Element ):
784
+ pre = etree .SubElement (root , 'pre' )
785
+ etree .SubElement (pre , 'code' )
You can’t perform that action at this time.
0 commit comments