Skip to content

Commit

Permalink
BUG: Fix backtick references following fenced code blocks
Browse files Browse the repository at this point in the history
Fixes #134
  • Loading branch information
kernc committed Jan 11, 2020
1 parent b287821 commit d6eca2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pdoc/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def to_markdown(text: str, docformat: str = 'numpy,google', *,
# Matches markdown code spans not +directly+ within links.
# E.g. `code` and [foo is `bar`]() but not [`code`](...)
# Also skips \-escaped grave quotes.
_code_refs=re.compile(r'(?<![\[\\])`(?!])(?:[^`]|(?<=\\)`)+`').sub):
_code_refs=re.compile(r'(?<![\[\\`])`(?!])(?:[^`]|(?<=\\)`)+`').sub):
"""
Returns `text`, assumed to be a docstring in `docformat`, converted to markdown.
Expand Down
19 changes: 15 additions & 4 deletions pdoc/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,21 @@ def test_glimpse(self):
self.assertEqual(glimpse('Foo bar\n-------'), 'Foo bar')

def test_to_html(self):
text = '# Title\n\n`pdoc.Module` is a `Doc`, not `dict`.'
expected = ('<h1 id="title">Title</h1>\n'
'<p><a href="#pdoc.Module">Module</a> is a <a href="#pdoc.Doc">Doc</a>, '
'not <code>dict</code>.</p>')
text = '''# Title
`pdoc.Module` is a `Doc`, not `dict`.
```
code block
```
reference: `package.foo`
'''
expected = '''<h1 id="title">Title</h1>
<p><a href="#pdoc.Module">Module</a> is a <a href="#pdoc.Doc">Doc</a>, not <code>dict</code>.</p>
<pre><code>code block
</code></pre>
<p>reference: <a href="/package.foo.ext">package.foo</a></p>'''

module = pdoc.Module(pdoc)

Expand Down

0 comments on commit d6eca2a

Please sign in to comment.