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

Strings starting with "{%" inside code blocks are parsed as unclosed Markdoc, clogging builds #72

Closed
matildepark opened this issue Jun 2, 2022 · 4 comments · Fixed by #94
Assignees
Labels
bug Something isn't working

Comments

@matildepark
Copy link

What happened?

I've been migrating our website to Markdoc. We use a bit of an esoteric programming language that does use {%term} format at times. When running next build, on the build would halt on one of 5 pages and my node would gradually use 12GB of RAM until my system froze.

Deleting files and escaping the Markdown render I've nailed it down to pages that have strings that start with {% inside a code block. Examples:

image

image

image

If I delete these lines from all these files, the build runs fine. If I retain even one, it goes into its death spiral.

To reproduce

Place one of those strings on a page. Should be enough. It looks like the Markdoc website wraps examples in a custom tag — was this an intentional workaround? We can do similar ...

Version

0.1.2

Additional context

No response

@rpaul-stripe
Copy link
Contributor

By default, the Markdoc parser attempts to parse Markdoc tags that appear inside of fenced code blocks. This behavior can be disabled individually per fenced code block by putting a process=false annotation in the fenced block's info line:

```js {% process=false %}
// Things that look like tags are ignored
console.log("{%"); 
```

We probably ought to add a global configuration option for this so that it doesn't need to be set individually for each fence.

@RomanHotsiy
Copy link
Collaborator

We probably ought to add a global configuration option for this so that it doesn't need to be set individually for each fence.

That would be great! I would also vote for making process=false the default.

@matildepark
Copy link
Author

{% process=false %} created some issues with my highlighter (prism-react-renderer), specifically crashing because it was trying to process a code block that was undefined? Seems like it just skips over it. If I try to call the Fence component like a custom component ({% fence process=false %}) then it seems to just skip over processing the entire block, so that clearly isn't the way. Anyway, for now I've just escaped the strings.

@khash
Copy link

khash commented Jul 1, 2022

I had some Liquid template code I needed to render as a code block and given the similarities of Liquid and Markdoc, the page wasn't rendering (non-closed tags and many other issues as expected). I tried the {% process=false %} method which perhaps combined with my Prism highlighter (Next.js) fixed the errors, but also skipped the entire code block (and empty element was returned).

I managed to fix the issue by using the Markdoc's own Doc repository and the markdoc-example tag (https://github.com/markdoc/docs/blob/main/markdoc/tags/markdoc-example.markdoc.js).

Your milage may vary, but it worked for me.

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
4 participants