Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #101 from FireflyTeam/fix-bold-link
Browse files Browse the repository at this point in the history
Fix exception with link inside bold/italic
  • Loading branch information
ericholscher committed May 30, 2018
2 parents 5f4bd64 + dd15581 commit 4f6a53a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
13 changes: 9 additions & 4 deletions recommonmark/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def visit_link(self, mdnode):
# TODO okay, so this is acutally not always the right line number, but
# these mdnodes won't have sourcepos on them for whatever reason. This
# is better than 0 though.
ref_node.line = (mdnode.sourcepos[0][0] if mdnode.sourcepos
else mdnode.parent.sourcepos[0][0])
ref_node.line = self._get_line(mdnode)
if mdnode.title:
ref_node['title'] = mdnode.title
next_node = ref_node
Expand All @@ -156,8 +155,7 @@ def visit_link(self, mdnode):
refwarn=True
)
# TODO also not correct sourcepos
wrap_node.line = (mdnode.sourcepos[0][0] if mdnode.sourcepos
else mdnode.parent.sourcepos[0][0])
wrap_node.line = self._get_line(mdnode)
if mdnode.title:
wrap_node['title'] = mdnode.title
wrap_node.append(ref_node)
Expand Down Expand Up @@ -248,3 +246,10 @@ def add_section(self, section, level):

def is_section_level(self, level, section):
return self._level_to_elem.get(level, None) == section

def _get_line(self, mdnode):
while mdnode:
if mdnode.sourcepos:
return mdnode.sourcepos[0][0]
mdnode = mdnode.parent
return 0
17 changes: 17 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ def test_links(self):
</document>
"""
)
self.assertParses(
"""
**[link](foo)**
""",
"""
<?xml version="1.0" ?>
<document source="&lt;string&gt;">
<paragraph>
<strong>
<pending_xref refdomain="None" refexplicit="True" reftarget="foo" reftype="any" refwarn="True">
<reference refuri="foo">link</reference>
</pending_xref>
</strong>
</paragraph>
</document>
"""
)

def test_image(self):
self.assertParses(
Expand Down

0 comments on commit 4f6a53a

Please sign in to comment.