Skip to content

feat(theme-classic): Pass metaOptions to whole codeblock component tree. #11023

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 12 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-4...Danielku15:docusaurus:feature/codeblock-meta-5

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 (#11022): Add CodeBlockToken component to customize DOM of highlighted tokens.
Step 5 (this PR): Pass metaOptions to whole codeblock component tree.

The motivation of this part is to allow users to customize the rendering of the components by utilizing any special metaOption which is applied to the code blocks.

Use cases are:

  1. Adjust the whole CodeBlock (e.g. replacing the syntax highlighter) or the Live Editor (passing on further options to react-live).
  2. Adjust the individual CodeBlockLine (e.g. checking for options which could hide/show lines dynamically, rendering additional annotations,..)
  3. Adjust the individual CodeBlockToken (e.g. render white spaces, link to mdn or webplatform.org, inline color,...)

The metaOptions doesn't need to be passed explicitely to the CodeBlockToken as it is accessible through props.line.metaOptions (See #11022).

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-11023--docusaurus-2.netlify.app/
Code Blocks: https://deploy-preview-11023--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 ed0a579
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/67dff69f0be2fd0008849236
😎 Deploy Preview https://deploy-preview-11023--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
/ 🔴 42 🟢 98 🟢 100 🟢 100 Report
/docs/installation 🔴 48 🟢 97 🟢 100 🟢 100 Report
/docs/category/getting-started 🟠 72 🟢 100 🟢 100 🟠 86 Report
/blog 🟠 61 🟢 96 🟢 100 🟠 86 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 66 🟢 92 🟢 100 🟢 100 Report
/blog/tags/release 🟠 60 🟢 96 🟢 100 🟠 86 Report
/blog/tags 🟠 73 🟢 100 🟢 100 🟠 86 Report

@Danielku15 Danielku15 force-pushed the feature/codeblock-meta-5 branch from ed0a579 to 2530d7e Compare March 28, 2025 12:19
@slorber
Copy link
Collaborator

slorber commented Apr 4, 2025

Added, see #11017 (comment)

(available as context instead of props)

@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