Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle bold/strong nested inside italics/em #307

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func TestEmphasisMix(t *testing.T) {
"*italics **and bold** end*\n",
"<p><em>italics <strong>and bold</strong> end</em></p>\n",

"*italics **and bold***\n",
"<p><em>italics <strong>and bold</strong></em></p>\n",

"*__triple emphasis__*\n",
"<p><em><strong>triple emphasis</strong></em></p>\n",

Expand Down
8 changes: 5 additions & 3 deletions parser/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,9 +1192,6 @@ func helperEmphasis(p *Parser, data []byte, c byte) (int, ast.Node) {

for i < len(data) {
length := helperFindEmphChar(data[i:], c)
if length == 0 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building on last commit, in the triple c case, we'd still have short-circuited here - but we actually want to claim this c as our own. So we do the rest of the validity checks first, and then do this check at the end to exit the loop

return 0, nil
}
i += length
if i >= len(data) {
return 0, nil
Expand All @@ -1217,6 +1214,11 @@ func helperEmphasis(p *Parser, data []byte, c byte) (int, ast.Node) {
p.Inline(emph, data[:i])
return i + 1, emph
}

// We have to check this at the end, otherwise the scenario where we find repeated c's will get skipped
if length == 0 {
return 0, nil
}
}

return 0, nil
Expand Down