@godcreator/word-report 0.5.1 → 0.6.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/dist/cli.mjs +2 -2
- package/dist/core.mjs +1 -1
- package/dist/{export-CGvF3Wz-.mjs → export-BrDdJ_E-.mjs} +2 -2
- package/dist/{mdx-B1V34o8x.mjs → mdx-DUOW1JEE.mjs} +45 -20
- package/dist/node.mjs +2 -2
- package/dist/{report-files-DyPBOCgh.mjs → report-files-CpZA-0-K.mjs} +1 -1
- package/dist/site-server.mjs +2 -2
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as reportExport, r as checkReports } from "./export-
|
|
3
|
-
import { o as reportEntryIn, s as reportEntryOf } from "./report-files-
|
|
2
|
+
import { n as reportExport, r as checkReports } from "./export-BrDdJ_E-.mjs";
|
|
3
|
+
import { o as reportEntryIn, s as reportEntryOf } from "./report-files-CpZA-0-K.mjs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { realpathSync } from "node:fs";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
package/dist/core.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { i as validateDocument, n as safeRelativePath, o as parseReportJson, s as ReportContentError, t as assembleDocument } from "./assemble-BEt9_xsB.mjs";
|
|
2
|
-
import { a as mdxReportInputsOf, i as compileMdxReport, n as MDX_REFERENCES_NAME, o as GENERATED_ID_PREFIX, r as assembleMdxReport, t as MDX_ENTRY_NAME } from "./mdx-
|
|
2
|
+
import { a as mdxReportInputsOf, i as compileMdxReport, n as MDX_REFERENCES_NAME, o as GENERATED_ID_PREFIX, r as assembleMdxReport, t as MDX_ENTRY_NAME } from "./mdx-DUOW1JEE.mjs";
|
|
3
3
|
export { GENERATED_ID_PREFIX, MDX_ENTRY_NAME, MDX_REFERENCES_NAME, ReportContentError, assembleDocument, assembleMdxReport, compileMdxReport, mdxReportInputsOf, parseReportJson, safeRelativePath, validateDocument };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as walk, i as validateDocument, n as safeRelativePath, o as parseReportJson, s as ReportContentError, t as assembleDocument } from "./assemble-BEt9_xsB.mjs";
|
|
2
|
-
import { a as mdxReportInputsOf, r as assembleMdxReport, t as MDX_ENTRY_NAME } from "./mdx-
|
|
3
|
-
import { l as reportsDirName, t as JSON_ENTRY_NAME } from "./report-files-
|
|
2
|
+
import { a as mdxReportInputsOf, r as assembleMdxReport, t as MDX_ENTRY_NAME } from "./mdx-DUOW1JEE.mjs";
|
|
3
|
+
import { l as reportsDirName, t as JSON_ENTRY_NAME } from "./report-files-CpZA-0-K.mjs";
|
|
4
4
|
import { access, mkdir, open, readFile, readdir, realpath, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -298,12 +298,13 @@ function collectElement(context, element, marks, out) {
|
|
|
298
298
|
return;
|
|
299
299
|
}
|
|
300
300
|
case "WordPlainMath": {
|
|
301
|
-
const attributes = attributesOf(context, element, {
|
|
302
|
-
const
|
|
301
|
+
const attributes = attributesOf(context, element, { word: "required" });
|
|
302
|
+
const latex = plainMathFormulaOf(context, element);
|
|
303
|
+
const plainText = plainMathRunsOf(context, element, attributes["word"]);
|
|
303
304
|
out.push(located(context, context.ids.request({
|
|
304
305
|
type: "math",
|
|
305
306
|
id: "",
|
|
306
|
-
latex
|
|
307
|
+
latex,
|
|
307
308
|
plainText
|
|
308
309
|
}, "m"), element));
|
|
309
310
|
return;
|
|
@@ -323,27 +324,51 @@ function unknownComponentMessage(name, allowed) {
|
|
|
323
324
|
if (/^[A-Z]/.test(name) && !name.startsWith("Word")) return `报告里的组件都以 Word 开头,<${name}> 不认:${allowed}`;
|
|
324
325
|
return `认不出组件 <${name}>:${allowed}`;
|
|
325
326
|
}
|
|
326
|
-
|
|
327
|
+
/** <WordPlainMath> 标签里的公式:只能是一个 $…$ */
|
|
328
|
+
function plainMathFormulaOf(context, element) {
|
|
329
|
+
const children = element.children.filter((child) => !isCommentOnlyExpression(child));
|
|
330
|
+
const only = children.length === 1 ? children[0] : void 0;
|
|
331
|
+
if (only?.type !== "inlineMath") failAt(context, element, "<WordPlainMath word=\"…\"> 的标签里只写一个行内公式 $…$,别的都不放");
|
|
332
|
+
return only.value;
|
|
333
|
+
}
|
|
334
|
+
const PLAIN_MATH_MARK_ORDER = [
|
|
327
335
|
"em",
|
|
328
336
|
"sub",
|
|
329
337
|
"sup"
|
|
330
338
|
];
|
|
331
|
-
/**
|
|
332
|
-
function plainMathRunsOf(context, element) {
|
|
333
|
-
const usage = "<WordPlainMath
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
339
|
+
/** word 属性:Word 里写的文字,按正文的规则解析,只收文字、*斜体*、<sub>、<sup>;相邻同样式的文字合并 */
|
|
340
|
+
function plainMathRunsOf(context, element, word) {
|
|
341
|
+
const usage = "<WordPlainMath> 的 word 属性写 Word 用的文字,只能用文字、*斜体*、<sub>、<sup>";
|
|
342
|
+
if (/[\r\n]/.test(word)) failAt(context, element, `${usage},不能换行`);
|
|
343
|
+
let root;
|
|
344
|
+
try {
|
|
345
|
+
root = parseMdx(word, "");
|
|
346
|
+
} catch (error) {
|
|
347
|
+
return failAt(context, element, `<WordPlainMath> 的 word 属性解析不了(位置从属性开头算):${error.message}`);
|
|
348
|
+
}
|
|
349
|
+
const blocks = root.children;
|
|
350
|
+
if (blocks.length !== 1 || blocks[0].type !== "paragraph") failAt(context, element, `${usage},这里${blocks.length ? "不是一段文字" : "是空的"}`);
|
|
351
|
+
const runs = [];
|
|
352
|
+
const collect = (nodes, marks) => {
|
|
353
|
+
for (const node of nodes) if (node.type === "text") {
|
|
354
|
+
const sorted = PLAIN_MATH_MARK_ORDER.filter((mark) => marks.has(mark));
|
|
355
|
+
const previous = runs.at(-1);
|
|
356
|
+
if (previous && (previous.marks ?? []).join() === sorted.join()) previous.text += node.value;
|
|
357
|
+
else runs.push(sorted.length ? {
|
|
358
|
+
text: node.value,
|
|
359
|
+
marks: sorted
|
|
360
|
+
} : { text: node.value });
|
|
361
|
+
} else if (node.type === "emphasis") collect(node.children, /* @__PURE__ */ new Set([...marks, "em"]));
|
|
362
|
+
else if (node.type === "mdxJsxTextElement" && (node.name === "sub" || node.name === "sup")) {
|
|
363
|
+
if (node.attributes.length) failAt(context, element, `${usage},<${node.name}> 不带属性`);
|
|
364
|
+
const script = node.name;
|
|
365
|
+
if (marks.has(script === "sub" ? "sup" : "sub")) failAt(context, element, "<WordPlainMath> 的 word 属性里同一段文字不能既是下标又是上标");
|
|
366
|
+
collect(node.children, /* @__PURE__ */ new Set([...marks, script]));
|
|
367
|
+
} else failAt(context, element, `${usage},这里出现了 ${node.type === "mdxJsxTextElement" ? `<${node.name}>` : node.type}`);
|
|
368
|
+
};
|
|
369
|
+
collect(blocks[0].children, /* @__PURE__ */ new Set());
|
|
370
|
+
if (!runs.some((run) => run.text)) failAt(context, element, `${usage},这里是空的`);
|
|
371
|
+
return runs.filter((run) => run.text);
|
|
347
372
|
}
|
|
348
373
|
function linkTextOf(context, link) {
|
|
349
374
|
const inlines = [];
|
package/dist/node.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as readReport, n as reportExport, r as checkReports, t as reportEntry } from "./export-
|
|
2
|
-
import { a as readReportFiles, c as reportIdsOf, i as readMdxReportFiles, l as reportsDirName, n as REPORT_ID_PATTERN, o as reportEntryIn, r as isMdxEntry, s as reportEntryOf, t as JSON_ENTRY_NAME } from "./report-files-
|
|
1
|
+
import { i as readReport, n as reportExport, r as checkReports, t as reportEntry } from "./export-BrDdJ_E-.mjs";
|
|
2
|
+
import { a as readReportFiles, c as reportIdsOf, i as readMdxReportFiles, l as reportsDirName, n as REPORT_ID_PATTERN, o as reportEntryIn, r as isMdxEntry, s as reportEntryOf, t as JSON_ENTRY_NAME } from "./report-files-CpZA-0-K.mjs";
|
|
3
3
|
export { JSON_ENTRY_NAME, REPORT_ID_PATTERN, checkReports, isMdxEntry, readMdxReportFiles, readReport, readReportFiles, reportEntry, reportEntryIn, reportEntryOf, reportExport, reportIdsOf, reportsDirName };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as validateDocument, n as safeRelativePath, o as parseReportJson, s as ReportContentError } from "./assemble-BEt9_xsB.mjs";
|
|
2
|
-
import { a as mdxReportInputsOf, t as MDX_ENTRY_NAME } from "./mdx-
|
|
2
|
+
import { a as mdxReportInputsOf, t as MDX_ENTRY_NAME } from "./mdx-DUOW1JEE.mjs";
|
|
3
3
|
import { readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
//#region src/node/report-files.ts
|
package/dist/site-server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as assembleDocument } from "./assemble-BEt9_xsB.mjs";
|
|
2
|
-
import { a as mdxReportInputsOf, r as assembleMdxReport, t as MDX_ENTRY_NAME } from "./mdx-
|
|
3
|
-
import { a as readReportFiles, c as reportIdsOf, i as readMdxReportFiles, n as REPORT_ID_PATTERN, o as reportEntryIn, r as isMdxEntry, t as JSON_ENTRY_NAME } from "./report-files-
|
|
2
|
+
import { a as mdxReportInputsOf, r as assembleMdxReport, t as MDX_ENTRY_NAME } from "./mdx-DUOW1JEE.mjs";
|
|
3
|
+
import { a as readReportFiles, c as reportIdsOf, i as readMdxReportFiles, n as REPORT_ID_PATTERN, o as reportEntryIn, r as isMdxEntry, t as JSON_ENTRY_NAME } from "./report-files-CpZA-0-K.mjs";
|
|
4
4
|
import { n as reportHrefOf } from "./page-data-DLPoVgXy.mjs";
|
|
5
5
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|