Skip to content

Commit d222e4d

Browse files
authored
jetpack-mu-wpcom: Add code block (disabled) (#45181)
Add the Code Block feature to jetpack-mu-wpcom. The feature implementation is added but is not enabled anywhere. See pgsdXZ-j-p2.
1 parent 06e3eac commit d222e4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4291
-1
lines changed

pnpm-lock.yaml

Lines changed: 345 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Add code block
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { buildParserFile } = require( '@lezer/generator' );
2+
3+
/**
4+
* Webpack loader for processing Lezer parser grammars.
5+
*
6+
* This loader processes `.grammar` files and generates the appropriate module code.
7+
* It supports multiple ways to request parser vs terms:
8+
* - `xyz.grammar` (default) for the generated parser
9+
* - `xyz.grammar?terms` for the parser terms
10+
*
11+
* Usage in webpack config:
12+
* ```
13+
* module.exports = {
14+
* module: {
15+
* rules: [
16+
* {
17+
* test: /\.grammar$/,
18+
* use: 'lezer-loader.js',
19+
* }
20+
* ]
21+
* }
22+
* };
23+
* ```
24+
*
25+
* Usage in code:
26+
* ```
27+
* import parser from './xyz.grammar';
28+
* import * as terms from './xyz.grammar?terms';
29+
* ```
30+
*
31+
* @see [https://lezer.codemirror.net](https://lezer.codemirror.net)
32+
* @see [https://github.com/lezer-parser/generator/blob/dbf0e3d579cf383a4dea2c1ed50ba3fd5407cf81/src/rollup-plugin-lezer.js](https://github.com/lezer-parser/generator/blob/dbf0e3d579cf383a4dea2c1ed50ba3fd5407cf81/src/rollup-plugin-lezer.js)
33+
*
34+
* @type {import('webpack').LoaderDefinitionFunction}
35+
*/
36+
module.exports = function lezerLoader( source ) {
37+
const callback = this.async();
38+
this.addDependency( this.resourcePath );
39+
const isTermsImport = new URLSearchParams( this.resourceQuery ).has( 'terms' );
40+
41+
try {
42+
const { parser, terms } = buildParserFile( source, {
43+
fileName: this.resourcePath,
44+
moduleStyle: 'es',
45+
} );
46+
callback( null, isTermsImport ? terms : parser );
47+
} catch ( error ) {
48+
callback( error );
49+
}
50+
};

projects/packages/jetpack-mu-wpcom/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@
3838
"@codemirror/commands": "6.8.1",
3939
"@codemirror/lang-css": "6.3.1",
4040
"@codemirror/lang-html": "6.4.9",
41+
"@codemirror/lang-json": "6.0.2",
4142
"@codemirror/language": "6.11.2",
43+
"@codemirror/language-data": "6.5.1",
4244
"@codemirror/lint": "6.8.5",
4345
"@codemirror/search": "6.5.11",
4446
"@codemirror/state": "6.5.2",
4547
"@codemirror/view": "6.38.0",
4648
"@gravatar-com/hovercards": "0.10.8",
4749
"@gravatar-com/quick-editor": "0.8.0",
50+
"@lezer/common": "1.2.3",
4851
"@lezer/highlight": "1.2.1",
52+
"@lezer/lr": "1.4.2",
4953
"@popperjs/core": "^2.11.8",
5054
"@preact/signals": "1.2.2",
5155
"@sentry/browser": "8.33.0",
@@ -62,6 +66,7 @@
6266
"@wordpress/dom": "4.31.0",
6367
"@wordpress/dom-ready": "^4.8.1",
6468
"@wordpress/edit-post": "8.31.0",
69+
"@wordpress/editor": "14.31.0",
6570
"@wordpress/element": "6.31.0",
6671
"@wordpress/hooks": "4.31.0",
6772
"@wordpress/i18n": "6.4.0",
@@ -93,6 +98,7 @@
9398
"@babel/plugin-transform-react-jsx": "7.27.1",
9499
"@babel/preset-react": "7.27.1",
95100
"@babel/runtime": "7.28.4",
101+
"@lezer/generator": "1.8.0",
96102
"@playwright/test": "1.55.1",
97103
"@tsconfig/strictest": "2.0.5",
98104
"@types/node": "^20.4.2",

projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ public static function load_features() {
268268
require_once __DIR__ . '/features/blog-privacy/blog-privacy.php';
269269
require_once __DIR__ . '/features/cloudflare-analytics/cloudflare-analytics.php';
270270
require_once __DIR__ . '/features/code-editor/class-code-editor.php';
271+
require_once __DIR__ . '/features/wpcom-blocks/code/class-code-block.php';
271272
require_once __DIR__ . '/features/css-monkey-patches/index.php';
272273
require_once __DIR__ . '/features/error-reporting/error-reporting.php';
273274
require_once __DIR__ . '/features/first-posts-stream/first-posts-stream-helpers.php';
@@ -293,6 +294,7 @@ public static function load_features() {
293294
// Initializers, if needed.
294295
\Marketplace_Products_Updater::init();
295296
\Automattic\Jetpack\Code_Editor::setup();
297+
\Automattic\Jetpack\Code_Block::setup();
296298
\Automattic\Jetpack\Classic_Theme_Helper\Main::init();
297299
\Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::setup();
298300

0 commit comments

Comments
 (0)