Skip to content

feat(theme-classic): Add CodeBlockToken component for swizzling #11022

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

Closed
wants to merge 11 commits into from

Conversation

Danielku15
Copy link
Contributor

@Danielku15 Danielku15 commented Mar 23, 2025

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

This PR is part of a series related to #11008 and it superceeds #11011 in the goal to splitup the work into more isolated refactoring/feature parts.

Note that this PR also includes the changes of previous steps and therefore the overall diff can be misleading. The best approach will be to review and merge every step individually and then rebase accordingly.

Intermediately the specific changes can be checked here: Danielku15/docusaurus@feature/codeblock-meta-3...Danielku15:docusaurus:feature/codeblock-meta-4

Step 1 (#11017): Splitup current parseLines logic (separation of concerns)
Step 2 (#11019): Parse metastring into metaOptions and use it across components.
Step 3 (#11021): Add parsing of any options specified in the metastring.
Step 4 (this PR): Add CodeBlockToken component to customize DOM of highlighted tokens.
Step 5: Pass metaOptions to whole codeblock component tree.

The motivation of this part is to allow users to customize the rendering of the individual tokens rendered on the syntax highlighting. The component receives the props of the parent Line which already allows some degree of customization based on the data available.

This change will unleash its full potential with Step 5 when we pass down metaOptions to all components.

Test Plan

Automatic testing relies on existing integration tests.

Manual testing by checking /docs/markdown-features/code-blocks showed no impact of the change.

If more testing is expected I'd need some guidance on how to typically such tests are written for Swizzled components.

Test links

Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Code Blocks: https://deploy-preview-_____--docusaurus-2.netlify.app/docs/markdown-features/code-blocks/

Related issues/PRs

Copy link

netlify bot commented Mar 23, 2025

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 8f90795
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/67dff2a94cab2300081df1f7
😎 Deploy Preview https://deploy-preview-11022--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Mar 23, 2025

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO Report
/ 🟠 69 🟢 98 🟢 100 🟢 100 Report
/docs/installation 🟠 50 🟢 97 🟢 100 🟢 100 Report
/docs/category/getting-started 🟠 73 🟢 100 🟢 100 🟠 86 Report
/blog 🟠 61 🟢 96 🟢 100 🟠 86 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 62 🟢 92 🟢 100 🟢 100 Report
/blog/tags/release 🟠 62 🟢 96 🟢 100 🟠 86 Report
/blog/tags 🟠 73 🟢 100 🟢 100 🟠 86 Report

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this change be merged independently from other PRs if you removed all the unrelated things?


export default function CodeBlockToken(props: Props): ReactNode {
// We omit the "line" information in the default rendering,
// but its meant for devs who devs who Swizzle this component.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

@Danielku15 Danielku15 force-pushed the feature/codeblock-meta-4 branch from 8f90795 to 2acb5bd Compare March 28, 2025 12:19
@slorber
Copy link
Collaborator

slorber commented Apr 4, 2025

Added, see #11017 (comment)

@slorber slorber closed this Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants