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

Syntax highlighting hangs when using a substring pattern with ' #185

Open
kpietak opened this issue Mar 17, 2024 · 2 comments
Open

Syntax highlighting hangs when using a substring pattern with ' #185

kpietak opened this issue Mar 17, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@kpietak
Copy link

kpietak commented Mar 17, 2024

I have come across a problem with highlighting sections of source code using a pattern/substring using Nextra.

I am presenting code in Rust that implements lifetimes annotations marked with ' , for example:
fn longer<'a>(a : &'a [i32], b : &'a [i32]) -> &'a [i32].

I am trying to highlight the annotation itself ('a) using the code:

    ```rust /'a/
    fn longer_array<'a>(a : &'a [i32], b : &'a [i32]) -> &'a [i32] {
        ...
    }```

This syntax causes the page rendering to crash (even terminating the process causes the node to remain on).

The problem has been previously reported in the Nextra project (shuding/nextra#2792) and was redirected here as a code rendering issue.

@atomiks
Copy link
Collaborator

atomiks commented Mar 17, 2024

Nextra seems to be using v0.9.11 which is a bit old now as the current version is v0.13.0. In v0.12.1, a bug was fixed with word highlighting that could cause an infinite loop, although I thought it was a regression introduced in v0.12.0 🤔

Can you try to repro it using the latest version of rehype-pretty-code alone?

@kpietak
Copy link
Author

kpietak commented Mar 17, 2024

I've reproduced the error using the current version (v.0.13.0). Here is the sample code (a modified demo):

import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import rehypePrettyCode from "rehype-pretty-code";
 
async function main() {
  const file = await unified()
    .use(remarkParse)
    .use(remarkRehype)
    .use(rehypePrettyCode, {
      // See Options section below.
    })
    .use(rehypeStringify)
    .process(`\`\`\`rust /'a/
    
    fn longer_array<'a>(a : &'a [i32], b : &'a [i32]) -> &'a [i32] {
        
    }
    `);
 
  console.log(String(file));
}
 
main();

@o-az o-az added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants