Skip to content

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

Open
gibson042 wants to merge 5 commits into
tc39:mainfrom
gibson042:2026-06-format-typographic-quotes
Open

When formatting, replace inline ASCII quotes with typographic quotes#701
gibson042 wants to merge 5 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»).

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).
@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

it('preserves ASCII quotes that are code', async () => {
await assertRoundTrips(
`<p>ASCII quotes are not replaced in <code>"code elements"</code>, <emu-val>"emu-val elements"</emu-val>, ${'`'}"backtick spans"${'`'}, or *"inline language strings"*.</p>\n`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also put a quoted HTML attribute in this test.

Comment thread test/formatter.ts
});

it('<script>, <style>, and <pre> whitespace is preserved', async () => {
it('<script>, <style>, and <pre> whitespace and inner ASCII quotes are preserved', async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
it('<script>, <style>, and <pre> whitespace and inner ASCII quotes are preserved', async () => {
it('<script>, <style>, <pre> whitespace, and inner ASCII quotes are preserved', async () => {

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.

3 participants