Skip to content

Conversation

@reminjp
Copy link

@reminjp reminjp commented Jun 8, 2020

close #6385
close #5938

  • Add an option cjkSpacing
    • always: same as current behavior for Chinese and Japanese
    • preserve: same as current behavior for Korean
  • Update the splitText function in src/language-markdown/utils.js to implement the above option
  • Add some tests

While the discussion at #6385 seemed to be inactive, I was annoyed with spaces between CJK characters and non-CJK characters.
Thus, I'm working on this PR.

Before I start working on unfinished tasks (such as writing changelog_unreleased), I would like your advice about the direction of implementation. In addition, because I'm not a native English speaker, the namings and the descriptions might be unnatural. 😖


  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@sosukesuzuki
Copy link
Contributor

sosukesuzuki commented Jun 10, 2020

I also use Japanese-letters, so I know that this behavior is frustrating..

I opened #6385 but I don't think we should add new option for this now. See #6385 (comment). I agree the comment. Prettier should simply keep whitespace same as the input.
However, it is a big breaking change so we cannot add this change in minor and patch release. I think We can do it in next major release.

/cc @ikatyang How do you think?

@thorn0
Copy link
Member

thorn0 commented Jun 10, 2020

@sosukesuzuki I think the main problem with what I wrote there is line breaks. If --prose-wrap is set to always or never, Prettier needs to re-wrap text. If Latin and Japanese or Chinese meet on the line border:

.... .... .... .... ... .. ......... ....... <CJK>
<LATIN> .... .... ...... .. ...... .... ..

what should Prettier replace the line break with? A space or the empty string?

@reminjp
Copy link
Author

reminjp commented Jun 19, 2020

Because most plugins for removing linebreaks between CJK (e.g. markdown-it-cjk-breaks, hexo-filter-fix-cjk-spacing) don't treat linebreaks between CJK and non-CJK, in my opinion, it seems like a good idea to follow them and to leave a space:

Input

あおえ
うい
aoe
ui

Output

あおえうい aoe ui

The reason why I focused on the behavior of plugins is the release note.

Note for CJK users: If your markdown renderer does not support CJK line ending, you'll have to use plugin like markdown-it-perfect-newline-for-cjk, hexo-filter-fix-cjk-spacing, etc. to remove additional spaces.

// Source
一二三
四五六
七八九

// Rendered content with unsupported renderer
一二三 四五六 七八九

// Rendered content with supported renderer or via plugin
一二三四五六七八九

Thus, we warn users that formatting CJK text with --prose-wrap always could output undesirable results.

Input 1

私はJavaScriptが好きです。

Output 1 (prettier --prose-wrap always) / Input 2

私はJavaScript
が好きです。

Output 2 (prettier --prose-wrap never or markdown parsers with plugins)

私はJavaScript が好きです。

@uptonking
Copy link

I really want this option merged into prettier and released, because I rely on prettier heavily.
Now I have to ignore the .md files while formatting.

@thorn0
Copy link
Member

thorn0 commented Jul 1, 2020

@uptonking We know this is a problem, but we'd like to try to solve it without adding an option.

@uptonking
Copy link

@thorn0
As for Chinese language, it's quite a personal taste about whether to add a whitespace between Chinese and English characters.
Sometimes it's better, sometimes not. Some people prefer, some people not.
Someone even writes a guide for the recommended format for Chinese as stated in issue 6385. But I don't agree and won't adopt it.
So I strongly request an option. Otherwise github issues will always be open.

@alexander-akait
Copy link
Member

alexander-akait commented Jul 1, 2020

@uptonking no options, we will keep original input as it, if you need ensure one style on all docs, you need to use linter

@sosukesuzuki
Copy link
Contributor

sosukesuzuki commented Jul 1, 2020

I agree with evilebottnawi. As I mentioned on Twitter it is NOT Prettier role.

@reminjp
Copy link
Author

reminjp commented Jul 1, 2020

Sounds good. I am relieved to know that the discussion is continuing. Now I will close this PR because the PR is different from those plans.

@reminjp reminjp closed this Jul 1, 2020
@reminjp reminjp deleted the 6385-cjk-spacing branch July 1, 2020 22:17
@brody4hire
Copy link

It looks to me from #7933 (comment) like this change to disable adding spaces is wanted but with no option in the next major release. Considering that these changes seem to simplify src/language-markdown/utils.js, should this PR be resurrected with the option removed?

tats-u added a commit to tats-u/prettier that referenced this pull request Sep 3, 2020
…Japanese and others

 Based on prettier#8526 (Thanks to @rdrgn)

 Differences from prettier#8526:
 - Don't touch on Hangul.
 - Change option name & type & description.
tats-u added a commit to tats-u/prettier that referenced this pull request Sep 3, 2020
…Japanese and others Based on prettier#8526 (Thanks to @rdrgn) Differences from prettier#8526: - Don't touch on Hangul. - Change option name & type & description.
tats-u added a commit to tats-u/prettier that referenced this pull request Sep 3, 2020
…Japanese and others Based on prettier#8526 (Thanks to @rdrgn) Differences from prettier#8526: - Don't touch on Hangul. - Change option name & type & description.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not insert whitespaces between latin and cj letters Opt out inserting spaces between Japanese and Latin

6 participants