@@ -43,15 +43,22 @@ def abstract_inline_conversion(markup_fn):
4343 """
4444 This abstracts all simple inline tags like b, em, del, ...
4545 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
4748 references to self.strong_em_symbol etc.
4849 """
4950 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
5158 prefix , suffix , text = chomp (text )
5259 if not text :
5360 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 )
5562 return implementation
5663
5764
@@ -69,6 +76,7 @@ class DefaultOptions:
6976 default_title = False
7077 escape_asterisks = True
7178 escape_underscores = True
79+ escape_misc = True
7280 heading_style = UNDERLINED
7381 keep_inline_images_in = []
7482 newline_style = SPACES
@@ -199,6 +207,9 @@ def should_convert_tag(self, tag):
199207 def escape (self , text ):
200208 if not text :
201209 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 )
202213 if self .options ['escape_asterisks' ]:
203214 text = text .replace ('*' , r'\*' )
204215 if self .options ['escape_underscores' ]:
@@ -315,7 +326,7 @@ def convert_list(self, el, text, convert_as_inline):
315326 def convert_li (self , el , text , convert_as_inline ):
316327 parent = el .parent
317328 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 () :
319330 start = int (parent .get ("start" ))
320331 else :
321332 start = 1
@@ -377,13 +388,13 @@ def convert_figcaption(self, el, text, convert_as_inline):
377388
378389 def convert_td (self , el , text , convert_as_inline ):
379390 colspan = 1
380- if 'colspan' in el .attrs :
391+ if 'colspan' in el .attrs and el [ 'colspan' ]. isdigit () :
381392 colspan = int (el ['colspan' ])
382393 return ' ' + text .strip ().replace ("\n " , " " ) + ' |' * colspan
383394
384395 def convert_th (self , el , text , convert_as_inline ):
385396 colspan = 1
386- if 'colspan' in el .attrs :
397+ if 'colspan' in el .attrs and el [ 'colspan' ]. isdigit () :
387398 colspan = int (el ['colspan' ])
388399 return ' ' + text .strip ().replace ("\n " , " " ) + ' |' * colspan
389400
@@ -400,7 +411,7 @@ def convert_tr(self, el, text, convert_as_inline):
400411 # first row and is headline: print headline underline
401412 full_colspan = 0
402413 for cell in cells :
403- if " colspan" in cell .attrs :
414+ if ' colspan' in cell .attrs and cell [ 'colspan' ]. isdigit () :
404415 full_colspan += int (cell ["colspan" ])
405416 else :
406417 full_colspan += 1
0 commit comments