Skip to content

@gridsome/remark-prismjs breaks on nested code block syntax #1524

@songololo

Description

@songololo

Description

@gridsome/remark-prismjs breaks when processing nested code block syntax, e.g.


````markdown

# some text

```python
some = 'code'
```

````markdown

These nested style code blocks (where the inner block is not meant to be rendered) are useful for documentation pages.

This bug only started with the latest prism release a few days ago.

I've made a pull request at prism to add a check for whether document exists in the current context:
PrismJS/prism#2975

In the meantime, the prism version needs to be pinned to 1.23.0 per this pull-request: #1525

Steps to reproduce

Create and build a markdown page with @gridsome/vue-remark and @gridsome/remark-prismjs, e.g.


````markdown

# some text

```python
some = 'code'
```

````markdown

Expected result

The result should look per github rendered result

# some text

```python
some = 'code'
```

Actual result

ReferenceError: document is not defined
    at /Users/username/project-name/node_modules/prismjs/components/prism-markdown.js:354:24
    at Object.run (/Users/username/project-name/node_modules/prismjs/prism.js:720:6)
    at stringify (/Users/username/project-name/node_modules/prismjs/prism.js:836:11)
    at /Users/username/project-name/node_modules/prismjs/prism.js:813:10
    at Array.forEach (<anonymous>)
    at stringify (/Users/username/project-name/node_modules/prismjs/prism.js:812:6)
    at stringify (/Users/username/project-name/node_modules/prismjs/prism.js:820:13)
    at /Users/username/project-name/node_modules/prismjs/prism.js:813:10
    at Array.forEach (<anonymous>)
    at Function.stringify (/Users/username/project-name/node_modules/prismjs/prism.js:812:6)
    at Object.highlight (/Users/username/project-name/node_modules/prismjs/prism.js:630:17)
    at highlight (/Users/username/project-name/node_modules/@gridsome/remark-prismjs/index.js:36:13)
    at createCode (/Users/username/project-name/node_modules/@gridsome/remark-prismjs/index.js:72:26)
    at /Users/username/project-name/node_modules/@gridsome/remark-prismjs/index.js:23:38
    at overload (/Users/username/project-name/node_modules/@gridsome/remark-prismjs/node_modules/unist-util-visit/index.js:27:12)
    at one (/Users/username/project-name/node_modules/@gridsome/remark-prismjs/node_modules/unist-util-visit-parents/index.js:34:25)

Environment

  System:
    OS: macOS 11.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  Binaries:
    Node: 16.4.0 - /var/folders/bs/sq3p18cs4dn1ws4kpmfyk_3c0000gn/T/yarn--1625138660567-0.8438846376893232/node
    Yarn: 1.22.10 - /var/folders/bs/sq3p18cs4dn1ws4kpmfyk_3c0000gn/T/yarn--1625138660567-0.8438846376893232/yarn
    npm: 7.18.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 91.0.4472.114
    Edge: 91.0.864.59
    Firefox: 88.0.1
    Safari: 14.1.1
  npmPackages:
    @gridsome/plugin-sitemap: ^0.4.0 => 0.4.0 
    @gridsome/remark-prismjs: ^0.5.0 => 0.5.0 
    @gridsome/transformer-remark: ^0.6.4 => 0.6.4 
    @gridsome/vue-remark: ^0.2.6 => 0.2.6 
    gridsome: ^0.7.23 => 0.7.23 
    gridsome-plugin-pug: ^0.0.3 => 0.0.3 
    gridsome-plugin-remark-container: ^0.1.3 => 0.1.3 
    gridsome-plugin-robots-txt: ^1.0.2 => 1.0.2 
    gridsome-remark-katex: ^0.1.1 => 0.1.1 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions