Skip to content

When formatting, replace inline ASCII quotes with typographic quotes#701

Merged
michaelficarra merged 4 commits into
tc39:mainfrom
gibson042:2026-06-format-typographic-quotes
Jun 25, 2026
Merged

When formatting, replace inline ASCII quotes with typographic quotes#701
michaelficarra merged 4 commits into
tc39:mainfrom
gibson042:2026-06-format-typographic-quotes

Conversation

@gibson042

@gibson042 gibson042 commented Jun 16, 2026

Copy link
Copy Markdown
Member

Ref tc39/ecma262#3861 (review)
Ref #173
Ref #317

Note that this processing cannot be scoped to individual text nodes because logical quotations can span across those, e.g. a "<a href="…">binary64</a> value" should get rewritten into a “<a href="…">binary64</a> value” (but the same would not be true if the medial element were block-level rather than inline).

ASCII quotes are not replaced inside of HTML comments, <code>/<emu-val> elements, backtick spans (e.g., `code`), asterisk spans (e.g., *"string"*), or after equals signs (as in HTML element attributes).

This approach is not perfect, but spec source text tends to strongly avoid the sort of edge cases that would reveal its flaws (e.g., using it as an automated analog of tc39/ecma262#3861 finds only one line to change, in substring—from «If the "to" suffix is omitted» to «If the “to” suffix is omitted»).

@michaelficarra

Copy link
Copy Markdown
Member

In editor call today, I asked to confirm that this auto-formatting also would have made all of the changes from tc39/ecma262#3861 for us automatically.

@michaelficarra

michaelficarra commented Jun 18, 2026

Copy link
Copy Markdown
Member

Also, do we have tests for the formatter that we can add to? In particular, I think the negative cases will be valuable.

@bakkot

bakkot commented Jun 18, 2026

Copy link
Copy Markdown
Member

Yes: https://github.com/tc39/ecmarkup/blob/39c401c8ba885942c142cfff513a9d5476d83640/test/formatter.ts

(Including negative tests in the form of assertRoundTrips.)

@michaelficarra

Copy link
Copy Markdown
Member

Then let's also add tests for this @gibson042.

@gibson042

Copy link
Copy Markdown
Member Author

In editor call today, I asked to confirm that this auto-formatting also would have made all of the changes from tc39/ecma262#3861 for us automatically.

This was a great idea, and did in fact find some bugs (now fixed).

Then let's also add tests for this @gibson042.

Done.

Comment thread test/formatter.ts Outdated
Comment thread test/formatter.ts Outdated
@gibson042 gibson042 force-pushed the 2026-06-format-typographic-quotes branch from ff2dac2 to 2ee368b Compare June 25, 2026 15:30
@gibson042 gibson042 force-pushed the 2026-06-format-typographic-quotes branch from 2ee368b to cc083c2 Compare June 25, 2026 15:35
Ref tc39/ecma262#3861 (review)
Ref tc39#173
Ref tc39#317

Note that this processing cannot be scoped to individual text nodes because e.g.
`a "<a href="…">binary64</a> value"` should get rewritten into
`a “<a href="…">binary64</a> value”` (but the same would not be true if
the medial element were block-level rather than inline).

ASCII quotes are not replaced inside of HTML comments, `<code>`/`<emu-val>`
elements, backtick spans (e.g., ``` `code` ```), asterisk spans
(e.g., `*"string"*`), or after equals signs (as in HTML element attributes).
@gibson042 gibson042 force-pushed the 2026-06-format-typographic-quotes branch from cc083c2 to 6a825ac Compare June 25, 2026 15:37
@michaelficarra michaelficarra merged commit 6cb9653 into tc39:main Jun 25, 2026
2 checks passed
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.

4 participants