Skip to content

Improve Typographer Edge Cases#280

Merged
yuin merged 5 commits into
yuin:masterfrom
natemoo-re:fix/typographer
Feb 18, 2022
Merged

Improve Typographer Edge Cases#280
yuin merged 5 commits into
yuin:masterfrom
natemoo-re:fix/typographer

Conversation

@natemoo-re
Copy link
Copy Markdown
Contributor

@natemoo-re natemoo-re commented Feb 17, 2022

I mentioned I wanted to help with #180 quite a while ago. I finally found time to do it!

This PR fixes various edge cases with the Typographer extension, with test cases borrowed from @brycewray's https://gm-typographer.vercel.app/.

Closes #180, gohugoio/hugo#9397.

cc @brycewray @skyfaller

@brycewray
Copy link
Copy Markdown

@natemoo-re Outstanding!

Cc: @bep

Comment thread extension/typographer.go
Comment on lines +234 to +241
// 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
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change I'm concerned about. I settled with t | e | n | l covering most common abbreviations like 'twas, 'em, and 'net but this is extremely difficult to generalize out to other abbreviations I might not have thought of.

<p>&ldquo;Monitor 21&quot;&rdquo; and &ldquo;Monitor&rdquo;&quot;</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//

9: Closing quotation marks within italics
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test cases are all borrowed from https://gm-typographer.vercel.app/!

@yuin
Copy link
Copy Markdown
Owner

yuin commented Feb 18, 2022

@natemoo-re Thanks for your contribution. Open source project should be like this.

@yuin yuin merged commit 1def545 into yuin:master Feb 18, 2022
<p><strong>&ldquo;At first, things were not clear.&rdquo;</strong></p>
//= = = = = = = = = = = = = = = = = = = = = = = =//

11: Closing quotation marks within boldfacing and italics
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are test cases 11&12 duplicated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plural possessives (Typographer extension)

4 participants