This commit is contained in:
yuin 2020-07-02 15:44:34 +09:00
parent feff0bb82b
commit 3c3d4481ef
4 changed files with 25 additions and 6 deletions

View file

@ -133,3 +133,12 @@ bbb
</li>
</ol>
//= = = = = = = = = = = = = = = = = = = = = = = =//
11: delimiters between ascii punctuations should be parsed
//- - - - - - - - -//
`{%`_name_`%}`
//- - - - - - - - -//
<p><code>{%</code><em>name</em><code>%}</code></p>
//= = = = = = = = = = = = = = = = = = = = = = = =//

View file

@ -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)

View file

@ -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)

View file

@ -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'