diff --git a/_test/extra.txt b/_test/extra.txt index 2143933..ead2da3 100644 --- a/_test/extra.txt +++ b/_test/extra.txt @@ -133,3 +133,12 @@ bbb //= = = = = = = = = = = = = = = = = = = = = = = =// + + + +11: delimiters between ascii punctuations should be parsed +//- - - - - - - - -// +`{%`_name_`%}` +//- - - - - - - - -// +

{%name%}

+//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/extension/typographer.go b/extension/typographer.go index 8e95231..2c34730 100644 --- a/extension/typographer.go +++ b/extension/typographer.go @@ -223,7 +223,7 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser if len(line) > 4 { after = util.ToRune(line, 4) } - if len(line) == 3 || unicode.IsSpace(after) || unicode.IsPunct(after) { + if len(line) == 3 || util.IsSpaceRune(after) || util.IsPunctRune(after) { node := gast.NewString(s.Substitutions[Apostrophe]) node.SetCode(true) block.Advance(1) diff --git a/parser/delimiter.go b/parser/delimiter.go index 612d7b7..8259f62 100644 --- a/parser/delimiter.go +++ b/parser/delimiter.go @@ -3,7 +3,6 @@ package parser import ( "fmt" "strings" - "unicode" "github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/text" @@ -128,10 +127,10 @@ func ScanDelimiter(line []byte, before rune, min int, processor DelimiterProcess } canOpen, canClose := false, false - beforeIsPunctuation := unicode.IsPunct(before) - beforeIsWhitespace := unicode.IsSpace(before) - afterIsPunctuation := unicode.IsPunct(after) - afterIsWhitespace := unicode.IsSpace(after) + beforeIsPunctuation := util.IsPunctRune(before) + beforeIsWhitespace := util.IsSpaceRune(before) + afterIsPunctuation := util.IsPunctRune(after) + afterIsWhitespace := util.IsSpaceRune(after) isLeft := !afterIsWhitespace && (!afterIsPunctuation || beforeIsWhitespace || beforeIsPunctuation) diff --git a/util/util.go b/util/util.go index ef113c4..e4ae5e0 100644 --- a/util/util.go +++ b/util/util.go @@ -8,6 +8,7 @@ import ( "regexp" "sort" "strconv" + "unicode" "unicode/utf8" ) @@ -777,11 +778,21 @@ func IsPunct(c byte) bool { return punctTable[c] == 1 } +// IsPunct returns true if the given rune is a punctuation, otherwise false. +func IsPunctRune(r rune) bool { + return int32(r) <= 256 && IsPunct(byte(r)) || unicode.IsPunct(r) +} + // IsSpace returns true if the given character is a space, otherwise false. func IsSpace(c byte) bool { return spaceTable[c] == 1 } +// IsSpace returns true if the given rune is a space, otherwise false. +func IsSpaceRune(r rune) bool { + return int32(r) <= 256 && IsSpace(byte(r)) || unicode.IsSpace(r) +} + // IsNumeric returns true if the given character is a numeric, otherwise false. func IsNumeric(c byte) bool { return c >= '0' && c <= '9'