Fixes #39, Fixes #127, Fixes #128, Fixes #129

This commit is contained in:
yuin 2020-05-21 18:13:20 +09:00
parent a302193b06
commit 3393022ab6
2 changed files with 59 additions and 2 deletions

View file

@ -25,3 +25,44 @@ Some say '90s, others say 90's, but I can't say which is best.
//- - - - - - - - -//
<p>Some say &rsquo;90s, others say 90&rsquo;s, but I can&rsquo;t say which is best.</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
5
//- - - - - - - - -//
[Cat][]'s Pajamas
[Cat]: http://example.com
//- - - - - - - - -//
<p><a href="http://example.com">Cat</a>&rsquo;s Pajamas</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
6
//- - - - - - - - -//
reported "issue 1 (IE-only)"
//- - - - - - - - -//
<p>reported &ldquo;issue 1 (IE-only)&rdquo;</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
7
//- - - - - - - - -//
Yahoo!'s
//- - - - - - - - -//
<p>Yahoo!&rsquo;s</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
8
//- - - - - - - - -//
Alice's, I'm ,Don't, You'd
I've, I'll, You're
//- - - - - - - - -//
<p>Alice&rsquo;s, I&rsquo;m ,Don&rsquo;t, You&rsquo;d</p>
<p>I&rsquo;ve, I&rsquo;ll, You&rsquo;re</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
9
//- - - - - - - - -//
My height is 5'6"".
//- - - - - - - - -//
<p>My height is 5'6&quot;&quot;.</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//

View file

@ -143,7 +143,6 @@ func (s *typographerParser) Trigger() []byte {
}
func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser.Context) gast.Node {
before := block.PrecendingCharacter()
line, _ := block.PeekLine()
c := line[0]
if len(line) > 2 {
@ -189,6 +188,7 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
}
}
if c == '\'' || c == '"' {
before := block.PrecendingCharacter()
d := parser.ScanDelimiter(line, before, 1, defaultTypographerDelimiterProcessor)
if d == nil {
return nil
@ -218,7 +218,17 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
}
}
if s.Substitutions[LeftSingleQuote] != nil && d.CanOpen && !d.CanClose {
node := gast.NewString(s.Substitutions[LeftSingleQuote])
nt := LeftSingleQuote
// special cases: Alice's, I'm ,Don't, You'd
if len(line) > 1 && (line[1] == 's' || line[1] == 'm' || line[1] == 't' || line[1] == 'd') && (len(line) < 3 || util.IsPunct(line[2]) || util.IsSpace(line[2])) {
nt = RightSingleQuote
}
// special cases: I've, I'll, You're
if len(line) > 2 && ((line[1] == 'v' && line[2] == 'e') || (line[1] == 'l' && line[2] == 'l') || (line[1] == 'r' && line[2] == 'e')) && (len(line) < 4 || util.IsPunct(line[3]) || util.IsSpace(line[3])) {
nt = RightSingleQuote
}
node := gast.NewString(s.Substitutions[nt])
node.SetCode(true)
block.Advance(1)
return node
@ -231,6 +241,12 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
}
}
if c == '"' {
// special case: 7'1""
if len(line) > 1 && line[1] == '"' && unicode.IsDigit(before) {
node := gast.NewString(line[0:2])
block.Advance(2)
return node
}
if s.Substitutions[LeftDoubleQuote] != nil && d.CanOpen && !d.CanClose {
node := gast.NewString(s.Substitutions[LeftDoubleQuote])
node.SetCode(true)