Skip to content

Highlighting more than 2 separate lines when importing code snippets produces "Invalid code snippet option" error #2546

Closed
@adamdehaven

Description

@adamdehaven
  • I confirm that this is an issue rather than a question.

Bug report

Steps to reproduce

  1. Save a new code snippet to .vuepress/public/snippet.js with any content. Here's an example:
const name = 'First Last'

// Create person object
let person = {
    name: name,
    email: 'test@example.com'
}
  1. Import code snippet in a Markdown file with lines highlighted: <<< @/.vuepress/public/snippet.js{2-4,6}
  2. Serve project locally with npm run dev (or whatever your serve command is to run vuepress dev)
  3. See error message: "Invalid code snippet option"

What is expected?

Code should be imported with highlighted lines.

What is actually happening?

Code import fails with message:

Invalid code snippet option

Examples:

  • <<< @/.vuepress/public/snippet.js - ✔️ Works (no highlighted lines)
  • <<< @/.vuepress/public/snippet.js{2} - ✔️ Works (1 highlighted line)
  • <<< @/.vuepress/public/snippet.js{2,4} - ✔️ Works (2 highlighted lines)
  • <<< @/.vuepress/public/snippet.js{2-4} - ✔️ Works (1 range of highlighted lines)
  • <<< @/.vuepress/public/snippet.js{2,4,6} - ❌ Fails (3 highlighted lines)
  • <<< @/.vuepress/public/snippet.js{2-4,6} - ❌ Fails (1 range of highlighted lines and 1 single line)

Other relevant information

  • Code highlighting works property in regular code blocks
  • Output of npx vuepress info in my VuePress project:
Environment Info:

  System:
    OS: Windows 10 10.0.16299
    CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
  Binaries:
    Node: 10.15.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 41.16299.1480.0
  npmPackages:
    @vuepress/core:  1.5.2
    @vuepress/theme-default:  1.5.2
    vuepress: ^1.5.2 => 1.5.2
  npmGlobalPackages:
    vuepress: Not Found

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