Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改行を保持するモード(hardLineBreaks: true)のとき改行のあとの全角スペースが削除される #186

Open
MurakamiShinyu opened this issue Dec 21, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@MurakamiShinyu
Copy link
Member

Issue Details

--hard-line-breaks オプションが有効の場合(hardLineBreaks: true) 、改行のあとの全角スペースが削除されてしまう。

  • VFM version
    • 2.2.1

MDの例:

---
vfm:
  hardLineBreaks: true
---

# 吾輩は猫である

 吾輩は猫である。名前はまだ無い。
 どこで生れたかとんと見当がつかぬ。

この「名前はまだ無い。」のあとの改行が hardLineBreaks: true の効果により <br> タグに変換される。そしてそのあとの全角スペースが消えてしまう。次の出力となる:

<p> 吾輩は猫である。名前はまだ無い。<br>どこで生れたかとんと見当がつかぬ。</p>

Expected Behavior

強制改行 <br> のあとの全角スペースが出力されること。

<p> 吾輩は猫である。名前はまだ無い。<br> どこで生れたかとんと見当がつかぬ。</p>

Actual Behavior

強制改行 <br> のあとの全角スペースが出力されない。

Debug log (Any)

Run vfm with DEBUG=vfm to see detailed log.

$ DEBUG=vfm vfm TEST.md 
  vfm 
  vfm ### mdast ### +0ms
  vfm root[2] (1:1-10:1, 0-85)
  vfm ├─0 yaml "vfm:\n  hardLineBreaks: true" (1:1-4:4, 0-35)
  vfm └─1 section[2]
  vfm     │ data: {"hName":"section","hProperties":{"class":["level1"],"aria-labelledby":"吾輩は猫である"}}
  vfm     │ depth: 1
  vfm     ├─0 heading[1] (6:1-6:10, 37-46)
  vfm     │   │ depth: 1
  vfm     │   │ data: {"hProperties":{"id":"吾輩は猫である"},"id":"吾輩は猫である"}
  vfm     │   └─0 text "吾輩は猫である" (6:3-6:10, 39-46)
  vfm     └─1 paragraph[3] (8:1-9:19, 48-84)
  vfm         ├─0 text " 吾輩は猫である。名前はまだ無い。" (8:1-8:18, 48-65)
  vfm         ├─1 break (8:18-9:1, 65-66)
  vfm         └─2 text " どこで生れたかとんと見当がつかぬ。" (9:1-9:19, 66-84) +0ms
  vfm 
  vfm ### hast ### +3ms
  vfm root[1] (1:1-10:1, 0-85)
  vfm │ data: {"quirksMode":false}
  vfm └─0 element<section>[2]
  vfm     │ properties: {"className":["level1"],"ariaLabelledBy":["吾輩は猫である"]}
  vfm     ├─0 element<h1>[1] (6:1-6:10, 37-46)
  vfm     │   │ properties: {"id":"吾輩は猫である"}
  vfm     │   └─0 text "吾輩は猫である" (6:3-6:10, 39-46)
  vfm     └─1 element<p>[3] (8:1-9:19, 48-84)
  vfm         │ properties: {}
  vfm         ├─0 text " 吾輩は猫である。名前はまだ無い。" (8:1-8:18, 48-65)
  vfm         ├─1 element<br>[0] (8:18-9:1, 65-66)
  vfm         │     properties: {}
  vfm         └─2 text "\nどこで生れたかとんと見当がつかぬ。" (9:19, 84) +0ms
  vfm {} +2ms
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>吾輩は猫である</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <section class="level1" aria-labelledby="吾輩は猫である">
      <h1 id="吾輩は猫である">吾輩は猫である</h1>
      <p> 吾輩は猫である。名前はまだ無い。<br>どこで生れたかとんと見当がつかぬ。</p>
    </section>
  </body>
</html>
@MurakamiShinyu MurakamiShinyu added the bug Something isn't working label Dec 21, 2023
@tats-u
Copy link

tats-u commented Nov 27, 2024

JSで安易に.trim()を使うと引っかかります。
.trim()は全角スペース含めて色々削除します。
CommonMarkのJS実装でもやらかしています。

commonmark/commonmark.js#289

CommonMark自体は半角スペース以外のスペースの削除は認めていません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants