@godcreator/word-report 0.5.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { n as reportExport, r as checkReports } from "./export-B01-yaAq.mjs";
3
- import { o as reportEntryIn, s as reportEntryOf } from "./report-files-Dfr71bRv.mjs";
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-C1RVv6E-.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-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-C1RVv6E-.mjs";
3
- import { l as reportsDirName, t as JSON_ENTRY_NAME } from "./report-files-Dfr71bRv.mjs";
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, { tex: "required" });
302
- const plainText = plainMathRunsOf(context, element);
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: attributes["tex"],
307
+ latex,
307
308
  plainText
308
309
  }, "m"), element));
309
310
  return;
@@ -315,30 +316,59 @@ function collectElement(context, element, marks, out) {
315
316
  return;
316
317
  default:
317
318
  if (name !== null && BLOCK_COMPONENTS.has(name)) failAt(context, element, `<${name}> 要单独成段,前后空一行,不写在一段文字中间`);
318
- failAt(context, element, `认不出组件 <${name ?? ""}>:行内只能用 WordRef、WordCite、WordPlainMath、sub、sup、strong、em、br`);
319
+ failAt(context, element, unknownComponentMessage(name ?? "", "行内只能用 WordRef、WordCite、WordPlainMath 与 HTML 标签 sub、sup、strong、em、br"));
319
320
  }
320
321
  }
321
- const PLAIN_MATH_MARKS = [
322
+ /** 认不出的元素:大写开头、不以 Word 开头的单独说明——报告的组件名都以 Word 开头,小写的只认几个 HTML 标签 */
323
+ function unknownComponentMessage(name, allowed) {
324
+ if (/^[A-Z]/.test(name) && !name.startsWith("Word")) return `报告里的组件都以 Word 开头,<${name}> 不认:${allowed}`;
325
+ return `认不出组件 <${name}>:${allowed}`;
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 = [
322
335
  "em",
323
336
  "sub",
324
337
  "sup"
325
338
  ];
326
- /** <WordPlainMath> 里写给 Word 的文字:只收文字、斜体、下标、上标 */
327
- function plainMathRunsOf(context, element) {
328
- const usage = "<WordPlainMath tex=\"…\"> 里写 Word 用的文字,只能用文字、*斜体*、<sub>、<sup>";
329
- const inlines = inlinesOf(context, element.children);
330
- if (!inlines.length) failAt(context, element, `${usage},这里是空的`);
331
- return inlines.map((inline) => {
332
- if (inline.type !== "text") failAt(context, element, `${usage},这里出现了 ${inline.type}`);
333
- const marks = inline.marks ?? [];
334
- const unsupported = marks.find((mark) => !PLAIN_MATH_MARKS.includes(mark));
335
- if (unsupported !== void 0) failAt(context, element, `${usage},这里出现了 ${unsupported}`);
336
- if (marks.includes("sub") && marks.includes("sup")) failAt(context, element, "<WordPlainMath> 里同一段文字不能既是下标又是上标");
337
- return marks.length ? {
338
- text: inline.text,
339
- marks
340
- } : { text: inline.text };
341
- });
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);
342
372
  }
343
373
  function linkTextOf(context, link) {
344
374
  const inlines = [];
@@ -593,7 +623,7 @@ function componentOf(context, element, place) {
593
623
  case "tr":
594
624
  case "th":
595
625
  case "td": return failAt(context, element, `<${element.name}> 只能写在 <WordTable> 里:不编号的简单表格直接写 GFM 表格`);
596
- default: return failAt(context, element, `认不出组件 <${element.name ?? ""}>:块级只能用 Figure、Figures、Table、Abstract、Bibliography`);
626
+ default: return failAt(context, element, unknownComponentMessage(element.name ?? "", "块级只能用 WordFigure、WordFigures、WordTable、WordAbstract、WordBibliography"));
597
627
  }
598
628
  }
599
629
  function captionOf(context, element, what) {
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-B01-yaAq.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-Dfr71bRv.mjs";
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-C1RVv6E-.mjs";
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
@@ -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-C1RVv6E-.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-Dfr71bRv.mjs";
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godcreator/word-report",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "author": {
5
5
  "name": "godcreator"
6
6
  },