|
41 | 41 | # confused with a list item
|
42 | 42 | re_escape_misc_list_items = re.compile(r'((?:\s|^)[0-9]{1,9})([.)](?:\s|$))')
|
43 | 43 |
|
| 44 | +# Find consecutive backtick sequences in a string |
| 45 | +re_backtick_runs = re.compile(r'`+') |
| 46 | + |
44 | 47 | # Heading styles
|
45 | 48 | ATX = 'atx'
|
46 | 49 | ATX_CLOSED = 'atx_closed'
|
@@ -480,10 +483,24 @@ def convert_br(self, el, text, parent_tags):
|
480 | 483 | return ' \n'
|
481 | 484 |
|
482 | 485 | def convert_code(self, el, text, parent_tags):
|
483 |
| - if 'pre' in parent_tags: |
| 486 | + if '_noformat' in parent_tags: |
484 | 487 | return text
|
485 |
| - converter = abstract_inline_conversion(lambda self: '`') |
486 |
| - return converter(self, el, text, parent_tags) |
| 488 | + |
| 489 | + prefix, suffix, text = chomp(text) |
| 490 | + if not text: |
| 491 | + return '' |
| 492 | + |
| 493 | + # Find the maximum number of consecutive backticks in the text, then |
| 494 | + # delimit the code span with one more backtick than that |
| 495 | + max_backticks = max((len(match) for match in re.findall(re_backtick_runs, text)), default=0) |
| 496 | + markup_delimiter = '`' * (max_backticks + 1) |
| 497 | + |
| 498 | + # If the maximum number of backticks is greater than zero, add a space |
| 499 | + # to avoid interpretation of inside backticks as literals |
| 500 | + if max_backticks > 0: |
| 501 | + text = " " + text + " " |
| 502 | + |
| 503 | + return '%s%s%s%s%s' % (prefix, markup_delimiter, text, markup_delimiter, suffix) |
487 | 504 |
|
488 | 505 | convert_del = abstract_inline_conversion(lambda self: '~~')
|
489 | 506 |
|
|
0 commit comments