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

Code block not recognized as one if there is trailing space on the closing fence #135

Open
kirawi opened this issue Feb 20, 2024 · 5 comments · May be fixed by #155
Open

Code block not recognized as one if there is trailing space on the closing fence #135

kirawi opened this issue Feb 20, 2024 · 5 comments · May be fixed by #155
Labels
bug Something isn't working

Comments

@kirawi
Copy link

kirawi commented Feb 20, 2024

Describe the bug

Ref helix-editor/helix#9678

Code example

'''c
''' 
int i = 0;

Replace the single quotes with backticks and int i = 0 will be highlighted as C.

Expected behavior

According to https://github.github.com/gfm/#fenced-code-blocks, trailing whitespace are ignored on the closing code fence.

Actual behavior

Closing fence is not recognized.

@kirawi kirawi added the bug Something isn't working label Feb 20, 2024
@clason
Copy link
Collaborator

clason commented Feb 21, 2024

For the record, this parser implements CommonMark Spec, with only some GFM extensions (that are optional but enabled by default). I would prefer to stay strict on this (and similar "softenings" of restrictions that make parsing easier).

@clason
Copy link
Collaborator

clason commented Feb 21, 2024

But CommonMark also specifies that whitespace after closing fences are to be ignored, so this should be fixed (here). PR welcome!

@savetheclocktower
Copy link

savetheclocktower commented Mar 20, 2024

I can confirm that this also happens when the closing fence is followed immediately by EOF. That's an easier scenario to catch than trailing whitespace, so I might open a PR for that case specifically.

@pokey
Copy link

pokey commented Jun 14, 2024

I can confirm that this also happens when the closing fence is followed immediately by EOF. That's an easier scenario to catch than trailing whitespace, so I might open a PR for that case specifically.

If that's easy, a fix there would be awesome, because I think that's probably a more common scenario than trailing whitespace, though obviously both would be nice to have

@pokey
Copy link

pokey commented Jun 14, 2024

I would think both should be a fairly easy fix, no? I might be missing something, but it looks like we could just check for end of file or space in addition to \r and \n in

(lexer->lookahead == '\n' || lexer->lookahead == '\r')) {

@SomeoneToIgnore SomeoneToIgnore linked a pull request Jul 22, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

4 participants