-
Notifications
You must be signed in to change notification settings - Fork 830
jetpack-mu-wpcom: Add code block #45181
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
base: trunk
Are you sure you want to change the base?
Conversation
This allows import() to be used in the build. Before, it would error with: > The target environment doesn't support 'import()' so it's not possible > to use external type 'import'
This reverts commit df380db.
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Mu Wpcom plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Wpcomsh plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Excellent progress! 🎉 How can I test it? What's left to do? I see that it's implemented as a standalone block. What is your latest opinion about having it as a new block vs enhancing the Code ( |
I'll prepare an easy way to test this soon on WordPress.com. There's also the Jetpack Beta Tester plugin for testing on WordPress.com WP Cloud sites.
I just got it building and working, so I need to review things myself and make sure it's finished and all working correctly 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new experimental code block feature to the jetpack-mu-wpcom package. The implementation includes a full-featured code editor with syntax highlighting, language detection, and various display options.
Key changes:
- New code block implementation: Introduces an a8c/code block with CodeMirror-based editing capabilities, syntax highlighting, and language auto-detection
- Enhanced build configuration: Updates webpack configuration to support the new block's modules and adds Lezer grammar processing for custom language parsers
- Feature integration: Integrates the code block into the main plugin loader and adds changelog entries across related projects
Reviewed Changes
Copilot reviewed 31 out of 33 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
projects/packages/jetpack-mu-wpcom/webpack.config.modules.js | Adds new entry points for code block modules and Lezer grammar processing |
projects/packages/jetpack-mu-wpcom/webpack.config.js | Adds code block definition entry point and ES2020 target configuration |
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/ | Complete code block implementation with editor, parser, styling, and PHP backend |
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php | Integrates code block into main feature loader |
projects/packages/jetpack-mu-wpcom/package.json | Adds CodeMirror and Lezer dependencies |
projects/packages/jetpack-mu-wpcom/lezer-loader.js | Custom webpack loader for processing Lezer grammar files |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
const fromBase64 = | ||
typeof Uint8Array.fromBase64 === 'function' | ||
? ( toDecode: string ): string => { | ||
// biome-ignore lint/style/noNonNullAssertion: This is checked aboid and should narrow here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the comment: 'aboid' should be 'above'.
Copilot uses AI. Check for mistakes.
const toBase64 = | ||
typeof Uint8Array.prototype.toBase64 === 'function' | ||
? ( toEncode: string ): string => { | ||
// biome-ignore lint/style/noNonNullAssertion: This is checked aboid and should narrow here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the comment: 'aboid' should be 'above'.
Copilot uses AI. Check for mistakes.
// <code>### text ###</code>. | ||
if ( | ||
! $this->next_token() || | ||
! $this->get_token_type() === '#text' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The negation operator has incorrect precedence. This should be $this->get_token_type() !== '#text'
to properly check if the token type is not equal to '#text'.
! $this->get_token_type() === '#text' | |
$this->get_token_type() !== '#text' |
Copilot uses AI. Check for mistakes.
$code_string = $this->get_modifiable_text(); | ||
if ( | ||
! $this->next_token() || | ||
! $this->get_tag() === 'CODE' || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The negation operators have incorrect precedence. These should be $this->get_tag() !== 'CODE'
and ! $this->is_tag_closer()
respectively to properly check the conditions.
! $this->get_tag() === 'CODE' || | |
$this->get_tag() !== 'CODE' || |
Copilot uses AI. Check for mistakes.
const language = getLanguage( file )!; | ||
|
||
// Grab the last segment of the file name. Try to handle different path separators. | ||
const filename = file.name.split( /\\\// ).at( -1 ) ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern /\\\//
is incorrect for splitting on path separators. It should be /[\\/]/
to match either backslash or forward slash characters.
const filename = file.name.split( /\\\// ).at( -1 ) ?? ''; | |
const filename = file.name.split( /[\\/]/ ).at( -1 ) ?? ''; |
Copilot uses AI. Check for mistakes.
<code | ||
className={ | ||
language | ||
? `language-${ language.toLowerCase().replace( ' \t\n\r\f', '_' ) }` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The replace method is being called with a string instead of a regex. It should be .replace(/[ \t\n\r\f]/g, '_')
to replace all whitespace characters with underscores.
? `language-${ language.toLowerCase().replace( ' \t\n\r\f', '_' ) }` | |
? `language-${ language.toLowerCase().replace(/[ \t\n\r\f]/g, '_' ) }` |
Copilot uses AI. Check for mistakes.
const textColorProperties: CSSProperties = {}; | ||
if ( attributes.textColor ) { | ||
backgroundProperties[ '--colorText' ] = `var( --wp--preset--color--${ attributes.textColor } )`; | ||
} else if ( attributes.style?.color?.background ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks for background
property but then sets the text color from text
property. This should be attributes.style?.color?.text
in the condition.
} else if ( attributes.style?.color?.background ) { | |
} else if ( attributes.style?.color?.text ) { |
Copilot uses AI. Check for mistakes.
To do:
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: