Skip to content

Don't treat space and newline between Japanese/Chinese characters interchangeable #127

Open
@tats-u

Description

@tats-u

Describe the bug

dprint-plugin-markdown version: 0.17.8

CSS requires line breaks in Japanese/Chinese text should be trimmed instead of converted to spaces.

https://drafts.csswg.org/css-text-4/#line-break-transform

EXAMPLE 16

這個段落是那麼長,
在一行寫不行。最好
用三行寫。

In languages that have no word separators, such as Chinese, “unbreaking” a line requires joining the two lines with no intervening space.

這個段落是那麼長,在一行寫不行。最好用三行寫。

Only Firefox follows this rule today.

https://wpt.fyi/results/css/css-text/line-breaking?label=master&label=experimental&aligned&q=segment-break-transformation-
https://drafts.csswg.org/css-text-4/#line-break-transform

Chrome & Safari's behavior is treated as a bug:

Symbols for the following description:

  • '字': Japanese or Chinese character (e.g. kanji/han, hiragana, and katakana)
  • 'A': One of other characters (e.g. English and Korean)
  • '\n': LF
  • ' ': ASCII Space

Claims:

  1. ' ' in '字' ' ' '字' should not be converted to '\n' but kept as is
  2. '\n' in '字' '\n' '字' should be forcibly trimmed
  3. ' ' or '\n' between '字' and 'A' can be processed by the current way (Prettier is going to forcibly convert it to ' ' but it's just due to the backward compatibility and dprint don't need to follow it)

You might want to see the following related issues/PRs in Prettier for details of backgrounds:

Input Code

日本語 日本語
日本語 日本語
日本語 日本語
English English
日本語 日本語
日本語 日本語
日本語 日本語
English English
日本語 日本語
日本語 日本語
日本語 日本語
English English

textWrap = always

Expected Output

日本語 日本語日本語 日本語日本語 日本語
English English
日本語 日本語日本語 日本語日本語 日本語
English English
日本語 日本語日本語 日本語日本語 日本語
English English

Actual Output

日本語 日本語 日本語 日本語 日本語 日本語 English English 日本語 日本語 日本語
日本語 日本語 日本語 English English 日本語 日本語 日本語 日本語 日本語 日本語
English English

https://dprint.dev/playground/#code/qemhpzR5UQBKYLAFDSuejrwKIDsDmAbAlgM4AWEWeRxK4SsCNa9kj5BJZObVTt1zyPFp0ocKJIA/config/N4KABGBEA2CWB2BTA6rAJgFwBaQFxgA4AGAGnCiQHcAZBRAaQTTymgDNIyJINEAPDMgBOAQwAOLSCOiURATwDOncpEQBbMVhELYCxvGb5IAVwOIhCgMYB7IYiVcoCjEOvwA5vsNRtvIboBrBxVYd3hbRAARWDtLDFgAN0RJNDF-eAwAWlDwu2VuHIiAMVhoKJjEOMTko1T0rMK7TLZS5MdIRsQAZQwRIQxo2PiklLSEBrCIzOc+jHyoToBRA0HK4ZqoOvHsyabEA0gQAF8QIA/plugin/markdown

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions