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

Parser Error on String Literal inside mustache #55

Open
5 tasks done
zojize opened this issue Oct 27, 2024 · 1 comment
Open
5 tasks done

Parser Error on String Literal inside mustache #55

zojize opened this issue Oct 27, 2024 · 1 comment

Comments

@zojize
Copy link

zojize commented Oct 27, 2024

Describe the bug

I'm not sure if this is the right place to raise this issue, but I encountered an issue with function calls inside a mustache tag in a markdown file. And I was able to recreate this error using the example folder in this repo.

[vite] Internal server error: Error parsing JavaScript expression: Unexpected character '“'. (1:13)
  Plugin: vite:vue
  File: /home/unplugin/unplugin-vue-markdown/examples/vite/pages/index.md:1:44
  2  |  title: Hello
  3  |  meta:
  4  |    - name: description
     |                       ^
  5  |      content: Hello World
  6  |  test: test
      at createCompilerError (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js#cjs:1329:17)
      at emitError (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js#cjs:2822:5)
      at createExp (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js#cjs:2815:7)
      at Object.oninterpolation (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js#cjs:2156:16)
      at Tokenizer.stateInterpolationClose (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js#cjs:546:18)
      at Tokenizer.parse (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js#cjs:1047:16)
      at Object.baseParse (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js#cjs:2861:13)
      at Object.parse (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js#cjs:703:23)
      at Object.parse$2 [as parse] (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected]/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js#cjs:1851:24)
      at createDescriptor (file:///home/unplugin/unplugin-vue-markdown/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@vitejs/plugin-vue/dist/index.mjs:90:43)

Reproduction Steps (StackBlitz):

  1. Open this repo using stack blitz
  2. Run the following commands:
pnpm i
cd examples/vite
pnpm i
pnpm run dev
  1. Apparently the there is a parser error caused by the examples/vite/README.md, but I'm ignoring it for now by removing the contents inside, might be worth to look at this issue as well.
  2. Edit examples/vite/pages/index.md and add {{ console.log("test") }} anywhere after the frontmatter section of the code. It doesn't have to be console.log("test"), anything that has a string literal will cause an error.
  3. You see this parser error

Reproduction

https://stackblitz.com/~/github.com/unplugin/unplugin-vue-markdown

System Info

Irrelevant since I was able to reproduce this on StackBlitz, but here's my envinfo:

  System:
    OS: macOS 12.5
    CPU: (8) arm64 Apple M1
    Memory: 148.33 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 22.8.0 - ~/.nvm/versions/node/v22.8.0/bin/node
    Yarn: 1.22.18 - ~/.pnpm/bin/yarn
    npm: 10.8.3 - ~/.nvm/versions/node/v22.8.0/bin/npm
    pnpm: 9.5.0 - ~/.pnpm/bin/pnpm
  Browsers:
    Chrome: 130.0.6723.70
    Safari: 16.6

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@zojize
Copy link
Author

zojize commented Nov 7, 2024

This appears to be an issue with markdown-it converting regular quotes (""'') to typographical quotes (“”‘’) by default, I was able to fix it by adding quotes: '""\'\'' to the configuration. But should this be made the default by the plugin since using literal strings aren't that uncommon? My specific use case was link resolution using {{ $router.resolve("foo/bar").href }}, which by the way doesn't work when put inside a markdown link like this [foo/bar]({{ $router.resolve("foo/bar").href }}), but solving this may be beyond the scope of this plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant