diff --git a/inline_test.go b/inline_test.go index 312daf6..b77a92b 100644 --- a/inline_test.go +++ b/inline_test.go @@ -173,6 +173,18 @@ func TestEmphasisMix(t *testing.T) { "***triple emphasis___\n", "
***triple emphasis___
\n", + "*italics **and bold** end*\n", + "italics and bold end
\n", + + "*italics **and bold***\n", + "italics and bold
\n", + + "***bold** and italics*\n", + "bold and italics
\n", + + "*start **bold** and italics*\n", + "start bold and italics
\n", + "*__triple emphasis__*\n", "triple emphasis
\n", @@ -183,7 +195,7 @@ func TestEmphasisMix(t *testing.T) { "improper *nesting is* bad
\n", "*improper **nesting* is** bad\n", - "*improper nesting* is bad
\n", + "improper **nesting is** bad
\n", } doTestsInline(t, tests) } diff --git a/parser/inline.go b/parser/inline.go index 87ff236..5417de7 100644 --- a/parser/inline.go +++ b/parser/inline.go @@ -1185,31 +1185,30 @@ func helperFindEmphChar(data []byte, c byte) int { func helperEmphasis(p *Parser, data []byte, c byte) (int, ast.Node) { i := 0 - // skip one symbol if coming from emph3 + // skip two symbol if coming from emph3, as it detected a double emphasis case if len(data) > 1 && data[0] == c && data[1] == c { - i = 1 + i = 2 } for i < len(data) { length := helperFindEmphChar(data[i:], c) - if length == 0 { - return 0, nil - } i += length if i >= len(data) { return 0, nil } if i+1 < len(data) && data[i+1] == c { - i++ + i += 2 continue } if data[i] == c && !IsSpace(data[i-1]) { - if p.extensions&NoIntraEmphasis != 0 { rest := data[i+1:] if !(len(rest) == 0 || IsSpace(rest[0]) || IsPunctuation2(rest)) { + if length == 0 { + return 0, nil + } continue } } @@ -1218,6 +1217,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 diff --git a/parser/parser.go b/parser/parser.go index 5d0ac2f..784e0c6 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -743,7 +743,7 @@ func IsPunctuation2(d []byte) bool { return unicode.IsPunct(r) } -// IsSpace returns true if c is a white-space charactr +// IsSpace returns true if c is a white-space character func IsSpace(c byte) bool { return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v' }