Skip to content

Add language import specification to code snippet imports #1191

@qdot

Description

@qdot

Feature request

What problem does this feature solve?

Importing code snippets currently uses the filename extension as the prism language. While this is fine for things like test.html and test.js, when you're using something like Makefile or Program.cs, the parser fails or prism gets a language specifier it doesn't understand. If prism language can be set specifically in an snippet import line, it'd be easier than trying to guess.

See #1189 for more info.

What does the proposed API look like?

A "lang=[prism language name]" token added to the import snippet line. Preferably before the file URI.

>>> lang=csharp @/test/Program.cs

"=" is used because ":" is already caught in the regex later for the path, not sure what the : is used for otherwise but didn't want to conflict.

How should this be implemented in your opinion?

Should be able to add it to vuepress/packages/@vuepress/markdown/lib/snippet.js. That's already just hand-parsing the line anyways.

Are you willing to work on this yourself?**

Yup. Shouldn't be too difficult, just want to make sure the format is acceptable before putting in a PR.

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