Skip to content

Commit 5bc3059

Browse files
authored
Merge pull request #165 from chrispy-snps/chrispy/fix-a-in-code
do not construct Markdown links in code spans and code blocks
2 parents 6258f5c + 71e1471 commit 5bc3059

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Diff for: markdownify/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ def underline(self, text, pad_char):
264264
return '\n\n%s\n%s\n\n' % (text, pad_char * len(text)) if text else ''
265265

266266
def convert_a(self, el, text, convert_as_inline):
267+
if el.find_parent(['pre', 'code', 'kbd', 'samp']):
268+
return text
267269
prefix, suffix, text = chomp(text)
268270
if not text:
269271
return ''

Diff for: tests/test_conversions.py

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def test_a_no_autolinks():
3939
assert md('<a href="https://google.com">https://google.com</a>', autolinks=False) == '[https://google.com](https://google.com)'
4040

4141

42+
def test_a_in_code():
43+
assert md('<code><a href="https://google.com">Google</a></code>') == '`Google`'
44+
assert md('<pre><a href="https://google.com">Google</a></pre>') == '\n```\nGoogle\n```\n'
45+
46+
4247
def test_b():
4348
assert md('<b>Hello</b>') == '**Hello**'
4449

0 commit comments

Comments
 (0)