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

feat(build): improve code blocks and snippets #875

Merged
merged 8 commits into from Jul 23, 2022
Merged

feat(build): improve code blocks and snippets #875

merged 8 commits into from Jul 23, 2022

Conversation

@brc-dd brc-dd changed the title feat: add support for specifying language in imported snippets feat(build): support specifying language in imported snippets Jun 28, 2022
@emersonbottero
Copy link

Shouldn't It recognize the language by the extension?
cs => c#
py => python

and so on?

@brc-dd
Copy link
Member Author

brc-dd commented Jul 1, 2022

@emersonbottero Read this section https://deploy-preview-875--vitepress-docs.netlify.app/guide/markdown.html#import-code-snippets

You'll have to provide language in case of C#. For *.py, the language will be auto detected as the extension py is a valid language specifier.

I have not implemented language-extension mapping because it will be a fairly long list that we'll need to hard code. It is better to rely on users to override the detected language (the extension of file).

(If your file extension is in this list, then you don't need to specify language: https://github.com/shikijs/shiki/blob/main/docs/languages.md#all-languages)

@emersonbottero
Copy link

@emersonbottero Read this section https://deploy-preview-875--vitepress-docs.netlify.app/guide/markdown.html#import-code-snippets

You'll have to provide language in case of C#. For *.py, the language will be auto detected as the extension py is a valid language specifier.

I have not implemented language-extension mapping because it will be a fairly long list that we'll need to hard code. It is better to rely on users to override the detected language (the extension of file).

(If your file extension is in this list, then you don't need to specify language: https://github.com/shikijs/shiki/blob/main/docs/languages.md#all-languages)

Oh..

Ho, If I ask tô chance
| 'csharp' | 'c#'
to
| 'csharp' | 'c#' | 'cs'
In the shiki lib It should work them? ... 🤔

@brc-dd
Copy link
Member Author

brc-dd commented Jul 1, 2022

Yeah it would work then. BTW how frequently do you import snippets? There won't be much IG, so {c#} syntax should not be much trouble.

@brc-dd brc-dd changed the title feat(build): support specifying language in imported snippets feat(build): improve code blocks and snippets Jul 2, 2022
@meteorlxy
Copy link
Member

The syntax from markdown-it-vuepress-code-snippet-enhanced looks more markdown-like and extendable (I saw you have noticed that @brc-dd ), so I chose to implement it in vuepress-next (not as powerful as that plugin though).

Anyway, the <<< syntax has being always marked as beta in VuePress v1 (link), so we could still consider changing it.

@brc-dd
Copy link
Member Author

brc-dd commented Jul 8, 2022

But I don't think it supports importing regions from files. Or does it? Probably that transclude thing? But I'm not quite sure what it does.

@meteorlxy
Copy link
Member

meteorlxy commented Jul 8, 2022

It does: https://github.com/fabioaanthony/markdown-it-vuepress-code-snippet-enhanced#transclusion

I'd say that plugin is really powerful 😅

@brc-dd
Copy link
Member Author

brc-dd commented Jul 13, 2022

@meteorlxy So should we go ahead with this PR or implement that syntax? This PR fixes two other issues, I'll split it. We can track snippets (#861) separately from issues with code blocks.

@emersonbottero
Copy link

@meteorlxy So should we go ahead with this PR or implement that syntax? This PR fixes two other issues, I'll split it. We can track snippets (#861) separately from issues with code blocks.

even with the plugin I think it still makes sense to keep it in vitepress since it already has the feature to import code out of the box.

@brc-dd
Copy link
Member Author

brc-dd commented Jul 23, 2022

Let's merge this for now, we can work on changing the importing format later.

@emersonbottero
Copy link

shikijs/shiki#351

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants