fix typographer leading apostrophe for abbreviations

This commit is contained in:
Nate Moore 2022-02-17 10:04:21 -06:00
parent 7b616a4c80
commit a6c48071ed
2 changed files with 11 additions and 3 deletions

View file

@ -130,8 +130,7 @@ Janet said, "When everything is 'breaking news,' nothing is 'breaking news.'"
18: Opening single quotation marks for abbreviations 18: Opening single quotation marks for abbreviations
//- - - - - - - - -// //- - - - - - - - -//
We're talking about the internet --- 'net for short. We're talking about the internet --- 'net for short. Let's rock 'n roll!
//- - - - - - - - -// //- - - - - - - - -//
<p>We&rsquo;re talking about the internet &mdash; &rsquo;net for short.</p> <p>We&rsquo;re talking about the internet &mdash; &rsquo;net for short. Let&rsquo;s rock &rsquo;n roll!</p>
//= = = = = = = = = = = = = = = = = = = = = = = =// //= = = = = = = = = = = = = = = = = = = = = = = =//

View file

@ -1,6 +1,7 @@
package extension package extension
import ( import (
"fmt"
"unicode" "unicode"
"github.com/yuin/goldmark" "github.com/yuin/goldmark"
@ -230,6 +231,14 @@ func (s *typographerParser) Parse(parent gast.Node, block text.Reader, pc parser
return node return node
} }
} }
// special cases: 'twas, 'em, 'net
if len(line) > 1 && (unicode.IsPunct(before) || unicode.IsSpace(before)) && (line[1] == 't' || line[1] == 'e' || line[1] == 'n' || line[1] == 'l') {
fmt.Println(string(line))
node := gast.NewString(s.Substitutions[Apostrophe])
node.SetCode(true)
block.Advance(1)
return node
}
// Convert normal apostrophes. This is probably more flexible than necessary but // Convert normal apostrophes. This is probably more flexible than necessary but
// converts any apostrophe in between two alphanumerics. // converts any apostrophe in between two alphanumerics.
if len(line) > 1 && (unicode.IsDigit(before) || unicode.IsLetter(before)) && (unicode.IsLetter(util.ToRune(line, 1))) { if len(line) > 1 && (unicode.IsDigit(before) || unicode.IsLetter(before)) && (unicode.IsLetter(util.ToRune(line, 1))) {