diff --git a/inline_test.go b/inline_test.go index 8c8d8ad..312daf6 100644 --- a/inline_test.go +++ b/inline_test.go @@ -15,10 +15,7 @@ func TestEmphasis(t *testing.T) { doTestsInlineParam(t, tests, TestParams{}) } -// TODO: to fix this we would have to update IsPunctuation() to handle -// `—` which looks like `-` but is a unicode 3-byte thingy and -// currently IsPunctuation() only handles 1-byte ascii -func Disabled_TestBug309(t *testing.T) { +func TestBug309(t *testing.T) { var tests = []string{ `*f*—`, "

f

\n", diff --git a/parser/inline.go b/parser/inline.go index d6c8a72..87ff236 100644 --- a/parser/inline.go +++ b/parser/inline.go @@ -1208,7 +1208,8 @@ func helperEmphasis(p *Parser, data []byte, c byte) (int, ast.Node) { if data[i] == c && !IsSpace(data[i-1]) { if p.extensions&NoIntraEmphasis != 0 { - if !(i+1 == len(data) || IsSpace(data[i+1]) || IsPunctuation(data[i+1])) { + rest := data[i+1:] + if !(len(rest) == 0 || IsSpace(rest[0]) || IsPunctuation2(rest)) { continue } } diff --git a/parser/parser.go b/parser/parser.go index 8d72b64..5d0ac2f 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -8,6 +8,8 @@ import ( "fmt" "strconv" "strings" + "unicode" + "unicode/utf8" "github.com/gomarkdown/markdown/ast" ) @@ -727,6 +729,20 @@ func IsPunctuation(c byte) bool { return false } +func IsPunctuation2(d []byte) bool { + if len(d) == 0 { + return false + } + if IsPunctuation(d[0]) { + return true + } + r, _ := utf8.DecodeRune(d) + if r == utf8.RuneError { + return false + } + return unicode.IsPunct(r) +} + // IsSpace returns true if c is a white-space charactr func IsSpace(c byte) bool { return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'