@open-press/cli 0.8.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -23
- package/dist/cli.js +320 -252
- package/package.json +9 -8
- package/template/core/AGENTS.md +0 -126
- package/template/core/CHANGELOG.md +0 -215
- package/template/core/README.md +0 -40
- package/template/core/engine/cli.mjs +0 -96
- package/template/core/engine/commands/_shared.mjs +0 -177
- package/template/core/engine/commands/deploy.mjs +0 -31
- package/template/core/engine/commands/dev.mjs +0 -49
- package/template/core/engine/commands/doctor.mjs +0 -229
- package/template/core/engine/commands/export.mjs +0 -8
- package/template/core/engine/commands/init.mjs +0 -24
- package/template/core/engine/commands/inspect.mjs +0 -35
- package/template/core/engine/commands/pdf.mjs +0 -26
- package/template/core/engine/commands/preview.mjs +0 -26
- package/template/core/engine/commands/render.mjs +0 -17
- package/template/core/engine/commands/replace.mjs +0 -41
- package/template/core/engine/commands/search.mjs +0 -33
- package/template/core/engine/commands/typecheck.mjs +0 -5
- package/template/core/engine/commands/upgrade.mjs +0 -159
- package/template/core/engine/commands/validate.mjs +0 -17
- package/template/core/engine/document-export.mjs +0 -15
- package/template/core/engine/init.mjs +0 -90
- package/template/core/engine/output/chrome-pdf.d.mts +0 -34
- package/template/core/engine/output/chrome-pdf.mjs +0 -358
- package/template/core/engine/output/deploy-sync.mjs +0 -15
- package/template/core/engine/output/fonts.mjs +0 -62
- package/template/core/engine/output/katex-assets.mjs +0 -45
- package/template/core/engine/output/page-block.mjs +0 -30
- package/template/core/engine/output/pdf-media.mjs +0 -45
- package/template/core/engine/output/public-assets.mjs +0 -19
- package/template/core/engine/output/static-server.mjs +0 -532
- package/template/core/engine/react/caption-numbering.mjs +0 -73
- package/template/core/engine/react/comment-endpoint.d.mts +0 -11
- package/template/core/engine/react/comment-endpoint.mjs +0 -102
- package/template/core/engine/react/comment-marker.mjs +0 -374
- package/template/core/engine/react/document-entry.mjs +0 -324
- package/template/core/engine/react/document-export.mjs +0 -373
- package/template/core/engine/react/http-json.mjs +0 -24
- package/template/core/engine/react/mdx-compile.mjs +0 -599
- package/template/core/engine/react/measurement-css.mjs +0 -136
- package/template/core/engine/react/object-entities.mjs +0 -119
- package/template/core/engine/react/pagination/allocator.mjs +0 -122
- package/template/core/engine/react/pagination/regions.mjs +0 -81
- package/template/core/engine/react/pagination-constants.mjs +0 -3
- package/template/core/engine/react/pagination.mjs +0 -9
- package/template/core/engine/react/pipeline/allocate.mjs +0 -251
- package/template/core/engine/react/pipeline/final-render.mjs +0 -94
- package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -302
- package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
- package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
- package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
- package/template/core/engine/react/section-css.mjs +0 -56
- package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
- package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
- package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
- package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
- package/template/core/engine/react/style-discovery.mjs +0 -142
- package/template/core/engine/runtime/config.d.mts +0 -40
- package/template/core/engine/runtime/config.mjs +0 -175
- package/template/core/engine/runtime/file-utils.mjs +0 -106
- package/template/core/engine/runtime/file-walk.mjs +0 -22
- package/template/core/engine/runtime/inspection.mjs +0 -328
- package/template/core/engine/runtime/issue-report.mjs +0 -44
- package/template/core/engine/runtime/path-utils.mjs +0 -20
- package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
- package/template/core/engine/runtime/source-text-tools.mjs +0 -832
- package/template/core/engine/runtime/source-workspace.mjs +0 -159
- package/template/core/engine/runtime/validation.mjs +0 -174
- package/template/core/index.html +0 -13
- package/template/core/openpress.config.mjs +0 -12
- package/template/core/package.json +0 -91
- package/template/core/src/main.tsx +0 -16
- package/template/core/src/openpress/app/OpenPressApp.tsx +0 -140
- package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -94
- package/template/core/src/openpress/app/index.ts +0 -2
- package/template/core/src/openpress/core/Frame.tsx +0 -78
- package/template/core/src/openpress/core/FrameContext.tsx +0 -24
- package/template/core/src/openpress/core/MdxArea.tsx +0 -34
- package/template/core/src/openpress/core/Press.tsx +0 -34
- package/template/core/src/openpress/core/cn.ts +0 -4
- package/template/core/src/openpress/core/index.tsx +0 -40
- package/template/core/src/openpress/core/primitives.tsx +0 -44
- package/template/core/src/openpress/core/types.ts +0 -191
- package/template/core/src/openpress/core/useSource.ts +0 -28
- package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
- package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
- package/template/core/src/openpress/document-model/documentTypes.ts +0 -138
- package/template/core/src/openpress/document-model/index.ts +0 -6
- package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -51
- package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
- package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
- package/template/core/src/openpress/manuscript/index.tsx +0 -238
- package/template/core/src/openpress/mdx/index.ts +0 -88
- package/template/core/src/openpress/numbering/index.ts +0 -294
- package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
- package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
- package/template/core/src/openpress/reader/index.ts +0 -10
- package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
- package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
- package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
- package/template/core/src/openpress/reader/readerScroll.ts +0 -92
- package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
- package/template/core/src/openpress/reader/readerTypes.ts +0 -4
- package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
- package/template/core/src/openpress/reader/usePanelState.ts +0 -56
- package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
- package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
- package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
- package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
- package/template/core/src/openpress/shared/Panel.tsx +0 -77
- package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
- package/template/core/src/openpress/shared/index.ts +0 -4
- package/template/core/src/openpress/shared/numberUtils.ts +0 -3
- package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
- package/template/core/src/openpress/workbench/Workbench.tsx +0 -407
- package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
- package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
- package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
- package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
- package/template/core/src/openpress/workbench/actions/index.ts +0 -5
- package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
- package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
- package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
- package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
- package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
- package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
- package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
- package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
- package/template/core/src/openpress/workbench/document/index.ts +0 -10
- package/template/core/src/openpress/workbench/index.ts +0 -2
- package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
- package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
- package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
- package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
- package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
- package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -248
- package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
- package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
- package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
- package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
- package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -76
- package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
- package/template/core/src/openpress/workbench/panels/index.ts +0 -3
- package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -523
- package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
- package/template/core/src/openpress/workbench/project/index.ts +0 -2
- package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
- package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
- package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
- package/template/core/src/openpress/workbench/shell/index.ts +0 -1
- package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
- package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
- package/template/core/src/styles/openpress/app-shell.css +0 -251
- package/template/core/src/styles/openpress/media-workspace.css +0 -230
- package/template/core/src/styles/openpress/print-route.css +0 -184
- package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
- package/template/core/src/styles/openpress/public-viewer.css +0 -688
- package/template/core/src/styles/openpress/reader-runtime.css +0 -980
- package/template/core/src/styles/openpress/responsive.css +0 -245
- package/template/core/src/styles/openpress/workbench-panels.css +0 -594
- package/template/core/src/styles/openpress/workbench.css +0 -1255
- package/template/core/src/styles/openpress.css +0 -14
- package/template/core/src/vite-env.d.ts +0 -9
- package/template/core/tsconfig.json +0 -40
- package/template/core/vite.config.ts +0 -584
- package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +0 -35
- package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +0 -50
- package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +0 -47
- package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +0 -26
- package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +0 -32
- package/template/packs/academic-paper/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/academic-paper/document/components/Page.tsx +0 -60
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/academic-paper/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/academic-paper/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/academic-paper/document/design.md +0 -279
- package/template/packs/academic-paper/document/index.tsx +0 -123
- package/template/packs/academic-paper/document/media/README.md +0 -13
- package/template/packs/academic-paper/document/media/figure-placeholder.svg +0 -9
- package/template/packs/academic-paper/document/openpress.config.mjs +0 -26
- package/template/packs/academic-paper/document/theme/README.md +0 -11
- package/template/packs/academic-paper/document/theme/base/page-contract.css +0 -522
- package/template/packs/academic-paper/document/theme/base/print.css +0 -93
- package/template/packs/academic-paper/document/theme/base/typography.css +0 -333
- package/template/packs/academic-paper/document/theme/fonts.css +0 -3
- package/template/packs/academic-paper/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/academic-paper/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +0 -294
- package/template/packs/academic-paper/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/academic-paper/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/academic-paper/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/academic-paper/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/academic-paper/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/academic-paper/document/theme/tokens.css +0 -80
- package/template/packs/academic-paper/openpress.config.mjs +0 -5
- package/template/packs/claude-document/document/chapters/01-document-shape/content/01-document-shape.mdx +0 -51
- package/template/packs/claude-document/document/chapters/02-review-loop/content/01-review-loop.mdx +0 -31
- package/template/packs/claude-document/document/components/ChapterOpenerVisual.tsx +0 -96
- package/template/packs/claude-document/document/components/Page.tsx +0 -37
- package/template/packs/claude-document/document/design.md +0 -142
- package/template/packs/claude-document/document/index.tsx +0 -94
- package/template/packs/claude-document/document/media/README.md +0 -13
- package/template/packs/claude-document/document/openpress.config.mjs +0 -26
- package/template/packs/claude-document/document/theme/README.md +0 -15
- package/template/packs/claude-document/document/theme/base/page-contract.css +0 -525
- package/template/packs/claude-document/document/theme/base/print.css +0 -93
- package/template/packs/claude-document/document/theme/base/typography.css +0 -612
- package/template/packs/claude-document/document/theme/fonts.css +0 -4
- package/template/packs/claude-document/document/theme/page-surfaces/back-cover.css +0 -72
- package/template/packs/claude-document/document/theme/page-surfaces/chapter-opener.css +0 -236
- package/template/packs/claude-document/document/theme/page-surfaces/cover.css +0 -309
- package/template/packs/claude-document/document/theme/page-surfaces/toc.css +0 -225
- package/template/packs/claude-document/document/theme/patterns/_chart-frame.css +0 -53
- package/template/packs/claude-document/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/claude-document/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/claude-document/document/theme/shell/reader-controls.css +0 -789
- package/template/packs/claude-document/document/theme/tokens.css +0 -89
- package/template/packs/claude-document/openpress.config.mjs +0 -5
- package/template/packs/editorial-monograph/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +0 -31
- package/template/packs/editorial-monograph/document/chapters/02-workflow/content/01-workflow.mdx +0 -89
- package/template/packs/editorial-monograph/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +0 -51
- package/template/packs/editorial-monograph/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +0 -39
- package/template/packs/editorial-monograph/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/editorial-monograph/document/components/Page.tsx +0 -37
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/editorial-monograph/document/design.md +0 -279
- package/template/packs/editorial-monograph/document/index.tsx +0 -97
- package/template/packs/editorial-monograph/document/media/README.md +0 -13
- package/template/packs/editorial-monograph/document/openpress.config.mjs +0 -26
- package/template/packs/editorial-monograph/document/theme/README.md +0 -11
- package/template/packs/editorial-monograph/document/theme/base/page-contract.css +0 -505
- package/template/packs/editorial-monograph/document/theme/base/print.css +0 -93
- package/template/packs/editorial-monograph/document/theme/base/typography.css +0 -336
- package/template/packs/editorial-monograph/document/theme/fonts.css +0 -3
- package/template/packs/editorial-monograph/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/editorial-monograph/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/editorial-monograph/document/theme/page-surfaces/cover.css +0 -147
- package/template/packs/editorial-monograph/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/editorial-monograph/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/editorial-monograph/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/editorial-monograph/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/editorial-monograph/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/editorial-monograph/document/theme/tokens.css +0 -80
- package/template/packs/editorial-monograph/openpress.config.mjs +0 -5
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const DEFAULT_MAX_BODY_BYTES = 64 * 1024;
|
|
2
|
-
|
|
3
|
-
export async function readJsonBody(req, {
|
|
4
|
-
maxBytes = DEFAULT_MAX_BODY_BYTES,
|
|
5
|
-
bodyLabel = "Request",
|
|
6
|
-
} = {}) {
|
|
7
|
-
let body = "";
|
|
8
|
-
for await (const chunk of req) {
|
|
9
|
-
body += String(chunk);
|
|
10
|
-
if (Buffer.byteLength(body, "utf8") > maxBytes) {
|
|
11
|
-
throw new Error(`${bodyLabel} body is too large.`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
return JSON.parse(body || "{}");
|
|
16
|
-
} catch {
|
|
17
|
-
throw new Error(`${bodyLabel} body must be valid JSON.`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function writeJson(res, status, body) {
|
|
22
|
-
res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
|
|
23
|
-
res.end(`${JSON.stringify(body, null, 2)}\n`);
|
|
24
|
-
}
|
|
@@ -1,599 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
|
-
import { evaluate } from "@mdx-js/mdx";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import * as jsxRuntime from "react/jsx-runtime";
|
|
6
|
-
import rehypeKatex from "rehype-katex";
|
|
7
|
-
import remarkGfm from "remark-gfm";
|
|
8
|
-
import remarkMath from "remark-math";
|
|
9
|
-
|
|
10
|
-
const PAGINABLE_TAGS = new Set([
|
|
11
|
-
"p",
|
|
12
|
-
"h1",
|
|
13
|
-
"h2",
|
|
14
|
-
"h3",
|
|
15
|
-
"h4",
|
|
16
|
-
"h5",
|
|
17
|
-
"h6",
|
|
18
|
-
"ul",
|
|
19
|
-
"ol",
|
|
20
|
-
"pre",
|
|
21
|
-
"blockquote",
|
|
22
|
-
"figure",
|
|
23
|
-
"table",
|
|
24
|
-
]);
|
|
25
|
-
const TABLE_CAPTION_COMPONENT_NAME = "TableCaption";
|
|
26
|
-
const LEGACY_TABLE_CAPTION_MARKER_RE = /^\s*表\s*(?:[\d一二三四五六七八九十百千〇零]+(?:[--..][\d一二三四五六七八九十百千〇零]+)?)?\s*[::、..]\s*(.+?)\s*$/u;
|
|
27
|
-
|
|
28
|
-
export async function compileMdx({
|
|
29
|
-
source,
|
|
30
|
-
filePath,
|
|
31
|
-
components = {},
|
|
32
|
-
chapterSlug = "document",
|
|
33
|
-
includeBlockIds = null,
|
|
34
|
-
blockAttributes = null,
|
|
35
|
-
} = {}) {
|
|
36
|
-
if (typeof source !== "string") throw new Error("compileMdx requires a string `source`.");
|
|
37
|
-
if (typeof filePath !== "string" || !filePath.trim()) throw new Error("compileMdx requires `filePath`.");
|
|
38
|
-
assertNoImports(source, filePath);
|
|
39
|
-
const mdxSource = normalizeSingleLineDisplayMath(source);
|
|
40
|
-
|
|
41
|
-
const blocks = [];
|
|
42
|
-
const remarkPlugins = [[remarkMath, { singleDollarTextMath: true }], remarkGfm, [remarkBlockOnlyMdx, { filePath }]];
|
|
43
|
-
const rehypePlugins = [rehypeKatex, rehypeTableCaptions, [rehypeBlockIds, { blocks, filePath, chapterSlug, includeBlockIds, blockAttributes }]];
|
|
44
|
-
const mod = await evaluate(mdxSource, {
|
|
45
|
-
...jsxRuntime,
|
|
46
|
-
baseUrl: pathToFileURL(filePath).href,
|
|
47
|
-
remarkPlugins,
|
|
48
|
-
rehypePlugins,
|
|
49
|
-
});
|
|
50
|
-
const MdxContent = mod.default;
|
|
51
|
-
const mdxComponents = wrapMdxComponents(components);
|
|
52
|
-
|
|
53
|
-
function MdxContentWrapper(props = {}) {
|
|
54
|
-
return React.createElement(MdxContent, {
|
|
55
|
-
...props,
|
|
56
|
-
components: {
|
|
57
|
-
...mdxComponents,
|
|
58
|
-
...(props.components ?? {}),
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
Content: MdxContentWrapper,
|
|
65
|
-
blocks,
|
|
66
|
-
exports: mod,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function rehypeTableCaptions() {
|
|
71
|
-
return (tree) => {
|
|
72
|
-
normalizeTableCaptions(tree);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function rehypeBlockIds(options = {}) {
|
|
77
|
-
const blocks = Array.isArray(options.blocks) ? options.blocks : [];
|
|
78
|
-
const filePath = String(options.filePath ?? "document.mdx");
|
|
79
|
-
const chapterSlug = slugPart(options.chapterSlug ?? "document");
|
|
80
|
-
const sourceSlug = slugPart(path.basename(filePath, path.extname(filePath)));
|
|
81
|
-
const includeBlockIds = Array.isArray(options.includeBlockIds) ? new Set(options.includeBlockIds) : null;
|
|
82
|
-
const blockAttributes = normalizeBlockAttributes(options.blockAttributes);
|
|
83
|
-
let counter = 0;
|
|
84
|
-
|
|
85
|
-
return (tree) => {
|
|
86
|
-
filterTree(tree, (node) => {
|
|
87
|
-
const block = blockInfo(node);
|
|
88
|
-
if (!block) return true;
|
|
89
|
-
|
|
90
|
-
const id = `b-${chapterSlug}-${sourceSlug}-${counter}`;
|
|
91
|
-
counter += 1;
|
|
92
|
-
if (block.name === "table") {
|
|
93
|
-
return applyTableRowBlocks({
|
|
94
|
-
node,
|
|
95
|
-
id,
|
|
96
|
-
blocks,
|
|
97
|
-
filePath,
|
|
98
|
-
chapterSlug,
|
|
99
|
-
includeBlockIds,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (block.name === "ul" || block.name === "ol") {
|
|
103
|
-
return applyListItemBlocks({
|
|
104
|
-
node,
|
|
105
|
-
id,
|
|
106
|
-
blocks,
|
|
107
|
-
filePath,
|
|
108
|
-
chapterSlug,
|
|
109
|
-
includeBlockIds,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (includeBlockIds && !includeBlockIds.has(id)) return false;
|
|
113
|
-
|
|
114
|
-
setDataAttribute(node, "data-openpress-block-id", id);
|
|
115
|
-
setDataAttribute(node, "data-openpress-object-id", createBlockObjectEntityId(id));
|
|
116
|
-
const extraAttributes = blockAttributes.get(id);
|
|
117
|
-
if (extraAttributes) {
|
|
118
|
-
for (const [name, value] of Object.entries(extraAttributes)) {
|
|
119
|
-
if (value == null || value === "") continue;
|
|
120
|
-
setDataAttribute(node, name, String(value));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
blocks.push({
|
|
124
|
-
id,
|
|
125
|
-
kind: block.kind,
|
|
126
|
-
name: block.name,
|
|
127
|
-
text: block.text,
|
|
128
|
-
filePath,
|
|
129
|
-
chapterSlug,
|
|
130
|
-
source: sourcePosition(node.position),
|
|
131
|
-
});
|
|
132
|
-
return "skip";
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function applyTableRowBlocks({
|
|
138
|
-
node,
|
|
139
|
-
id,
|
|
140
|
-
blocks,
|
|
141
|
-
filePath,
|
|
142
|
-
chapterSlug,
|
|
143
|
-
includeBlockIds,
|
|
144
|
-
}) {
|
|
145
|
-
const rows = tableBodyRows(node);
|
|
146
|
-
const header = tableHeaderRow(node);
|
|
147
|
-
const caption = tableCaption(node);
|
|
148
|
-
const captionRecord = caption ? { id: `${id}-caption`, node: caption } : null;
|
|
149
|
-
const headerRecord = header ? { id: `${id}-h0`, node: header } : null;
|
|
150
|
-
const selectedCaption = captionRecord && (!includeBlockIds || includeBlockIds.has(captionRecord.id));
|
|
151
|
-
const selectedHeader = headerRecord && (!includeBlockIds || includeBlockIds.has(headerRecord.id));
|
|
152
|
-
const firstSelectedRowIndex = selectedFirstTableRowIndex(rows, includeBlockIds, id);
|
|
153
|
-
const renderCaption = selectedCaption || (captionRecord && includeBlockIds && firstSelectedRowIndex === 0);
|
|
154
|
-
const renderHeader = Boolean(headerRecord && (!includeBlockIds || firstSelectedRowIndex === 0 || selectedHeader));
|
|
155
|
-
if (rows.length === 0) {
|
|
156
|
-
if (includeBlockIds && !includeBlockIds.has(id)) return false;
|
|
157
|
-
setDataAttribute(node, "data-openpress-block-id", id);
|
|
158
|
-
setDataAttribute(node, "data-openpress-object-id", createBlockObjectEntityId(id));
|
|
159
|
-
blocks.push({
|
|
160
|
-
id,
|
|
161
|
-
kind: "element",
|
|
162
|
-
name: "table",
|
|
163
|
-
text: textContent(node).trim() || undefined,
|
|
164
|
-
filePath,
|
|
165
|
-
chapterSlug,
|
|
166
|
-
source: sourcePosition(node.position),
|
|
167
|
-
});
|
|
168
|
-
return "skip";
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const rowRecords = rows.map((row, index) => ({
|
|
172
|
-
id: `${id}-r${index}`,
|
|
173
|
-
node: row,
|
|
174
|
-
index,
|
|
175
|
-
}));
|
|
176
|
-
const selected = includeBlockIds
|
|
177
|
-
? rowRecords.filter((row) => includeBlockIds.has(row.id))
|
|
178
|
-
: rowRecords;
|
|
179
|
-
if (selected.length === 0 && !selectedCaption && !selectedHeader) return false;
|
|
180
|
-
|
|
181
|
-
setDataAttribute(node, "data-openpress-table-id", id);
|
|
182
|
-
if (headerRecord && renderHeader) {
|
|
183
|
-
setDataAttribute(headerRecord.node, "data-openpress-block-id", headerRecord.id);
|
|
184
|
-
setDataAttribute(headerRecord.node, "data-openpress-object-id", createBlockObjectEntityId(headerRecord.id));
|
|
185
|
-
setDataAttribute(headerRecord.node, "data-openpress-block-layout", "attached");
|
|
186
|
-
}
|
|
187
|
-
if (captionRecord) {
|
|
188
|
-
if (renderCaption) {
|
|
189
|
-
setDataAttribute(captionRecord.node, "data-openpress-block-id", captionRecord.id);
|
|
190
|
-
setDataAttribute(captionRecord.node, "data-openpress-object-id", createBlockObjectEntityId(captionRecord.id));
|
|
191
|
-
if (selectedCaption) {
|
|
192
|
-
blocks.push({
|
|
193
|
-
id: captionRecord.id,
|
|
194
|
-
kind: "element",
|
|
195
|
-
name: "caption",
|
|
196
|
-
text: textContent(captionRecord.node).trim() || undefined,
|
|
197
|
-
filePath,
|
|
198
|
-
chapterSlug,
|
|
199
|
-
tableId: id,
|
|
200
|
-
layout: "attached",
|
|
201
|
-
source: sourcePosition(captionRecord.node.position ?? node.position),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
removeTableCaption(node);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (headerRecord && selectedHeader) {
|
|
209
|
-
blocks.push({
|
|
210
|
-
id: headerRecord.id,
|
|
211
|
-
kind: "table-row",
|
|
212
|
-
name: "table-header-row",
|
|
213
|
-
text: textContent(headerRecord.node).trim() || undefined,
|
|
214
|
-
filePath,
|
|
215
|
-
chapterSlug,
|
|
216
|
-
tableId: id,
|
|
217
|
-
rowIndex: -1,
|
|
218
|
-
layout: "attached",
|
|
219
|
-
source: sourcePosition(headerRecord.node.position ?? node.position),
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
const selectedNodes = new Set(selected.map((row) => row.node));
|
|
223
|
-
pruneUnselectedTableRows(node, new Set(rowRecords.map((row) => row.node)), selectedNodes);
|
|
224
|
-
if (!renderHeader) stripTableHeader(node);
|
|
225
|
-
|
|
226
|
-
for (const row of selected) {
|
|
227
|
-
setDataAttribute(row.node, "data-openpress-block-id", row.id);
|
|
228
|
-
setDataAttribute(row.node, "data-openpress-object-id", createBlockObjectEntityId(row.id));
|
|
229
|
-
blocks.push({
|
|
230
|
-
id: row.id,
|
|
231
|
-
kind: "table-row",
|
|
232
|
-
name: "table-row",
|
|
233
|
-
text: textContent(row.node).trim() || undefined,
|
|
234
|
-
filePath,
|
|
235
|
-
chapterSlug,
|
|
236
|
-
tableId: id,
|
|
237
|
-
rowIndex: row.index,
|
|
238
|
-
source: sourcePosition(row.node.position ?? node.position),
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return "skip";
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function remarkBlockOnlyMdx(options = {}) {
|
|
245
|
-
const filePath = String(options.filePath ?? "document.mdx");
|
|
246
|
-
|
|
247
|
-
return (tree) => {
|
|
248
|
-
visit(tree, (node) => {
|
|
249
|
-
if (node?.type !== "mdxJsxTextElement") return;
|
|
250
|
-
const position = node.position?.start;
|
|
251
|
-
const suffix = position ? `:${position.line}:${position.column}` : "";
|
|
252
|
-
throw new Error(`MDX JSX components must be block-only in OpenPress chapter prose: ${filePath}${suffix}`);
|
|
253
|
-
});
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function normalizeTableCaptions(node) {
|
|
258
|
-
if (!Array.isArray(node?.children)) return;
|
|
259
|
-
|
|
260
|
-
for (let index = 0; index < node.children.length; index += 1) {
|
|
261
|
-
const child = node.children[index];
|
|
262
|
-
normalizeTableCaptions(child);
|
|
263
|
-
|
|
264
|
-
const legacyCaptionText = legacyTableCaptionText(child);
|
|
265
|
-
if (legacyCaptionText) {
|
|
266
|
-
throw new Error(`Legacy table caption markers are not supported. Use <TableCaption>${legacyCaptionText}</TableCaption> before the table.`);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const captionText = tableCaptionText(child);
|
|
270
|
-
if (!captionText) continue;
|
|
271
|
-
|
|
272
|
-
const tableIndex = nextElementIndex(node.children, index + 1);
|
|
273
|
-
const table = tableIndex === -1 ? null : node.children[tableIndex];
|
|
274
|
-
if (!table || table.type !== "element" || table.tagName !== "table") {
|
|
275
|
-
throw new Error(`<${TABLE_CAPTION_COMPONENT_NAME}> must appear immediately before a Markdown table.`);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (!table.children?.some((item) => item.type === "element" && item.tagName === "caption")) {
|
|
279
|
-
table.children ??= [];
|
|
280
|
-
table.children.unshift({
|
|
281
|
-
type: "element",
|
|
282
|
-
tagName: "caption",
|
|
283
|
-
properties: {},
|
|
284
|
-
position: child.position,
|
|
285
|
-
children: [{ type: "text", value: captionText }],
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
node.children.splice(index, tableIndex - index);
|
|
290
|
-
index -= 1;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function legacyTableCaptionText(node) {
|
|
295
|
-
if (node?.type !== "element" || node.tagName !== "p") return "";
|
|
296
|
-
const match = textContent(node).match(LEGACY_TABLE_CAPTION_MARKER_RE);
|
|
297
|
-
return match?.[1]?.trim() ?? "";
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function tableCaptionText(node) {
|
|
301
|
-
if (node?.type !== "mdxJsxFlowElement" || node.name !== TABLE_CAPTION_COMPONENT_NAME) return "";
|
|
302
|
-
const caption = textContent(node).trim();
|
|
303
|
-
if (!caption) throw new Error(`<${TABLE_CAPTION_COMPONENT_NAME}> requires caption text.`);
|
|
304
|
-
return caption;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function nextElementIndex(children, start) {
|
|
308
|
-
for (let index = start; index < children.length; index += 1) {
|
|
309
|
-
const child = children[index];
|
|
310
|
-
if (child?.type === "text" && !String(child.value ?? "").trim()) continue;
|
|
311
|
-
return child?.type === "element" ? index : -1;
|
|
312
|
-
}
|
|
313
|
-
return -1;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function textContent(node) {
|
|
317
|
-
if (node?.type === "text") return String(node.value ?? "");
|
|
318
|
-
if (!Array.isArray(node?.children)) return "";
|
|
319
|
-
return node.children.map(textContent).join("");
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function wrapMdxComponents(components) {
|
|
323
|
-
const wrapped = {};
|
|
324
|
-
for (const [name, Component] of Object.entries(components ?? {})) {
|
|
325
|
-
if (typeof Component !== "function") continue;
|
|
326
|
-
wrapped[name] = function ComponentBlock(props = {}) {
|
|
327
|
-
const blockId = props["data-openpress-block-id"];
|
|
328
|
-
const objectId = props["data-openpress-object-id"] || (blockId ? createBlockObjectEntityId(blockId) : undefined);
|
|
329
|
-
const rest = { ...props };
|
|
330
|
-
delete rest["data-openpress-block-id"];
|
|
331
|
-
delete rest["data-openpress-object-id"];
|
|
332
|
-
|
|
333
|
-
if (!blockId) return React.createElement(Component, rest);
|
|
334
|
-
|
|
335
|
-
return React.createElement(
|
|
336
|
-
"div",
|
|
337
|
-
{
|
|
338
|
-
"data-openpress-block-id": blockId,
|
|
339
|
-
"data-openpress-object-id": objectId,
|
|
340
|
-
"data-openpress-component-block": name,
|
|
341
|
-
},
|
|
342
|
-
React.createElement(Component, rest),
|
|
343
|
-
);
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
return wrapped;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function assertNoImports(source, filePath) {
|
|
350
|
-
if (/^\s*import\s/m.test(source)) {
|
|
351
|
-
throw new Error(`MDX imports are not supported in OpenPress chapter prose: ${filePath}`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function normalizeSingleLineDisplayMath(source) {
|
|
356
|
-
const fences = [];
|
|
357
|
-
const withoutFences = source.replace(/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g, (match) => {
|
|
358
|
-
const token = `@@MDX_FENCE_${fences.length}@@`;
|
|
359
|
-
fences.push(match);
|
|
360
|
-
return token;
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
const normalized = withoutFences.replace(/^([ \t]*)\$\$([^\n]+?)\$\$[ \t]*$/gm, (_match, indent, math) => (
|
|
364
|
-
`${indent}$$\n${indent}${math.trim()}\n${indent}$$`
|
|
365
|
-
));
|
|
366
|
-
|
|
367
|
-
return normalized.replace(/@@MDX_FENCE_(\d+)@@/g, (_match, index) => fences[Number(index)] ?? "");
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function blockInfo(node) {
|
|
371
|
-
if (node?.type === "element" && PAGINABLE_TAGS.has(node.tagName)) {
|
|
372
|
-
return { kind: "element", name: node.tagName, text: headingText(node) };
|
|
373
|
-
}
|
|
374
|
-
if (node?.type === "element" && node.tagName === "span" && hasClassName(node, "katex-display")) {
|
|
375
|
-
return { kind: "element", name: "math" };
|
|
376
|
-
}
|
|
377
|
-
if (node?.type === "mdxJsxFlowElement" && typeof node.name === "string" && node.name) {
|
|
378
|
-
return { kind: "component", name: node.name };
|
|
379
|
-
}
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function applyListItemBlocks({
|
|
384
|
-
node,
|
|
385
|
-
id,
|
|
386
|
-
blocks,
|
|
387
|
-
filePath,
|
|
388
|
-
chapterSlug,
|
|
389
|
-
includeBlockIds,
|
|
390
|
-
}) {
|
|
391
|
-
const items = listItems(node);
|
|
392
|
-
if (items.length === 0) {
|
|
393
|
-
if (includeBlockIds && !includeBlockIds.has(id)) return false;
|
|
394
|
-
setDataAttribute(node, "data-openpress-block-id", id);
|
|
395
|
-
setDataAttribute(node, "data-openpress-object-id", createBlockObjectEntityId(id));
|
|
396
|
-
blocks.push({
|
|
397
|
-
id,
|
|
398
|
-
kind: "element",
|
|
399
|
-
name: node.tagName,
|
|
400
|
-
text: textContent(node).trim() || undefined,
|
|
401
|
-
filePath,
|
|
402
|
-
chapterSlug,
|
|
403
|
-
source: sourcePosition(node.position),
|
|
404
|
-
});
|
|
405
|
-
return "skip";
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const itemRecords = items.map((item, index) => ({
|
|
409
|
-
id: `${id}-i${index}`,
|
|
410
|
-
node: item,
|
|
411
|
-
index,
|
|
412
|
-
}));
|
|
413
|
-
const selected = includeBlockIds
|
|
414
|
-
? itemRecords.filter((item) => includeBlockIds.has(item.id))
|
|
415
|
-
: itemRecords;
|
|
416
|
-
if (selected.length === 0) return false;
|
|
417
|
-
|
|
418
|
-
setDataAttribute(node, "data-openpress-list-id", id);
|
|
419
|
-
|
|
420
|
-
// For ordered lists, continuation pages must keep numbering picking up
|
|
421
|
-
// from the first surviving item. `start` is the 1-based number of the
|
|
422
|
-
// first `<li>` rendered, so if the original list had `start="5"` and we
|
|
423
|
-
// dropped the first three items, continuation starts at 5 + 3 = 8.
|
|
424
|
-
if (node.tagName === "ol" && selected[0]?.index > 0) {
|
|
425
|
-
const baseStart = Number(node.properties?.start ?? 1);
|
|
426
|
-
const continuationStart = baseStart + selected[0].index;
|
|
427
|
-
node.properties = { ...node.properties, start: continuationStart };
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
const selectedNodes = new Set(selected.map((item) => item.node));
|
|
431
|
-
pruneUnselectedListItems(node, new Set(itemRecords.map((item) => item.node)), selectedNodes);
|
|
432
|
-
|
|
433
|
-
for (const item of selected) {
|
|
434
|
-
setDataAttribute(item.node, "data-openpress-block-id", item.id);
|
|
435
|
-
setDataAttribute(item.node, "data-openpress-object-id", createBlockObjectEntityId(item.id));
|
|
436
|
-
blocks.push({
|
|
437
|
-
id: item.id,
|
|
438
|
-
kind: "list-item",
|
|
439
|
-
name: "list-item",
|
|
440
|
-
text: textContent(item.node).trim() || undefined,
|
|
441
|
-
filePath,
|
|
442
|
-
chapterSlug,
|
|
443
|
-
listId: id,
|
|
444
|
-
listTag: node.tagName,
|
|
445
|
-
itemIndex: item.index,
|
|
446
|
-
source: sourcePosition(item.node.position ?? node.position),
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
return "skip";
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function listItems(list) {
|
|
453
|
-
if (list?.type !== "element") return [];
|
|
454
|
-
if (list.tagName !== "ul" && list.tagName !== "ol") return [];
|
|
455
|
-
return (list.children ?? []).filter((child) => child?.type === "element" && child.tagName === "li");
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
function pruneUnselectedListItems(node, itemNodes, selectedNodes) {
|
|
459
|
-
if (!Array.isArray(node?.children)) return;
|
|
460
|
-
node.children = node.children.filter((child) => {
|
|
461
|
-
if (!itemNodes.has(child)) return true;
|
|
462
|
-
return selectedNodes.has(child);
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function tableBodyRows(table) {
|
|
467
|
-
if (table?.type !== "element" || table.tagName !== "table") return [];
|
|
468
|
-
const rows = [];
|
|
469
|
-
for (const child of table.children ?? []) {
|
|
470
|
-
if (child?.type === "element" && child.tagName === "tbody") {
|
|
471
|
-
for (const row of child.children ?? []) {
|
|
472
|
-
if (row?.type === "element" && row.tagName === "tr") rows.push(row);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
if (rows.length > 0) return rows;
|
|
477
|
-
return (table.children ?? []).filter((child) => child?.type === "element" && child.tagName === "tr");
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
function tableHeaderRow(table) {
|
|
481
|
-
if (table?.type !== "element" || table.tagName !== "table") return null;
|
|
482
|
-
for (const child of table.children ?? []) {
|
|
483
|
-
if (child?.type !== "element" || child.tagName !== "thead") continue;
|
|
484
|
-
return (child.children ?? []).find((row) => row?.type === "element" && row.tagName === "tr") ?? null;
|
|
485
|
-
}
|
|
486
|
-
return null;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function selectedFirstTableRowIndex(rows, includeBlockIds, tableId) {
|
|
490
|
-
if (!includeBlockIds) return 0;
|
|
491
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
492
|
-
if (includeBlockIds.has(`${tableId}-r${index}`)) return index;
|
|
493
|
-
}
|
|
494
|
-
return -1;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
function tableCaption(table) {
|
|
498
|
-
if (table?.type !== "element" || table.tagName !== "table") return null;
|
|
499
|
-
return (table.children ?? []).find((child) => child?.type === "element" && child.tagName === "caption") ?? null;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
function pruneUnselectedTableRows(node, rowNodes, selectedNodes) {
|
|
503
|
-
if (!Array.isArray(node?.children)) return;
|
|
504
|
-
node.children = node.children.filter((child) => {
|
|
505
|
-
if (!rowNodes.has(child)) return true;
|
|
506
|
-
return selectedNodes.has(child);
|
|
507
|
-
});
|
|
508
|
-
for (const child of node.children) pruneUnselectedTableRows(child, rowNodes, selectedNodes);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function stripTableHeader(table) {
|
|
512
|
-
if (!Array.isArray(table?.children)) return;
|
|
513
|
-
table.children = table.children.filter((child) => {
|
|
514
|
-
if (child?.type !== "element") return true;
|
|
515
|
-
return child.tagName !== "thead";
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
function removeTableCaption(table) {
|
|
520
|
-
if (!Array.isArray(table?.children)) return;
|
|
521
|
-
table.children = table.children.filter((child) => child?.type !== "element" || child.tagName !== "caption");
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
function headingText(node) {
|
|
525
|
-
if (!/^h[1-6]$/.test(String(node?.tagName ?? ""))) return undefined;
|
|
526
|
-
return textContent(node).trim() || undefined;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
function normalizeBlockAttributes(value) {
|
|
530
|
-
if (!value) return new Map();
|
|
531
|
-
if (value instanceof Map) return value;
|
|
532
|
-
if (typeof value === "object") return new Map(Object.entries(value));
|
|
533
|
-
return new Map();
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
function hasClassName(node, className) {
|
|
537
|
-
const raw = node?.properties?.className;
|
|
538
|
-
if (Array.isArray(raw)) return raw.includes(className);
|
|
539
|
-
if (typeof raw === "string") return raw.split(/\s+/).includes(className);
|
|
540
|
-
return false;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
function setDataAttribute(node, name, value) {
|
|
544
|
-
if (node.type === "mdxJsxFlowElement") {
|
|
545
|
-
node.attributes ??= [];
|
|
546
|
-
node.attributes.push({
|
|
547
|
-
type: "mdxJsxAttribute",
|
|
548
|
-
name,
|
|
549
|
-
value,
|
|
550
|
-
});
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
node.properties ??= {};
|
|
555
|
-
node.properties[name] = value;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function createObjectEntityId(kind, ...parts) {
|
|
559
|
-
return [kind, ...parts.map((part) => encodeURIComponent(String(part)))].join(":");
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
function createBlockObjectEntityId(blockId) {
|
|
563
|
-
return createObjectEntityId("mdx-block", blockId);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
function visit(node, visitor) {
|
|
567
|
-
visitor(node);
|
|
568
|
-
if (!Array.isArray(node?.children)) return;
|
|
569
|
-
for (const child of node.children) visit(child, visitor);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
function filterTree(node, visitor) {
|
|
573
|
-
const keep = visitor(node);
|
|
574
|
-
if (!keep) return false;
|
|
575
|
-
if (keep === "skip") return true;
|
|
576
|
-
if (!Array.isArray(node?.children)) return true;
|
|
577
|
-
node.children = node.children.filter((child) => filterTree(child, visitor));
|
|
578
|
-
return true;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
function sourcePosition(position) {
|
|
582
|
-
if (!position?.start || !position?.end) return undefined;
|
|
583
|
-
return {
|
|
584
|
-
line: position.start.line,
|
|
585
|
-
column: position.start.column,
|
|
586
|
-
endLine: position.end.line,
|
|
587
|
-
endColumn: position.end.column,
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
function slugPart(value) {
|
|
592
|
-
const slug = String(value)
|
|
593
|
-
.trim()
|
|
594
|
-
.replace(/\.[^.]+$/, "")
|
|
595
|
-
.replace(/[^A-Za-z0-9_-]+/g, "-")
|
|
596
|
-
.replace(/^-+|-+$/g, "")
|
|
597
|
-
.toLowerCase();
|
|
598
|
-
return slug || "document";
|
|
599
|
-
}
|