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

fix: custom titles of code snippets inside code groups #1834

Merged
merged 11 commits into from
Feb 14, 2023

Conversation

Raiondesu
Copy link
Contributor

This PR fixes #1785, by allowing the following syntax when a snippet is placed in a code group:

::: code-group

<<< @/snippets/snippet.js [snippet.js]

<!-- with custom tab titles -->
<<< @/snippets/snippet-with-region.js [snippet with region custom title]

<!-- filename is now grabbed by-default -->
<<< @/snippets/snippet.cs{1,2,4-6 c#}

:::

See updated docs for an example.

@Raiondesu Raiondesu changed the title Fix: custom titles of code snippets inside code groups fix: custom titles of code snippets inside code groups Jan 22, 2023
@sky124380729
Copy link

when would it be merged, i need this feature

@Raiondesu
Copy link
Contributor Author

@brc-dd, please take a look at this 🙏

It's a small fix, but oh so useful

@MarkusKeck
Copy link
Collaborator

I would also appreciate if this gets merged.
Does the proposed solution allow to include icons (in my case fontawesome) as description, judging from the regex it does not?
The current implementation does allow it. I would suggest a uniform behavior.

Example (Changed ` for ' so it gets displayed correctly)

'''java [<i class="fa-sharp fa-solid fa-flag-checkered"></i> Alternate Solution]
 ... content
'''

image

@Raiondesu
Copy link
Contributor Author

@MarkusKeck, technically the regex doesn't disallow the markup inside the [title] brackets, though I didn't test for this.

This PR's code simply passes the parsed title to already existing logic for processing.

@MarkusKeck
Copy link
Collaborator

@Raiondesu Even better.
I just saw you added the following regex ?(?:\[([\w0-9_\-\.]+)\])? in src/node/markdown/plugins/snippet.ts:101
I checked it with https://regex101.com/ and the icon version did pass. I am not completly sure why, but it seems your addition did not affect the default behavior much. Someone with more experience in regex should take a look at this ;)

I really like the approach and implementation. It will make my project much cleaner. At the moment I am using a "workaround" which allows me to externalize my snippets but also allows me to change the displayed name.

::: code-group

<!--@include: ./../../../snippets/xxx.java-->
<!--@include: ./../../../snippets/yyy.java-->
<!--@include: ./../../../snippets/zzz.java-->

:::

Inside every file I have to add the codetab markup (see example above). It is not really pretty but the only way I could figure out to make this work. Looking forward to getting this merged. Thanks for the implementation.

@brc-dd brc-dd self-assigned this Feb 7, 2023
@Raiondesu
Copy link
Contributor Author

Raiondesu commented Feb 7, 2023

@MarkusKeck, thanks! I believe the regex you mentioned was actually changed to ?(?:\[(.+)\])?$ in this commit, though I must admit I didn't expect the original regex to work too! 😅

@Raiondesu
Copy link
Contributor Author

@brc-dd, what's keeping this from being merged?
Maybe I need to change something in the pr?

@brc-dd brc-dd merged commit bcb8cbf into vuejs:main Feb 14, 2023
@MarkusKeck
Copy link
Collaborator

Thank you @brc-dd

@RaniAgus
Copy link

Thank you! @Raiondesu @brc-dd

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 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.

Can't change title of code snippets inside code groups
5 participants