-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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(v2): fix code block title parsing, support multiple metastring attributes #4541
Conversation
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-4541--docusaurus-2.netlify.app/ |
Thanks I know we don't have much tests in the theme currently but our goel is to add tests. Can you please extract a |
extract `parseCodeBlockTitle` function to add tests for title parsing
[V2] Built with commit aed1216 |
ah sorry was kinda busy. also, just as a note, swizzling the resultant |
Thanks, this is what I had in mind. Will take a look for swizzle and test folder, thanks. |
[V1] Built with commit aed1216 |
Motivation
In its current form, the
docusaurus-theme-classic
CodeBlock title captures everything from its opening delimiter to the last double quote in the line. This means other code block metadata must either use a delimiter other than double quotes, or be placed before thetitle="
delimiter. Changing it to only capture until the next double quote would allow greater flexibility in code block metadata.Doing this change would prevent double quotes from being parts of code block titles. A simple and self-evident solution, implemented in this PR as well, is in allowing the title to be delimited by single quotes as well would accommodate for these cases. It should be noted, however, that code block titles containing both single and double quotes would still have no alternative. Other ideas on how to approach this issue would be beneficial.
Have you read the Contributing Guidelines on pull requests?
yes
Test Plan
I swizzled the classic theme CodeBlock component and made the changes on one of my projects using Docusaurus before making this.
Related PRs
The code block docs do not mention that the title must currently be enclosed by double quotes, nor that it captures from the opening double quote to the last double quote in the line.
I can update the docs upon request or if/when this gets approved.