Skip to content

Commit

Permalink
Fixes #141
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Jul 2, 2020
1 parent feff0bb commit 3c3d448
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
9 changes: 9 additions & 0 deletions _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>
//= = = = = = = = = = = = = = = = = = = = = = = =//
2 changes: 1 addition & 1 deletion extension/typographer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions parser/delimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package parser
import (
"fmt"
"strings"
"unicode"

"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text"
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"regexp"
"sort"
"strconv"
"unicode"
"unicode/utf8"
)

Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 3c3d448

Please sign in to comment.