slidev icon indicating copy to clipboard operation
slidev copied to clipboard

Leading whitespace in code blocks breaks all subsequent highlighted codeblocks

Open EmNudge opened this issue 1 year ago • 1 comments

Describe the bug

If you have a leading white space in a codeblock, it will break the parser such that having subsequent highlighted codeblocks will crash the current slide.

image

This is an issue for assembly which often has leading whitespace. This is also where I encountered this problem.

Minimal reproduction

https://stackblitz.com/edit/github-sspw9v?file=slides.md=

block 1

```
 test
```

block 2

```js
const val = 42
```

Environment

  • Slidev version: 0.49.29
  • Browser: Chrome
  • OS: MacOS

EmNudge avatar Sep 16 '24 17:09 EmNudge

Thanks for the report! I also encountered same exception this afternoon, but slightly different cause.


```python {all}{lines: true}

print(test)
```

It won't occur if there's no {lines: true}

the leading blank line will cause same issue. Thanks to the report, provide me a clue.

zillionare avatar Sep 20 '24 10:09 zillionare

I am sorry for the late reply.

@EmNudge I've opened https://github.com/slidevjs/slidev/pull/1909 to allow leading whitespace in code blocks.

@zillionare In my opinion the leading empty lines are invalid. Because Slidev wraps code blocks before passing the code to the Markdown parser, we may not be able to handle them correctly.

kermanx avatar Oct 25 '24 10:10 kermanx

@KermanX

Thank you for the answering my question.

Although my example may not be syntactically correct, I believe many others might also be confused about the formatting requirements here. So, it would be helpful to keep this as a record.

It would be even better if there could be a section in the documentation or discussions dedicated to recording these invalid cases that people often make mistakes with.

zillionare avatar Oct 26 '24 06:10 zillionare