diff --git a/extension/_test/typographer.txt b/extension/_test/typographer.txt index d99a6ac..6155291 100644 --- a/extension/_test/typographer.txt +++ b/extension/_test/typographer.txt @@ -26,43 +26,34 @@ Some say '90s, others say 90's, but I can't say which is best.

Some say ’90s, others say 90’s, but I can’t say which is best.

//= = = = = = = = = = = = = = = = = = = = = = = =// -5 -//- - - - - - - - -// -[Cat][]'s Pajamas - -[Cat]: http://example.com -//- - - - - - - - -// -

Cat’s Pajamas

-//= = = = = = = = = = = = = = = = = = = = = = = =// - -6 -//- - - - - - - - -// -reported "issue 1 (IE-only)" -//- - - - - - - - -// -

reported “issue 1 (IE-only)”

-//= = = = = = = = = = = = = = = = = = = = = = = =// - -7 -//- - - - - - - - -// -Yahoo!'s -//- - - - - - - - -// -

Yahoo!’s

-//= = = = = = = = = = = = = = = = = = = = = = = =// - -8 +5: contractions //- - - - - - - - -// Alice's, I'm ,Don't, You'd I've, I'll, You're + +[Cat][]'s Pajamas + +Yahoo!'s + +[Cat]: http://example.com //- - - - - - - - -//

Alice’s, I’m ,Don’t, You’d

I’ve, I’ll, You’re

+

Cat’s Pajamas

+

Yahoo!’s

//= = = = = = = = = = = = = = = = = = = = = = = =// -9 +6: "" after digits are an inch //- - - - - - - - -// My height is 5'6"". //- - - - - - - - -//

My height is 5'6"".

//= = = = = = = = = = = = = = = = = = = = = = = =// +7: quote followed by ,.?! and spaces maybe a closer +//- - - - - - - - -// +reported "issue 1 (IE-only)", "issue 2", 'issue3 (FF-only)', 'issue4' +//- - - - - - - - -// +

reported “issue 1 (IE-only)”, “issue 2”, ‘issue3 (FF-only)’, ‘issue4’

+//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/extension/typographer.go b/extension/typographer.go index 47e55d2..caaae9a 100644 --- a/extension/typographer.go +++ b/extension/typographer.go @@ -233,11 +233,15 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser block.Advance(1) return node } - if s.Substitutions[RightSingleQuote] != nil && d.CanClose && !d.CanOpen { - node := gast.NewString(s.Substitutions[RightSingleQuote]) - node.SetCode(true) - block.Advance(1) - return node + if s.Substitutions[RightSingleQuote] != nil { + isClose := d.CanClose && !d.CanOpen + maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && (line[1] == ',' || line[1] == '.' || line[1] == '!' || line[1] == '?') && (len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2]))) + if isClose || maybeClose { + node := gast.NewString(s.Substitutions[RightSingleQuote]) + node.SetCode(true) + block.Advance(1) + return node + } } } if c == '"' { @@ -253,11 +257,15 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser block.Advance(1) return node } - if s.Substitutions[RightDoubleQuote] != nil && d.CanClose && !d.CanOpen { - node := gast.NewString(s.Substitutions[RightDoubleQuote]) - node.SetCode(true) - block.Advance(1) - return node + if s.Substitutions[RightDoubleQuote] != nil { + isClose := d.CanClose && !d.CanOpen + maybeClose := d.CanClose && d.CanOpen && len(line) > 1 && (line[1] == ',' || line[1] == '.' || line[1] == '!' || line[1] == '?') && (len(line) == 2 || (len(line) > 2 && util.IsPunct(line[2]) || util.IsSpace(line[2]))) + if isClose || maybeClose { + node := gast.NewString(s.Substitutions[RightDoubleQuote]) + node.SetCode(true) + block.Advance(1) + return node + } } } }