Skip to content

Markdown code blocks strip leading whitespace #2498

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

Closed
CAD97 opened this issue May 9, 2020 · 3 comments · Fixed by #2564
Closed

Markdown code blocks strip leading whitespace #2498

CAD97 opened this issue May 9, 2020 · 3 comments · Fixed by #2564
Labels
A-frontend 🐹 C-bug 🐞 Category: unintended, undesired behavior

Comments

@CAD97
Copy link

CAD97 commented May 9, 2020

Example: https://crates.io/crates/slice-dst

The readme for that crate contains the code block

```text
                                             +--------------+
                                             |Node          |
                                       +---->|data: "a"     |
+------------+    +---------------+    |     |children: none|
|Node        |    |Vec<Arc<Node>> |    |     +--------------+
|data: "abc" |    |[0]: +--------------+     |Node          |
|children: +----->|[1]: +------------------->|data: "b"     |
+------------+    |[2]: +--------------+     |children: none|
                  +---------------|    |     +--------------+
                                       |     |Node          |
                                       +---->|data: "c"     |
                                             |children: none|
                                             +--------------+
```

which shows up on crates-io as

+--------------+
                                             |Node          |
                                       +---->|data: "a"     |
+------------+    +---------------+    |     |children: none|
|Node        |    |Vec<Arc<Node>> |    |     +--------------+
|data: "abc" |    |[0]: +--------------+     |Node          |
|children: +----->|[1]: +------------------->|data: "b"     |
+------------+    |[2]: +--------------+     |children: none|
                  +---------------|    |     +--------------+
                                       |     |Node          |
                                       +---->|data: "c"     |
                                             |children: none|
                                             +--------------+

For comparison purposes, lib-rs renders this correctly.

github

image

crates-io

image

lib-rs

image

@Turbo87 Turbo87 added A-backend ⚙️ C-bug 🐞 Category: unintended, undesired behavior labels May 10, 2020
@jtgeibel
Copy link
Member

I was hoping bumping to the latest version of comrak in #2513 would resolve this, but that doesn't appear to be the case. I haven't had a chance trace through the readme logic to see if this is being removed by comrak or some other step in the HTML sanitation process.

@jtgeibel
Copy link
Member

I've dug into this a bit more, and it looks like this is a frontend issue with syntax highlighting. The rendered reame looks fine when loaded directly from https://static.crates.io/readmes/slice-dst/slice-dst-1.4.1.html

If I remove the {{highlight-syntax selector="pre > code"}} from

<section local-class="crate-readme" aria-label="Readme" {{highlight-syntax selector="pre > code"}}>
then the issue goes away, although this is obviously a loss of functionality.

@Turbo87
Copy link
Member

Turbo87 commented May 20, 2020

interesting, I'll have a look!

bors added a commit that referenced this issue Jun 10, 2020
modifiers/highlight-syntax: Disable aggressive whitespace stripping

see https://prismjs.com/plugins/normalize-whitespace/

Resolves #2498

r? @locks
@bors bors closed this as completed in 87a070e Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend 🐹 C-bug 🐞 Category: unintended, undesired behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants