@@ -43,15 +43,22 @@ def abstract_inline_conversion(markup_fn):
43
43
"""
44
44
This abstracts all simple inline tags like b, em, del, ...
45
45
Returns a function that wraps the chomped text in a pair of the string
46
- that is returned by markup_fn. markup_fn is necessary to allow for
46
+ that is returned by markup_fn, with '/' inserted in the string used after
47
+ the text if it looks like an HTML tag. markup_fn is necessary to allow for
47
48
references to self.strong_em_symbol etc.
48
49
"""
49
50
def implementation (self , el , text , convert_as_inline ):
50
- markup = markup_fn (self )
51
+ markup_prefix = markup_fn (self )
52
+ if markup_prefix .startswith ('<' ) and markup_prefix .endswith ('>' ):
53
+ markup_suffix = '</' + markup_prefix [1 :]
54
+ else :
55
+ markup_suffix = markup_prefix
56
+ if el .find_parent (['pre' , 'code' , 'kbd' , 'samp' ]):
57
+ return text
51
58
prefix , suffix , text = chomp (text )
52
59
if not text :
53
60
return ''
54
- return '%s%s%s%s%s' % (prefix , markup , text , markup , suffix )
61
+ return '%s%s%s%s%s' % (prefix , markup_prefix , text , markup_suffix , suffix )
55
62
return implementation
56
63
57
64
@@ -69,6 +76,7 @@ class DefaultOptions:
69
76
default_title = False
70
77
escape_asterisks = True
71
78
escape_underscores = True
79
+ escape_misc = True
72
80
heading_style = UNDERLINED
73
81
keep_inline_images_in = []
74
82
newline_style = SPACES
@@ -199,6 +207,9 @@ def should_convert_tag(self, tag):
199
207
def escape (self , text ):
200
208
if not text :
201
209
return ''
210
+ if self .options ['escape_misc' ]:
211
+ text = re .sub (r'([\\&<`[>~#=+|-])' , r'\\\1' , text )
212
+ text = re .sub (r'([0-9])([.)])' , r'\1\\\2' , text )
202
213
if self .options ['escape_asterisks' ]:
203
214
text = text .replace ('*' , r'\*' )
204
215
if self .options ['escape_underscores' ]:
@@ -315,7 +326,7 @@ def convert_list(self, el, text, convert_as_inline):
315
326
def convert_li (self , el , text , convert_as_inline ):
316
327
parent = el .parent
317
328
if parent is not None and parent .name == 'ol' :
318
- if parent .get ("start" ):
329
+ if parent .get ("start" ) and str ( parent . get ( "start" )). isnumeric () :
319
330
start = int (parent .get ("start" ))
320
331
else :
321
332
start = 1
@@ -377,13 +388,13 @@ def convert_figcaption(self, el, text, convert_as_inline):
377
388
378
389
def convert_td (self , el , text , convert_as_inline ):
379
390
colspan = 1
380
- if 'colspan' in el .attrs :
391
+ if 'colspan' in el .attrs and el [ 'colspan' ]. isdigit () :
381
392
colspan = int (el ['colspan' ])
382
393
return ' ' + text .strip ().replace ("\n " , " " ) + ' |' * colspan
383
394
384
395
def convert_th (self , el , text , convert_as_inline ):
385
396
colspan = 1
386
- if 'colspan' in el .attrs :
397
+ if 'colspan' in el .attrs and el [ 'colspan' ]. isdigit () :
387
398
colspan = int (el ['colspan' ])
388
399
return ' ' + text .strip ().replace ("\n " , " " ) + ' |' * colspan
389
400
@@ -400,7 +411,7 @@ def convert_tr(self, el, text, convert_as_inline):
400
411
# first row and is headline: print headline underline
401
412
full_colspan = 0
402
413
for cell in cells :
403
- if " colspan" in cell .attrs :
414
+ if ' colspan' in cell .attrs and cell [ 'colspan' ]. isdigit () :
404
415
full_colspan += int (cell ["colspan" ])
405
416
else :
406
417
full_colspan += 1
0 commit comments