Skip to content

Commit eb6f6c3

Browse files
committed
chore(docs): change path from /js/reference/ to /reference/
Update docs build script to reflect this, and fix some mdx generation errors Add .gitignore to docs/reference/ to keep generated md/mdx out of version control Add Docusaurus redirect config for /reference/js/ -> /reference/
1 parent 50591e0 commit eb6f6c3

52 files changed

Lines changed: 211 additions & 21246 deletions

Some content is hidden

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

packages/blockly/scripts/gulpfiles/docs_tasks.mjs

Lines changed: 27 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as gulp from 'gulp';
55
import replace from 'gulp-replace';
66
import rename from 'gulp-rename';
77

8-
const DOCS_DIR = 'docs/docs/reference/js';
9-
const REFERENCE_SIDEBAR_DIR = 'docs/docs/reference';
8+
const DOCS_DIR = '../docs/docs/reference';
9+
const REFERENCE_SIDEBAR_DIR = DOCS_DIR;
1010

1111
/**
1212
* Run API Extractor to generate the intermediate json file.
@@ -31,9 +31,7 @@ const removeRenames = function() {
3131
*/
3232
const generateDocs = function(done) {
3333
if (!fs.existsSync(DOCS_DIR)) {
34-
// Create the directory if it doesn't exist.
35-
// If it already exists, the contents will be deleted by api-documenter.
36-
fs.mkdirSync(DOCS_DIR);
34+
fs.mkdirSync(DOCS_DIR, {recursive: true});
3735
}
3836
execSync(
3937
`api-documenter markdown --input-folder temp --output-folder ${DOCS_DIR}`,
@@ -237,83 +235,35 @@ const fixMdxIssues = function(done) {
237235
const filePath = path.join(DOCS_DIR, file);
238236
let content = fs.readFileSync(filePath, 'utf8');
239237

240-
// Split content into lines for line-by-line processing
241238
const lines = content.split('\n');
242239
let inCodeBlock = false;
243-
let inTableCell = false;
244240

245241
for (let i = 0; i < lines.length; i++) {
246-
const line = lines[i];
247-
248-
// Track code blocks
249-
if (line.trim().startsWith('```')) {
242+
if (lines[i].trim().startsWith('```')) {
250243
inCodeBlock = !inCodeBlock;
251244
continue;
252245
}
253-
254-
// Skip processing inside code blocks
255246
if (inCodeBlock) continue;
256247

257-
// Track if we're entering a table cell (opening tag without closing on same line)
258-
if (line.includes('<td>') && !line.includes('</td>')) {
259-
inTableCell = true;
260-
}
261-
262-
// Remove empty MDX comments
263-
lines[i] = lines[i].replace(/\{\/\*\s*\*\/\}/g, '');
248+
// Remove all MDX comments (artifacts from HTML comment conversion)
249+
lines[i] = lines[i].replace(/\{\/\*[\s\S]*?\*\/\}/g, '');
264250

265251
// Remove unnecessary markdown escapes for underscores and brackets
266-
// These are not needed in MDX and can cause display issues
267252
lines[i] = lines[i].replace(/\\_/g, '_');
268253
lines[i] = lines[i].replace(/\\\[/g, '[');
269254
lines[i] = lines[i].replace(/\\\]/g, ']');
270255

271-
// Escape standalone HTML tags (not in tables or code)
272-
if (!lines[i].includes('<table>') && !lines[i].includes('</table>') &&
273-
!lines[i].includes('<thead>') && !lines[i].includes('<tbody>') &&
274-
!lines[i].includes('<tr>') && !lines[i].includes('<th>') && !lines[i].includes('<td>')) {
275-
lines[i] = lines[i].replace(/<([a-z]+)>/g, '`<$1>`');
256+
// Escape HTML tags (with or without attributes) outside of table markup
257+
const isTableMarkup = /^<\/?(table|thead|tbody|tr|th|td)[\s>]/.test(lines[i].trim());
258+
if (!isTableMarkup) {
259+
lines[i] = lines[i].replace(/<([a-z]+)(\s[^>]*)?>/g, '`$&`');
260+
lines[i] = lines[i].replace(/<\/([a-z]+)>/g, '`$&`');
276261
}
277262

278-
// Handle curly braces ANYWHERE (in tables or outside)
279-
// If the line has curly braces with type-like content, wrap in backticks
280-
const trimmed = lines[i].trim();
281-
if (trimmed && (trimmed.includes('{') || trimmed.includes('\\{')) &&
282-
(trimmed.includes('}') || trimmed.includes('\\}'))) {
283-
284-
// Skip if it's an MDX comment, table/code tag line, or already in backticks
285-
if (trimmed.includes('{/*') || trimmed.includes('*/}') ||
286-
trimmed.includes('<td>') || trimmed.includes('</td>') ||
287-
trimmed.includes('<table>') || trimmed.includes('<tr>') ||
288-
trimmed.startsWith('```') || trimmed.startsWith('`') && trimmed.endsWith('`')) {
289-
// Process table cell content specifically
290-
if (inTableCell && !lines[i].includes('<td>') && !lines[i].includes('</td>')) {
291-
// Remove any existing escaping first
292-
let cleaned = trimmed.replace(/\\\{/g, '{').replace(/\\\}/g, '}');
293-
// Only remove trailing semicolons for nested object type patterns
294-
if (cleaned.match(/\{\s*\[.*\]:\s*\{.*\};\s*\}/)) {
295-
cleaned = cleaned.replace(/;\s*}/g, ' }');
296-
}
297-
if (!cleaned.startsWith('`') || !cleaned.endsWith('`')) {
298-
lines[i] = lines[i].replace(trimmed, '`' + cleaned + '`');
299-
}
300-
}
301-
} else {
302-
// Not in a tag line - wrap curly brace content in backticks
303-
let cleaned = trimmed.replace(/\\\{/g, '{').replace(/\\\}/g, '}');
304-
// Remove trailing semicolons for type patterns
305-
if (cleaned.match(/\{\s*\[.*\]:\s*\{.*\};\s*\}/)) {
306-
cleaned = cleaned.replace(/;\s*}/g, ' }');
307-
}
308-
// Wrap in backticks
309-
lines[i] = lines[i].replace(trimmed, '`' + cleaned + '`');
310-
}
311-
}
312-
313-
// Track if we're exiting a table cell (must be after processing)
314-
if (line.includes('</td>')) {
315-
inTableCell = false;
316-
}
263+
// Escape curly braces so MDX doesn't parse them as JSX expressions.
264+
// First undo any backslash-escaping from api-documenter, then re-escape.
265+
lines[i] = lines[i].replace(/\\\{/g, '{').replace(/\\\}/g, '}');
266+
lines[i] = lines[i].replace(/\{/g, '\\{').replace(/\}/g, '\\}');
317267
}
318268

319269
content = lines.join('\n');
@@ -329,8 +279,8 @@ const convertToMdx = function() {
329279
.pipe(replace(/<!--\s*([\s\S]*?)\s*-->/g, '{/* $1 */}'))
330280
// Fix malformed markdown links: [text][/path](https://developers.google.com/path) -> [text](/path)
331281
.pipe(replace(/\[([^\]]+)\]\[([^\]]+)\]\(https:\/\/developers\.google\.com([^)]+)\)/g, '[$1]($2)'))
332-
// Fix all internal links: remove .md extension and convert ./filename to /reference/js/filename
333-
.pipe(replace(/\]\(\.\/([^)]+)\.md\)/g, '](/reference/js/$1)'))
282+
// Fix all internal links: remove .md extension and convert ./filename to /reference/filename
283+
.pipe(replace(/\]\(\.\/([^)]+)\.md\)/g, '](/reference/$1)'))
334284
// Replace developers.google.com links with relative paths
335285
.pipe(replace(/https:\/\/developers\.google\.com(\/blockly\/[^)\s"']+)/g, '$1'))
336286
// Replace developers.devsite.google.com links with relative paths
@@ -342,6 +292,11 @@ const convertToMdx = function() {
342292
}))
343293
// Remove %5C (URL-encoded backslash) and literal backslash before anchor tags
344294
.pipe(replace(/(%5C|\\)(#[^)\s"']*)/g, '$2'))
295+
// Convert <code>text</code> to markdown backtick code
296+
.pipe(replace(/<code>([^<]*)<\/code>/g, '`$1`'))
297+
// Convert paragraph breaks to spaces (for table cells) and remove remaining p tags
298+
.pipe(replace(/<\/p><p>/g, ' '))
299+
.pipe(replace(/<\/?p>/g, ''))
345300
.pipe(rename({ extname: '.mdx' }))
346301
.pipe(gulp.dest(DOCS_DIR));
347302
}
@@ -428,7 +383,7 @@ const parseHtmlTables = function(fileContent) {
428383
if (!sectionName || sectionName === 'blockly package') continue;
429384

430385
// Find table rows in HTML - match links with or without ./ prefix
431-
const tableRowRegex = /<tr><td>\s*\[([^\]]+)\]\((?:\/reference\/js\/)?([^\)]+)\)/g;
386+
const tableRowRegex = /<tr><td>\s*\[([^\]]+)\]\((?:\/reference\/)?([^\)]+)\)/g;
432387
const items = [];
433388

434389
let match;
@@ -465,7 +420,7 @@ const createReferenceSidebar = function(done) {
465420
sidebarContent += ' {\n';
466421
sidebarContent += ' "type": "doc",\n';
467422
sidebarContent += ' "label": "Overview",\n';
468-
sidebarContent += ' "id": "reference/js/blockly"\n';
423+
sidebarContent += ' "id": "reference/blockly"\n';
469424
sidebarContent += ' },\n';
470425

471426
// Process each section (Classes, Interfaces, Functions, etc.)
@@ -494,7 +449,7 @@ const createReferenceSidebar = function(done) {
494449
sidebarContent += ` "label": "${itemName}",\n`;
495450
sidebarContent += ' "link": {\n';
496451
sidebarContent += ' "type": "doc",\n';
497-
sidebarContent += ` "id": "reference/js/${itemPath}"\n`;
452+
sidebarContent += ` "id": "reference/${itemPath}"\n`;
498453
sidebarContent += ' },\n';
499454
sidebarContent += ' "items": [\n';
500455

@@ -504,7 +459,7 @@ const createReferenceSidebar = function(done) {
504459
sidebarContent += ' {\n';
505460
sidebarContent += ' "type": "doc",\n';
506461
sidebarContent += ` "label": "${subPage}",\n`;
507-
sidebarContent += ` "id": "reference/js/${subPage}"\n`;
462+
sidebarContent += ` "id": "reference/${subPage}"\n`;
508463
sidebarContent += ' },\n';
509464
}
510465

@@ -520,7 +475,7 @@ const createReferenceSidebar = function(done) {
520475
sidebarContent += ' {\n';
521476
sidebarContent += ' "type": "doc",\n';
522477
sidebarContent += ` "label": "${itemName}",\n`;
523-
sidebarContent += ` "id": "reference/js/${itemPath}"\n`;
478+
sidebarContent += ` "id": "reference/${itemPath}"\n`;
524479
sidebarContent += ' },\n';
525480
}
526481
}

packages/docs/.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Autogenerated reference docs, do not check in
2-
docs/docs/reference/*
3-
2+
docs/reference/*
3+
!docs/reference/_reference.js
44
.docusaurus
5+
build/

packages/docs/README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
44

5-
65
## Installation
76

87
Run `npm install` at the root of the blockly repo, then all other commands from the `packages/docs` directory.
@@ -12,7 +11,7 @@ npm install
1211
cd packages/docs
1312
```
1413

15-
## Local Development
14+
## Local development
1615

1716
```bash
1817
npm start
@@ -28,14 +27,22 @@ npm run build
2827

2928
This command generates static content into the `build` directory and can be served using any static contents hosting service.
3029

31-
## Test your production build locally
30+
## Test your build locally
3231

3332
```bash
3433
npm run serve
3534
```
3635

37-
The build folder is now served at http://localhost:3000/.
36+
The build folder is now served at http://localhost:3000/.
37+
38+
## Generating reference docs
39+
40+
The API reference pages are auto-generated from the Blockly TypeScript source using `@microsoft/api-extractor` and `@microsoft/api-documenter`. This is a separate step from the Docusaurus build and must be run from the `packages/blockly` directory:
3841

39-
## Deployment
42+
```bash
43+
cd packages/blockly
44+
npm run build && npm run package
45+
npm run docs
46+
```
4047

41-
TODO
48+
This generates MDX files into `packages/docs/docs/reference/`. These files are gitignored, so this needs to be run locally (and / or in CI).

packages/docs/docs/codelabs/custom-renderer/understand-connection-shapes.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The outline of the block is a single [SVG path](https://developer.mozilla.org/en
1515

1616
Each sub-path is a string of [path commands](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#path_commands) that describe the appropriate shape. These commands must use relative (rather than absolute) coordinates.
1717

18-
SVG path commands can be written as strings, but Blockly provides a set of [utility functions](/reference/js/blockly.utils_namespace.svgpaths_namespace) to make writing and reading paths easier.
18+
SVG path commands can be written as strings, but Blockly provides a set of [utility functions](/reference/blockly.utils_namespace.svgpaths_namespace) to make writing and reading paths easier.
1919

2020
### `init()`
2121

packages/docs/docs/guides/configure/web/appearance/block-colour.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ see [Colour formats](/guides/configure/web/appearance/colour-formats).
5353
Note the British spelling. Failure to set the colour results in a black block.
5454

5555
You can also set the block color using the
56-
[`Block.setColour(..)`](/reference/js/blockly.block_class.setcolour_1_method)
56+
[`Block.setColour(..)`](/reference/blockly.block_class.setcolour_1_method)
5757
function, or by using [themes](/guides/configure/web/appearance/themes)
5858
and defining a block style.
5959

packages/docs/docs/guides/configure/web/appearance/colour-formats.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ toolbox categories, plus a distinct colour for dynamic variables:
7777
```
7878

7979
These string values can be used in both the JSON definitions and
80-
[`block.setColour(..)`](/reference/js/blockly.block_class.setcolour_1_method).
80+
[`block.setColour(..)`](/reference/blockly.block_class.setcolour_1_method).
8181

8282
You can add your own colour constants by adding to `Blockly.Msg`:
8383

packages/docs/docs/guides/configure/web/configuration_struct.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ directly.
3838
## Configuration options{#the-options-dictionary}
3939

4040
The configuration object implements
41-
[`Blockly.BlocklyOptions`](/reference/js/blockly.blocklyoptions_interface)
41+
[`Blockly.BlocklyOptions`](/reference/blockly.blocklyoptions_interface)
4242
and has the following options. Note that several of these options change their
4343
default value based on whether the provided toolbox has categories or not.
4444

@@ -72,8 +72,8 @@ default value based on whether the provided toolbox has categories or not.
7272
[Grid]: /guides/configure/web/grid
7373
[media]: /guides/configure/web/media
7474
[Move]: /guides/configure/web/move
75-
[setIsReadOnly]: /reference/js/blockly.workspace_class.setisreadonly_1_method
76-
[isReadOnly]: /reference/js/blockly.workspace_class.isreadonly_1_method
75+
[setIsReadOnly]: /reference/blockly.workspace_class.setisreadonly_1_method
76+
[isReadOnly]: /reference/blockly.workspace_class.isreadonly_1_method
7777
[renderer]: /guides/create-custom-blocks/renderers/create-custom-renderers/basic-implementation
7878
[RTL demo]: https://raspberrypifoundation.github.io/blockly-samples/examples/rtl-demo/
7979
[Themes]: /guides/configure/web/appearance/themes

packages/docs/docs/guides/configure/web/context-menus.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,15 @@ steps:
455455
456456
[block-default-menu-image]: /images/context-menus/block-default-menu.png
457457
[context-menu-items-source]: https://github.com/RaspberryPiFoundation/blockly/blob/main/core/contextmenu_items.ts
458-
[i-context-menu]: /reference/js/blockly.icontextmenu_interface
459-
[i-focusable-node]: /reference/js/blockly.ifocusablenode_interface
460-
[RegistryItem]: /reference/js/blockly.contextmenuregistry_namespace.registryitem_typealias
458+
[i-context-menu]: /reference/blockly.icontextmenu_interface
459+
[i-focusable-node]: /reference/blockly.ifocusablenode_interface
460+
[RegistryItem]: /reference/blockly.contextmenuregistry_namespace.registryitem_typealias
461461
[Scope]: #scope
462462
[enabled-image]: /images/context-menus/enabled-option.png
463463
[disabled-image]: /images/context-menus/disabled-option.png
464-
[customContextMenu]: /reference/js/blockly.blocksvg_class.customcontextmenu_property
465-
[configureContextMenu]: /reference/js/blockly.workspacesvg_class.configurecontextmenu_property
466-
[ContextMenuOption]: /reference/js/blockly.contextmenuregistry_namespace.contextmenuoption_typealias
467-
[LegacyContextMenuOption]: /reference/js/blockly.contextmenuregistry_namespace.legacycontextmenuoption_interface
464+
[customContextMenu]: /reference/blockly.blocksvg_class.customcontextmenu_property
465+
[configureContextMenu]: /reference/blockly.workspacesvg_class.configurecontextmenu_property
466+
[ContextMenuOption]: /reference/blockly.contextmenuregistry_namespace.contextmenuoption_typealias
467+
[LegacyContextMenuOption]: /reference/blockly.contextmenuregistry_namespace.legacycontextmenuoption_interface
468468
[coordinate-systems]: /guides/configure/web/metrics_manager#coordinate-systems
469469
[keyboard-navigation-plugin]: /guides/configure/web/keyboard-nav

packages/docs/docs/guides/configure/web/copy-paste.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ Blockly.clipboard.registry.register('MY_PASTER', new MyPaster());
153153
```
154154

155155
[implement-paster]: /guides/configure/web/copy-paste#implement-a-paster
156-
[ICopyable]: /reference/js/blockly.icopyable_interface
157-
[IDeletable]: /reference/js/blockly.ideletable_interface
158-
[IDraggable]: /reference/js/blockly.idraggable_interface
159-
[ICopyData]: /reference/js/blockly.icopyable_namespace.icopydata_interface
160-
[IPaster]: /reference/js/blockly.ipaster_interface
161-
[ISelectable]: /reference/js/blockly.iselectable_interface
156+
[ICopyable]: /reference/blockly.icopyable_interface
157+
[IDeletable]: /reference/blockly.ideletable_interface
158+
[IDraggable]: /reference/blockly.idraggable_interface
159+
[ICopyData]: /reference/blockly.icopyable_namespace.icopydata_interface
160+
[IPaster]: /reference/blockly.ipaster_interface
161+
[ISelectable]: /reference/blockly.iselectable_interface
162162
[default-keyboard-shortcuts]: /guides/configure/web/keyboard-shortcuts#default-shortcuts
163163
[context-menu-option]: /guides/configure/web/context-menus
164164
[custom-draggables]: /guides/configure/web/dragging/draggable
165165
[multiselect-plugin]: https://www.npmjs.com/package/@mit-app-inventor/blockly-plugin-workspace-multiselect
166166
[cross-tab-copy-paste-plugin]: https://www.npmjs.com/package/@blockly/plugin-cross-tab-copy-paste
167-
[clipboard-namespace]: /reference/js/blockly.clipboard_namespace
167+
[clipboard-namespace]: /reference/blockly.clipboard_namespace

packages/docs/docs/guides/configure/web/customization.mdx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ The following Blockly classes can be replaced:
3030
For information about how to replace a renderer, see [Create custom
3131
renderers](/guides/create-custom-blocks/renderers/create-custom-renderers/basic-implementation).
3232

33-
[`Blockly.dragging.Dragger`]: /reference/js/blockly.dragging_namespace.dragger_class
34-
[`Blockly.IDragger`]: /reference/js/blockly.idragger_interface
35-
[`Blockly.ConnectionChecker`]: /reference/js/blockly.connectionchecker_class
36-
[`Blockly.IConnectionChecker`]: /reference/js/blockly.iconnectionchecker_interface
37-
[`Blockly.InsertionMarkerPreviewer`]: /reference/js/blockly.insertionmarkerpreviewer_class
38-
[`Blockly.IConnectionPreviewer`]: /reference/js/blockly.iconnectionpreviewer_interface
39-
[`Blockly.HorizontalFlyout`]: /reference/js/blockly.horizontalflyout_class
40-
[`Blockly.VerticalFlyout`]: /reference/js/blockly.verticalflyout_class
41-
[`Blockly.IFlyout`]: /reference/js/blockly.iflyout_interface
42-
[`Blockly.MetricsManager`]: /reference/js/blockly.metricsmanager_class
43-
[`Blockly.IMetricsManager`]: /reference/js/blockly.imetricsmanager_interface
44-
[`Blockly.Toolbox`]: /reference/js/blockly.toolbox_class
45-
[`Blockly.IToolbox`]: /reference/js/blockly.itoolbox_interface
46-
[`Blockly.VariableMap`]: /reference/js/blockly.variablemap_class
47-
[`Blockly.IVariableMap`]: /reference/js/blockly.ivariablemap_interface
48-
[`Blockly.VariableModel`]: /reference/js/blockly.variablemodel_class
49-
[`Blockly.IVariableModel`]: /reference/js/blockly.ivariablemodel_interface
33+
[`Blockly.dragging.Dragger`]: /reference/blockly.dragging_namespace.dragger_class
34+
[`Blockly.IDragger`]: /reference/blockly.idragger_interface
35+
[`Blockly.ConnectionChecker`]: /reference/blockly.connectionchecker_class
36+
[`Blockly.IConnectionChecker`]: /reference/blockly.iconnectionchecker_interface
37+
[`Blockly.InsertionMarkerPreviewer`]: /reference/blockly.insertionmarkerpreviewer_class
38+
[`Blockly.IConnectionPreviewer`]: /reference/blockly.iconnectionpreviewer_interface
39+
[`Blockly.HorizontalFlyout`]: /reference/blockly.horizontalflyout_class
40+
[`Blockly.VerticalFlyout`]: /reference/blockly.verticalflyout_class
41+
[`Blockly.IFlyout`]: /reference/blockly.iflyout_interface
42+
[`Blockly.MetricsManager`]: /reference/blockly.metricsmanager_class
43+
[`Blockly.IMetricsManager`]: /reference/blockly.imetricsmanager_interface
44+
[`Blockly.Toolbox`]: /reference/blockly.toolbox_class
45+
[`Blockly.IToolbox`]: /reference/blockly.itoolbox_interface
46+
[`Blockly.VariableMap`]: /reference/blockly.variablemap_class
47+
[`Blockly.IVariableMap`]: /reference/blockly.ivariablemap_interface
48+
[`Blockly.VariableModel`]: /reference/blockly.variablemodel_class
49+
[`Blockly.IVariableModel`]: /reference/blockly.ivariablemodel_interface
5050

5151
## Create a replacement class
5252

0 commit comments

Comments
 (0)