Skip to content

Add text-autospace for CJKs#3020

Open
Evian-Zhang wants to merge 1 commit intorust-lang:masterfrom
Evian-Zhang:autospace
Open

Add text-autospace for CJKs#3020
Evian-Zhang wants to merge 1 commit intorust-lang:masterfrom
Evian-Zhang:autospace

Conversation

@Evian-Zhang
Copy link
Contributor

The CSS property text-autospace has finally work for all mainstream browsers (you can see this news in the top banner of the MDN documentation). This property will automatically insert spaces between CJK and non-CJK characters and around punctuation, which is the preferred approach for CJK typesettings (This typesetting rule is adopted in the Chinese version of "The Rust Programming Language", where all spaces are manually inserted).

Before applying this property:

截屏2026-02-02 10 49 25

After applying this property:

截屏2026-02-02 10 54 52

The property will only add spaces if there is no space, and if the author has manually inserted spaces, there will be no difference.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Feb 2, 2026
/* make long words/inline code not x overflow */
main {
overflow-wrap: break-word;
text-autospace: normal;
Copy link
Member

Choose a reason for hiding this comment

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

Looks reasonable.

Does it matter that caniuse shows its usage rate is only 77%?

https://caniuse.com/mdn-css_properties_text-autospace

Copy link
Member

Choose a reason for hiding this comment

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

For those non-CJK users, it is kinda a best practice among programmers that you insert space between CJK and other ASCII characters for readability. See https://github.com/sparanoid/chinese-copywriting-guidelines. And there is a well-known plugin for this behavior: https://github.com/vinta/pangu.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the reason for the low rate is the common usage of old Chrome. I'm not sure to what extent does mdbook want to maintain compatibility.

And for pangu, I think text-autospace is just a browser built-in solution for it? I remember that pangu has some visual issues since it scans all text and insert whitespaces at runtime.

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

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants