@gmb/bitmark-parser-generator 5.24.0 → 5.26.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.
@@ -230,6 +230,7 @@ var BitType2 = {
230
230
  dangerAlt: "danger-alt",
231
231
  dangerCollapsible: "danger-collapsible",
232
232
  definitionList: "definition-list",
233
+ definitionListCollapsible: "definition-list-collapsible",
233
234
  definitionTerm: "definition-term",
234
235
  deleted: "deleted",
235
236
  details: "details",
@@ -510,6 +511,8 @@ var BitType2 = {
510
511
  smartStandardArticleNonNormativeCollapsible: "smart-standard-article-non-normative-collapsible",
511
512
  smartStandardArticleNormative: "smart-standard-article-normative",
512
513
  smartStandardArticleNormativeCollapsible: "smart-standard-article-normative-collapsible",
514
+ smartStandardDefinitionListNonNormative: "smart-standard-definition-list-non-normative",
515
+ smartStandardDefinitionListNormative: "smart-standard-definition-list-normative",
513
516
  smartStandardExampleNonNormative: "smart-standard-example-non-normative",
514
517
  smartStandardExampleNonNormativeCollapsible: "smart-standard-example-non-normative-collapsible",
515
518
  smartStandardExampleNormative: "smart-standard-example-normative",
@@ -560,6 +563,8 @@ var BitType2 = {
560
563
  smartStandardTableNormativeCollapsible: "smart-standard-table-normative-collapsible",
561
564
  standardArticleNonNormative: "standard-article-non-normative",
562
565
  standardArticleNormative: "standard-article-normative",
566
+ standardDefinitionListNonNormative: "standard-definition-list-non-normative",
567
+ standardDefinitionListNormative: "standard-definition-list-normative",
563
568
  standardExampleNonNormative: "standard-example-non-normative",
564
569
  standardExampleNormative: "standard-example-normative",
565
570
  standardImageFigureNonNormative: "standard-image-figure-non-normative",
@@ -731,6 +736,7 @@ var CardSetConfigKey = {
731
736
  flashcard: "flashcard",
732
737
  flashcard1: "flashcard1",
733
738
  definitionList: "definitionList",
739
+ definitionListPlain: "definitionListPlain",
734
740
  elements: "elements",
735
741
  statements: "statements",
736
742
  quiz: "quiz",
@@ -1344,6 +1350,7 @@ var propertyKeys = {
1344
1350
  property_enforceUpdateOverUserInput: "@enforceUpdateOverUserInput",
1345
1351
  property_extractorExtractionTimestamp: "@extractorExtractionTimestamp",
1346
1352
  property_isCaseSensitive: "@isCaseSensitive",
1353
+ property_isCollapsible: "@isCollapsible",
1347
1354
  property_isInfoOnly: "@isInfoOnly",
1348
1355
  property_isPublic: "@isPublic",
1349
1356
  property_isTemplate: "@isTemplate",
@@ -2548,6 +2555,126 @@ var CARDSETS = {
2548
2555
  ]
2549
2556
  },
2550
2557
  //
2558
+ // definition-list-plain
2559
+ //
2560
+ // Same shape as `definitionList`, but every variant body is rendered as
2561
+ // plain text (string), not bitmark+ AST. Used by
2562
+ // `meta-search-default-terms` / `meta-search-default-topics`, which need
2563
+ // term/definition text emitted verbatim instead of as a ProseMirror tree.
2564
+ //
2565
+ [CardSetConfigKey.definitionListPlain]: {
2566
+ jsonKey: "definitions",
2567
+ exportJsonKey: { definitions: "$" },
2568
+ sides: [
2569
+ {
2570
+ name: "term",
2571
+ variants: [
2572
+ {
2573
+ jsonKey: "term.text",
2574
+ exportJsonKey: [{ "@absent": { term: {} } }, { term: { text: "$" } }],
2575
+ format: TextFormat2.plainText,
2576
+ tags: [
2577
+ {
2578
+ key: ConfigKey.group_standardTags,
2579
+ description: "Standard tags for the definition."
2580
+ },
2581
+ {
2582
+ key: ConfigKey.tag_title,
2583
+ description: "Title of the definition.",
2584
+ format: TagFormat.plainText,
2585
+ jsonKey: "^heading.forKeys",
2586
+ exportJsonKey: { "@bit": { heading: { forKeys: "$" } } }
2587
+ },
2588
+ {
2589
+ key: ConfigKey.group_resourceIcon,
2590
+ description: "Icon resource for the definition.",
2591
+ format: TagFormat.plainText,
2592
+ jsonKey: "term.icon|resource(type=image, key=image)",
2593
+ exportJsonKey: { term: { icon: { type: "image", image: { src: "$" } } } }
2594
+ },
2595
+ {
2596
+ key: ConfigKey.property_example,
2597
+ exportJsonKey: [
2598
+ { "@keyonly": { isExample: true, example: true, "@bit": { isExample: true } } },
2599
+ { "@absent": { isExample: true, example: true, "@bit": { isExample: true } } },
2600
+ { isExample: true, example: "$", "@bit": { isExample: true } }
2601
+ ],
2602
+ description: "Example marker for the definition term.",
2603
+ format: TagFormat.bitmarkText,
2604
+ nullable: true
2605
+ }
2606
+ ]
2607
+ }
2608
+ ]
2609
+ },
2610
+ {
2611
+ name: "definition",
2612
+ variants: [
2613
+ {
2614
+ jsonKey: "definition.text",
2615
+ exportJsonKey: [{ "@absent": { definition: {} } }, { definition: { text: "$" } }],
2616
+ format: TextFormat2.plainText,
2617
+ tags: [
2618
+ {
2619
+ key: ConfigKey.group_standardTags,
2620
+ description: "Standard tags for the definition."
2621
+ },
2622
+ {
2623
+ key: ConfigKey.tag_title,
2624
+ description: "Title of the definition.",
2625
+ format: TagFormat.plainText,
2626
+ jsonKey: "^heading.forValues",
2627
+ exportJsonKey: { "@bit": { heading: { forValues: "$" } } }
2628
+ },
2629
+ {
2630
+ key: ConfigKey.group_resourceIcon,
2631
+ description: "Icon resource for the definition.",
2632
+ jsonKey: "definition.icon|resource(type=image, key=image)",
2633
+ exportJsonKey: { definition: { icon: { type: "image", image: { src: "$" } } } }
2634
+ },
2635
+ {
2636
+ key: ConfigKey.property_example,
2637
+ exportJsonKey: [
2638
+ { "@keyonly": { isExample: true, example: true, "@bit": { isExample: true } } },
2639
+ { "@absent": { isExample: true, example: true, "@bit": { isExample: true } } },
2640
+ { isExample: true, example: "$", "@bit": { isExample: true } }
2641
+ ],
2642
+ description: "Example marker for the definition.",
2643
+ format: TagFormat.bitmarkText,
2644
+ nullable: true
2645
+ }
2646
+ ]
2647
+ },
2648
+ {
2649
+ jsonKey: "alternativeDefinitions[].text",
2650
+ exportJsonKey: { alternativeDefinitions: [{ text: "$" }] },
2651
+ format: TextFormat2.plainText,
2652
+ tags: [
2653
+ {
2654
+ key: ConfigKey.group_standardTags,
2655
+ description: "Standard tags for the definition."
2656
+ },
2657
+ {
2658
+ exportJsonKey: { title: "$" },
2659
+ key: ConfigKey.tag_title,
2660
+ description: "Title of the definition."
2661
+ },
2662
+ {
2663
+ key: ConfigKey.group_resourceIcon,
2664
+ description: "Icon resource for the definition.",
2665
+ jsonKey: "alternativeDefinitions[].icon|resource(type=image, key=image)",
2666
+ exportJsonKey: {
2667
+ alternativeDefinitions: [{ icon: { type: "image", image: { src: "$" } } }]
2668
+ }
2669
+ }
2670
+ ],
2671
+ repeatCount: Count.infinity
2672
+ }
2673
+ ]
2674
+ }
2675
+ ]
2676
+ },
2677
+ //
2551
2678
  // match-pairs
2552
2679
  //
2553
2680
  [CardSetConfigKey.matchPairs]: {
@@ -3485,12 +3612,29 @@ var CARDSETS = {
3485
3612
  // ALIGN-EXAMPLE-CASCADE §3.10: `questions` is NOT in BPG's
3486
3613
  // `pushExampleDownTree` dispatch — bit-header `[@example]`
3487
3614
  // does not propagate `example`/`isExample` onto question
3488
- // entries. Only entry-local `[@example]` fires (handled by
3489
- // `@keyonly` and the unconditional fallback). No `@absent`
3490
- // rule.
3615
+ // entries. Only entry-local `[@example]` fires.
3616
+ //
3617
+ // BPG's `BaseBuilder.toExample` for interview questions
3618
+ // (Builder.ts:2575,2588) uses `data.__sampleSolutionAst`
3619
+ // as `defaultExample` — bare `[@example]` (which sets
3620
+ // `__isDefaultExample=true, example=undefined`) emits the
3621
+ // parsed sample-solution AST in the `example` slot. The
3622
+ // `@keyonly` rule mirrors that runtime behaviour via
3623
+ // `$parent.sampleSolution` — the chain-walker's post-walk
3624
+ // retry resolves this once the sibling `[@sampleSolution]`
3625
+ // chain has merged into the shared scope (interview's
3626
+ // `[@example]` typically precedes `[@sampleSolution]` in
3627
+ // source). Format coercion turns the resolved string
3628
+ // value into a PM tree.
3491
3629
  key: ConfigKey.property_example,
3492
3630
  exportJsonKey: [
3493
- { "@keyonly": { isExample: true, example: true, "@bit": { isExample: true } } },
3631
+ {
3632
+ "@keyonly": {
3633
+ isExample: true,
3634
+ example: "$parent.sampleSolution",
3635
+ "@bit": { isExample: true }
3636
+ }
3637
+ },
3494
3638
  { isExample: true, example: "$", "@bit": { isExample: true } }
3495
3639
  ],
3496
3640
  description: "Example marker for the question (entry-local only; no bit-header cascade).",
@@ -5313,7 +5457,11 @@ var GROUPS = {
5313
5457
  {
5314
5458
  key: ConfigKey.property_mark,
5315
5459
  jsonKey: "marks.mark",
5316
- exportJsonKey: { marks: [{ mark: "$" }] },
5460
+ // `emphasis: 'underline'` is the per-entry default for mark
5461
+ // configs — mirrors the hardcoded default in BPG
5462
+ // `MarkConfigChainContentProcessor.ts:55-58`. Chained
5463
+ // `[@emphasis:…]` overrides via deep-merge into `marks[-1]`.
5464
+ exportJsonKey: { marks: [{ mark: "$", emphasis: "underline" }] },
5317
5465
  description: "The mark configuration",
5318
5466
  format: TagFormat.plainText,
5319
5467
  maxCount: Count.infinity,
@@ -5355,13 +5503,22 @@ var GROUPS = {
5355
5503
  {
5356
5504
  key: ConfigKey.property_example,
5357
5505
  jsonKey: "example",
5358
- exportJsonKey: [
5359
- { "@keyonly": { isExample: true, example: true, "@bit": { isExample: true } } },
5360
- { "@absent": { isExample: true, example: true, "@bit": { isExample: true } } },
5361
- { isExample: true, example: "$", "@bit": { isExample: true } }
5362
- ],
5506
+ // Per-mark `@example` is a boolean toggle. BPG's runtime
5507
+ // `ExampleTagContentProcessor.handleDefaultOnlyExample`
5508
+ // (lines 147-161) normalises ANY `[@example]` or
5509
+ // `[@example:V]` on a mark body-bit to
5510
+ // `__isDefaultExample=true, example=undefined`; the
5511
+ // downstream `toExample(_, _, defaultExample=true)` in
5512
+ // `BaseBuilder.ts:80-87` then emits `example: true`
5513
+ // regardless of source. Declare a single unconditional
5514
+ // boolean-shape rule so the exported schema matches that
5515
+ // runtime semantic instead of the misleading `example: $`
5516
+ // shape (which would only fire if `handleDefaultOnlyExample`
5517
+ // were removed). `@bit: {isExample: true}` cascades the
5518
+ // marker — but NOT the `example` value — to bit root.
5519
+ exportJsonKey: { isExample: true, example: true, "@bit": { isExample: true } },
5363
5520
  description: "An example for the marked content",
5364
- format: TagFormat.bitmarkText,
5521
+ format: TagFormat.boolean,
5365
5522
  nullable: true
5366
5523
  }
5367
5524
  ]
@@ -8137,6 +8294,12 @@ var BITS = {
8137
8294
  description: "The progress of the chapter, used for tracking reading progress",
8138
8295
  format: TagFormat.boolean,
8139
8296
  defaultValue: "true"
8297
+ },
8298
+ {
8299
+ key: ConfigKey.property_isCollapsible,
8300
+ description: "If true, the chapter is collapsible",
8301
+ format: TagFormat.boolean,
8302
+ defaultValue: "false"
8140
8303
  }
8141
8304
  ]
8142
8305
  },
@@ -8911,7 +9074,12 @@ var BITS = {
8911
9074
  maxCount: Count.infinity
8912
9075
  },
8913
9076
  {
8914
- // Override inherited @example from group_standardTags: string root example.
9077
+ // Override inherited @example from group_standardTags: emits both
9078
+ // `isExample` (bool) AND `example` (paragraph array). Declared as
9079
+ // bitmarkText because BPG `JsonGenerator.toExample` renders the
9080
+ // root-example value through the bit's textFormat (not this tag's
9081
+ // declared format) — `TagFormat.plainText` here would be ignored
9082
+ // at runtime and is misleading.
8915
9083
  key: ConfigKey.property_example,
8916
9084
  exportJsonKey: [
8917
9085
  { "@keyonly": { isExample: true, example: "true" } },
@@ -8919,7 +9087,7 @@ var BITS = {
8919
9087
  { isExample: true, example: "$" }
8920
9088
  ],
8921
9089
  description: "The example text for the essay bit",
8922
- format: TagFormat.plainText,
9090
+ format: TagFormat.bitmarkText,
8923
9091
  nullable: true
8924
9092
  }
8925
9093
  ],
@@ -9965,6 +10133,11 @@ var BITS = {
9965
10133
  baseBitType: BitType2._standard,
9966
10134
  description: "Extractor rule bit, used to define extraction rules with reference images and instructions",
9967
10135
  tags: [
10136
+ {
10137
+ exportJsonKey: { title: "$" },
10138
+ key: ConfigKey.tag_title,
10139
+ description: "The name of the extraction rule"
10140
+ },
9968
10141
  {
9969
10142
  key: ConfigKey.group_resourceBitTags,
9970
10143
  description: "Resource bit tags for extraction rule images"
@@ -10281,11 +10454,36 @@ var BITS = {
10281
10454
  ],
10282
10455
  cardSet: CardSetConfigKey.definitionList
10283
10456
  },
10457
+ [BitType2.definitionListCollapsible]: {
10458
+ since: "5.25.0",
10459
+ baseBitType: BitType2.definitionList,
10460
+ description: "Collapsible definition list bit, used to create collapsible lists of definitions in articles or books"
10461
+ },
10462
+ [BitType2.standardDefinitionListNormative]: {
10463
+ since: "5.24.0",
10464
+ baseBitType: BitType2.definitionList,
10465
+ description: "Standard normative definition list bit, used to create normative standard definition lists in articles or books"
10466
+ },
10467
+ [BitType2.standardDefinitionListNonNormative]: {
10468
+ since: "5.24.0",
10469
+ baseBitType: BitType2.definitionList,
10470
+ description: "Standard non-normative definition list bit, used to create non-normative standard definition lists in articles or books"
10471
+ },
10472
+ [BitType2.smartStandardDefinitionListNormative]: {
10473
+ since: "5.24.0",
10474
+ baseBitType: BitType2.standardDefinitionListNormative,
10475
+ description: "Smart standard normative definition list bit, used to create normative smart standard definition lists in articles or books"
10476
+ },
10477
+ [BitType2.smartStandardDefinitionListNonNormative]: {
10478
+ since: "5.24.0",
10479
+ baseBitType: BitType2.standardDefinitionListNonNormative,
10480
+ description: "Smart standard non-normative definition list bit, used to create non-normative smart standard definition lists in articles or books"
10481
+ },
10284
10482
  [BitType2.metaSearchDefaultTerms]: {
10285
10483
  since: "3.12.0",
10286
10484
  baseBitType: BitType2._standard,
10287
10485
  description: "Meta search default terms bit, used to define default search terms in articles",
10288
- cardSet: CardSetConfigKey.definitionList
10486
+ cardSet: CardSetConfigKey.definitionListPlain
10289
10487
  },
10290
10488
  [BitType2.metaSearchDefaultTopics]: {
10291
10489
  since: "3.12.0",
@@ -10329,7 +10527,11 @@ var BITS = {
10329
10527
  [BitType2.qAndACard]: {
10330
10528
  since: "3.25.0",
10331
10529
  baseBitType: BitType2.flashcard1,
10332
- description: "Q&A card bit, used to create question and answer cards in articles or books"
10530
+ description: "Q&A card bit, used to create question and answer cards in articles or books",
10531
+ // PLAN-085: q-and-a-card permits multiple cards (some fixtures carry
10532
+ // two). Override the inherited `flashcard1` (max=1) cardset back to
10533
+ // the unbounded `flashcard` cardset.
10534
+ cardSet: CardSetConfigKey.flashcard
10333
10535
  },
10334
10536
  [BitType2.focusImage]: {
10335
10537
  since: "1.3.0",
@@ -13415,7 +13617,7 @@ var instance2 = new Config();
13415
13617
  // src/generated/package_info.ts
13416
13618
  var PACKAGE_INFO = {
13417
13619
  "name": "@gmb/bitmark-parser-generator",
13418
- "version": "5.24.0",
13620
+ "version": "5.26.0",
13419
13621
  "author": "Get More Brain Ltd",
13420
13622
  "license": "ISC",
13421
13623
  "description": "A bitmark parser and generator using Peggy.js"
@@ -14061,6 +14263,8 @@ var NodeType = {
14061
14263
  internalPrintPdf: "internalPrintPdf",
14062
14264
  internalPrintPdfValue: "internalPrintPdfValue",
14063
14265
  isCaseSensitive: "isCaseSensitive",
14266
+ isCollapsible: "isCollapsible",
14267
+ isCollapsibleValue: "isCollapsibleValue",
14064
14268
  isCommented: "isCommented",
14065
14269
  isCorrect: "isCorrect",
14066
14270
  isEditable: "isEditable",
@@ -28299,6 +28503,12 @@ var Builder = class extends BaseBuilder {
28299
28503
  level: instance6.asNumber(data.level),
28300
28504
  toc: this.toAstProperty(bitType, ConfigKey.property_toc, data.toc, options),
28301
28505
  progress: this.toAstProperty(bitType, ConfigKey.property_progress, data.progress, options),
28506
+ isCollapsible: this.toAstProperty(
28507
+ bitType,
28508
+ ConfigKey.property_isCollapsible,
28509
+ data.isCollapsible,
28510
+ options
28511
+ ),
28302
28512
  anchor: data.anchor,
28303
28513
  reference: data.reference,
28304
28514
  referenceEnd: data.referenceEnd,
@@ -33845,6 +34055,7 @@ var JsonGenerator = class extends AstWalkerGenerator {
33845
34055
  if (instance2.isOfBitType(bitType, BitType2.chapter)) {
33846
34056
  if (bitJson.toc == null) bitJson.toc = true;
33847
34057
  if (bitJson.progress == null) bitJson.progress = true;
34058
+ if (bitJson.isCollapsible == null) bitJson.isCollapsible = false;
33848
34059
  if (bitJson.level == null) bitJson.level = 1;
33849
34060
  if (bitJson.body == null) bitJson.body = this.bodyDefault;
33850
34061
  }
@@ -36042,6 +36253,7 @@ function buildCards(context, bitType, textFormat, parsedCardSet, statementV1, st
36042
36253
  case CardSetConfigKey.flashcard:
36043
36254
  case CardSetConfigKey.flashcard1:
36044
36255
  case CardSetConfigKey.definitionList:
36256
+ case CardSetConfigKey.definitionListPlain:
36045
36257
  result = parseFlashcardOrDefinitionList(context, bitType, processedCardSet);
36046
36258
  break;
36047
36259
  case CardSetConfigKey.elements:
@@ -42108,7 +42320,11 @@ var InputFormat = {
42108
42320
  /**
42109
42321
  * Input is plain text
42110
42322
  */
42111
- plainText: "plainText"
42323
+ plainText: "plainText",
42324
+ /**
42325
+ * Input is HTML (used by convertHtmlTable)
42326
+ */
42327
+ html: "html"
42112
42328
  };
42113
42329
  var BitmarkParserGenerator = class {
42114
42330
  constructor() {
@@ -42643,6 +42859,87 @@ var BitmarkParserGenerator = class {
42643
42859
  const res = generator.generate(data);
42644
42860
  return res;
42645
42861
  }
42862
+ /**
42863
+ * Convert between HTML tables and bitmark tables.
42864
+ *
42865
+ * Direction is auto-detected (override with `options.inputFormat`):
42866
+ * - HTML input: every `<table>` is extracted and emitted as a `[.table-extended]` (or `[.table]`)
42867
+ * bit; output as bitmark (default), JSON, AST, or HTML (re-emit).
42868
+ * - bitmark / JSON / AST input: each `table` / `table-extended` bit is rendered as an HTML
42869
+ * `<table>` fragment.
42870
+ *
42871
+ * Cell content is reproduced verbatim except inline conversion to bitmark marks (bold, italic,
42872
+ * superscript, etc.), with lists and images mapped to their bitmark equivalents.
42873
+ *
42874
+ * @param input - HTML, bitmark, JSON or AST string; or a parsed JSON/AST value; or a file path.
42875
+ * @param options - the conversion options
42876
+ * @returns the converted output as a string (or object for JSON/AST), or void when writing a file
42877
+ * @throws Error if any error occurs
42878
+ */
42879
+ convertHtmlTable(input, options) {
42880
+ const opts = Object.assign({}, options);
42881
+ if (env.isBrowser && opts.outputFile) {
42882
+ throw new Error("Cannot write to file in browser environment");
42883
+ }
42884
+ let inStr = input;
42885
+ const inputIsString = typeof input === "string";
42886
+ if (env.isNode && inputIsString && fs.existsSync(inStr)) {
42887
+ inStr = fs.readFileSync(inStr, { encoding: "utf8" });
42888
+ }
42889
+ const isHtmlString = (s) => {
42890
+ const t = s.replace(/^\s+/, "");
42891
+ return t.startsWith("<") && /<table/i.test(t);
42892
+ };
42893
+ let htmlInput;
42894
+ if (opts.inputFormat === InputFormat.html) {
42895
+ htmlInput = true;
42896
+ } else if (opts.inputFormat != null) {
42897
+ htmlInput = false;
42898
+ } else {
42899
+ htmlInput = inputIsString && isHtmlString(inStr);
42900
+ }
42901
+ if (htmlInput) {
42902
+ const parser2 = new HtmlTableParser();
42903
+ const bits = parser2.parse(inStr, {
42904
+ tableFormat: opts.tableFormat ?? "table-extended",
42905
+ keepUnknownTags: opts.keepUnknownTags,
42906
+ onWarning: (m) => console.warn(m)
42907
+ });
42908
+ const outputFormat2 = opts.outputFormat ?? Output.bitmark;
42909
+ if (outputFormat2 === "html") {
42910
+ const json2 = this.convert(bits, { outputFormat: Output.json });
42911
+ return this.outputHtml(new HtmlTableGenerator().generate(json2), opts);
42912
+ }
42913
+ return this.convert(bits, {
42914
+ outputFormat: Enum22(Output).fromValue(outputFormat2),
42915
+ outputFile: opts.outputFile,
42916
+ fileOptions: opts.fileOptions,
42917
+ jsonOptions: opts.jsonOptions,
42918
+ bitmarkOptions: opts.bitmarkOptions
42919
+ });
42920
+ }
42921
+ const outputFormat = opts.outputFormat ?? "html";
42922
+ if (outputFormat !== "html") {
42923
+ throw new Error(
42924
+ "convertHtmlTable: non-HTML input can only be converted to HTML. Use convert() for bitmark/JSON/AST conversions."
42925
+ );
42926
+ }
42927
+ const json = this.convert(inputIsString ? inStr : input, { outputFormat: Output.json });
42928
+ return this.outputHtml(new HtmlTableGenerator().generate(json), opts);
42929
+ }
42930
+ /**
42931
+ * Write an HTML string to the configured output file, or return it.
42932
+ */
42933
+ outputHtml(html, opts) {
42934
+ if (opts.outputFile) {
42935
+ const output = opts.outputFile.toString();
42936
+ const flag = opts.fileOptions?.append ? "a" : "w";
42937
+ fs.ensureDirSync(path.dirname(output));
42938
+ fs.writeFileSync(output, html, { flag });
42939
+ return;
42940
+ }
42941
+ return html;
42942
+ }
42646
42943
  /**
42647
42944
  * Breakscape bitmark text.
42648
42945
  *
@@ -42921,6 +43218,728 @@ var BoundingBoxIndex = class _BoundingBoxIndex {
42921
43218
  }
42922
43219
  };
42923
43220
 
43221
+ // src/generator/html/HtmlTableGenerator.ts
43222
+ var MARK_TO_TAG = {
43223
+ bold: "b",
43224
+ italic: "i",
43225
+ superscript: "sup",
43226
+ subscript: "sub",
43227
+ strike: "s",
43228
+ del: "del",
43229
+ ins: "ins",
43230
+ underline: "u",
43231
+ highlight: "mark",
43232
+ code: "code"
43233
+ };
43234
+ var HtmlTableGenerator2 = class {
43235
+ constructor() {
43236
+ __publicField(this, "indentUnit", " ");
43237
+ }
43238
+ /**
43239
+ * Generate HTML table fragments from a string or JSON value.
43240
+ * @returns the concatenated `<table>` fragments, blank-line separated (empty string if none).
43241
+ */
43242
+ generate(input) {
43243
+ let data = input;
43244
+ if (typeof data === "string") {
43245
+ try {
43246
+ data = JSON.parse(data);
43247
+ } catch {
43248
+ return "";
43249
+ }
43250
+ }
43251
+ const bits = this.collectBits(data);
43252
+ const fragments = [];
43253
+ for (const bit of bits) {
43254
+ const html = this.renderTableBit(bit);
43255
+ if (html) fragments.push(html);
43256
+ }
43257
+ return fragments.join("\n\n");
43258
+ }
43259
+ // --- bit collection -------------------------------------------------------
43260
+ collectBits(data) {
43261
+ const out = [];
43262
+ const visit = (value) => {
43263
+ if (value == null || typeof value !== "object") return;
43264
+ if (Array.isArray(value)) {
43265
+ value.forEach(visit);
43266
+ return;
43267
+ }
43268
+ const obj = value;
43269
+ if ("bit" in obj && obj.bit && typeof obj.bit === "object") {
43270
+ out.push(obj.bit);
43271
+ } else if ("type" in obj) {
43272
+ out.push(obj);
43273
+ }
43274
+ };
43275
+ visit(data);
43276
+ return out;
43277
+ }
43278
+ // --- table rendering ------------------------------------------------------
43279
+ renderTableBit(bit) {
43280
+ const table = bit.table;
43281
+ if (!table) return "";
43282
+ if (bit.type !== "table" && bit.type !== "table-extended") return "";
43283
+ const extended = this.toExtended(table);
43284
+ const lines = [];
43285
+ lines.push("<table>");
43286
+ if (bit.caption != null) {
43287
+ const caption = this.cellContentToHtml(this.asTextAst(bit.caption));
43288
+ if (caption) lines.push(`${this.indentUnit}<caption>${caption}</caption>`);
43289
+ }
43290
+ this.renderSection(lines, "thead", extended.header, "header");
43291
+ this.renderSection(lines, "tbody", extended.body, "body");
43292
+ this.renderSection(lines, "tfoot", extended.footer, "footer");
43293
+ lines.push("</table>");
43294
+ return lines.join("\n");
43295
+ }
43296
+ toExtended(table) {
43297
+ const t = table;
43298
+ if (t.header || t.body || t.footer) return table;
43299
+ return convertBasicToExtendedTableFormat(table);
43300
+ }
43301
+ renderSection(lines, tag, section, key) {
43302
+ if (!section || !section.rows || section.rows.length === 0) return;
43303
+ lines.push(`${this.indentUnit}<${tag}>`);
43304
+ for (const row of section.rows) {
43305
+ lines.push(`${this.indentUnit.repeat(2)}<tr>`);
43306
+ for (const cell of row.cells ?? []) {
43307
+ lines.push(`${this.indentUnit.repeat(3)}${this.renderCell(cell, key)}`);
43308
+ }
43309
+ lines.push(`${this.indentUnit.repeat(2)}</tr>`);
43310
+ }
43311
+ lines.push(`${this.indentUnit}</${tag}>`);
43312
+ }
43313
+ renderCell(cell, _key) {
43314
+ const tag = cell.title === true ? "th" : "td";
43315
+ const attrs = [];
43316
+ if (cell.rowspan && cell.rowspan > 1) attrs.push(`rowspan="${cell.rowspan}"`);
43317
+ if (cell.colspan && cell.colspan > 1) attrs.push(`colspan="${cell.colspan}"`);
43318
+ if (cell.scope) attrs.push(`scope="${cell.scope}"`);
43319
+ if (cell.colwidth && cell.colwidth > 0) attrs.push(`width="${cell.colwidth}"`);
43320
+ const open = attrs.length > 0 ? `<${tag} ${attrs.join(" ")}>` : `<${tag}>`;
43321
+ return `${open}${this.cellContentToHtml(this.asTextAst(cell.content))}</${tag}>`;
43322
+ }
43323
+ // --- cell content (TextAst -> HTML) ---------------------------------------
43324
+ asTextAst(content) {
43325
+ if (content == null) return [];
43326
+ if (typeof content === "string") return [{ type: "text", text: content }];
43327
+ return content;
43328
+ }
43329
+ cellContentToHtml(blocks) {
43330
+ if (blocks.length === 0) return "";
43331
+ if (blocks.length === 1 && blocks[0].type === "paragraph") {
43332
+ return this.inlineToHtml(blocks[0].content ?? []);
43333
+ }
43334
+ return blocks.map((b) => this.blockToHtml(b)).join("");
43335
+ }
43336
+ blockToHtml(node) {
43337
+ switch (node.type) {
43338
+ case "paragraph":
43339
+ return `<p>${this.inlineToHtml(node.content ?? [])}</p>`;
43340
+ case "bulletList":
43341
+ case "noBulletList":
43342
+ case "orderedList":
43343
+ case "orderedListRoman":
43344
+ case "orderedListRomanLower":
43345
+ case "letteredList":
43346
+ case "letteredListLower":
43347
+ case "taskList":
43348
+ return this.listToHtml(node);
43349
+ case "image":
43350
+ case "imageInline":
43351
+ return this.imageToHtml(node);
43352
+ default:
43353
+ return this.inlineToHtml([node]);
43354
+ }
43355
+ }
43356
+ inlineToHtml(nodes) {
43357
+ return nodes.map((n) => this.inlineNodeToHtml(n)).join("");
43358
+ }
43359
+ inlineNodeToHtml(node) {
43360
+ if (node.type === "hardBreak") return "<br>";
43361
+ if (node.type === "image" || node.type === "imageInline") return this.imageToHtml(node);
43362
+ if (node.type === "text") {
43363
+ return this.wrapMarks(this.escapeText(node.text ?? ""), node.marks);
43364
+ }
43365
+ if (node.content) return this.inlineToHtml(node.content);
43366
+ return this.escapeText(node.text ?? "");
43367
+ }
43368
+ wrapMarks(text, marks) {
43369
+ if (!marks || marks.length === 0) return text;
43370
+ let open = "";
43371
+ let close = "";
43372
+ for (const mark of marks) {
43373
+ if (mark.type === "link") {
43374
+ const href = mark.attrs?.href ?? "";
43375
+ open += `<a href="${this.escapeAttr(href)}">`;
43376
+ close = `</a>${close}`;
43377
+ } else {
43378
+ const tag = MARK_TO_TAG[mark.type];
43379
+ if (tag) {
43380
+ open += `<${tag}>`;
43381
+ close = `</${tag}>${close}`;
43382
+ }
43383
+ }
43384
+ }
43385
+ return `${open}${text}${close}`;
43386
+ }
43387
+ // --- lists ----------------------------------------------------------------
43388
+ listToHtml(node) {
43389
+ const { tag, attrs } = this.listTag(node);
43390
+ const items = (node.content ?? []).map((item) => this.listItemToHtml(item, node.type === "taskList")).join("");
43391
+ return `<${tag}${attrs}>${items}</${tag}>`;
43392
+ }
43393
+ listTag(node) {
43394
+ const start = node.attrs?.start;
43395
+ const startAttr = typeof start === "number" && start !== 1 ? ` start="${start}"` : "";
43396
+ switch (node.type) {
43397
+ case "orderedList":
43398
+ return { tag: "ol", attrs: startAttr };
43399
+ case "orderedListRoman":
43400
+ return { tag: "ol", attrs: ` type="I"${startAttr}` };
43401
+ case "orderedListRomanLower":
43402
+ return { tag: "ol", attrs: ` type="i"${startAttr}` };
43403
+ case "letteredList":
43404
+ return { tag: "ol", attrs: ` type="A"${startAttr}` };
43405
+ case "letteredListLower":
43406
+ return { tag: "ol", attrs: ` type="a"${startAttr}` };
43407
+ case "noBulletList":
43408
+ return { tag: "ul", attrs: ' style="list-style:none"' };
43409
+ case "taskList":
43410
+ case "bulletList":
43411
+ default:
43412
+ return { tag: "ul", attrs: "" };
43413
+ }
43414
+ }
43415
+ listItemToHtml(item, task) {
43416
+ const inner = (item.content ?? []).map((b) => {
43417
+ if (b.type === "paragraph") return this.inlineToHtml(b.content ?? []);
43418
+ return this.blockToHtml(b);
43419
+ }).join("");
43420
+ if (task) {
43421
+ const checked = item.attrs?.checked ? " checked" : "";
43422
+ return `<li><input type="checkbox"${checked}>${inner}</li>`;
43423
+ }
43424
+ return `<li>${inner}</li>`;
43425
+ }
43426
+ // --- images ---------------------------------------------------------------
43427
+ imageToHtml(node) {
43428
+ const attrs = node.attrs ?? {};
43429
+ const parts = [];
43430
+ const src = attrs.src;
43431
+ parts.push(`src="${this.escapeAttr(typeof src === "string" ? src : "")}"`);
43432
+ if (typeof attrs.alt === "string") parts.push(`alt="${this.escapeAttr(attrs.alt)}"`);
43433
+ if (typeof attrs.title === "string") parts.push(`title="${this.escapeAttr(attrs.title)}"`);
43434
+ if (attrs.width != null) parts.push(`width="${attrs.width}"`);
43435
+ if (attrs.height != null) parts.push(`height="${attrs.height}"`);
43436
+ if (typeof attrs.class === "string" && attrs.class) {
43437
+ parts.push(`class="${this.escapeAttr(attrs.class)}"`);
43438
+ }
43439
+ return `<img ${parts.join(" ")}>`;
43440
+ }
43441
+ // --- escaping -------------------------------------------------------------
43442
+ escapeText(text) {
43443
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
43444
+ }
43445
+ escapeAttr(text) {
43446
+ return this.escapeText(text).replace(/"/g, "&quot;");
43447
+ }
43448
+ };
43449
+
43450
+ // src/parser/html/HtmlDom.ts
43451
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
43452
+ "area",
43453
+ "base",
43454
+ "br",
43455
+ "col",
43456
+ "embed",
43457
+ "hr",
43458
+ "img",
43459
+ "input",
43460
+ "link",
43461
+ "meta",
43462
+ "param",
43463
+ "source",
43464
+ "track",
43465
+ "wbr"
43466
+ ]);
43467
+ var IMPLIED_CLOSE = {
43468
+ li: /* @__PURE__ */ new Set(["li"]),
43469
+ td: /* @__PURE__ */ new Set(["td", "th"]),
43470
+ th: /* @__PURE__ */ new Set(["td", "th"]),
43471
+ tr: /* @__PURE__ */ new Set(["td", "th", "tr"]),
43472
+ thead: /* @__PURE__ */ new Set(["td", "th", "tr", "thead", "tbody", "tfoot"]),
43473
+ tbody: /* @__PURE__ */ new Set(["td", "th", "tr", "thead", "tbody", "tfoot"]),
43474
+ tfoot: /* @__PURE__ */ new Set(["td", "th", "tr", "thead", "tbody", "tfoot"]),
43475
+ p: /* @__PURE__ */ new Set(["p"]),
43476
+ option: /* @__PURE__ */ new Set(["option"])
43477
+ };
43478
+ var TAG_RE = /<(\/)?([a-zA-Z][a-zA-Z0-9-]*)((?:\s+(?:"[^"]*"|'[^']*'|[^<>"'])*)?)(\/)?>/g;
43479
+ var ATTR_RE = /([a-zA-Z_:][a-zA-Z0-9:._-]*)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s"'>]+))?/g;
43480
+ function parseAttrs(raw) {
43481
+ const attrs = {};
43482
+ if (!raw) return attrs;
43483
+ ATTR_RE.lastIndex = 0;
43484
+ let m;
43485
+ while ((m = ATTR_RE.exec(raw)) !== null) {
43486
+ const name = m[1].toLowerCase();
43487
+ let value = m[2] ?? "";
43488
+ if (value.length >= 2 && (value[0] === '"' || value[0] === "'")) {
43489
+ value = value.slice(1, -1);
43490
+ }
43491
+ attrs[name] = value;
43492
+ }
43493
+ return attrs;
43494
+ }
43495
+ function stripNonContent(html) {
43496
+ return html.replace(/<!--[\s\S]*?-->/g, "").replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, "").replace(/<!doctype[^>]*>/gi, "").replace(/<script\b[\s\S]*?<\/script>/gi, "").replace(/<style\b[\s\S]*?<\/style>/gi, "");
43497
+ }
43498
+ function tokenize(html) {
43499
+ const tokens = [];
43500
+ const clean = stripNonContent(html);
43501
+ TAG_RE.lastIndex = 0;
43502
+ let lastIndex = 0;
43503
+ let m;
43504
+ while ((m = TAG_RE.exec(clean)) !== null) {
43505
+ if (m.index > lastIndex) {
43506
+ tokens.push({ kind: "text", text: clean.slice(lastIndex, m.index) });
43507
+ }
43508
+ lastIndex = TAG_RE.lastIndex;
43509
+ const isClose = m[1] === "/";
43510
+ const name = m[2].toLowerCase();
43511
+ if (isClose) {
43512
+ tokens.push({ kind: "close", name });
43513
+ } else {
43514
+ tokens.push({
43515
+ kind: "open",
43516
+ name,
43517
+ attrs: parseAttrs(m[3]),
43518
+ selfClose: m[4] === "/"
43519
+ });
43520
+ }
43521
+ }
43522
+ if (lastIndex < clean.length) {
43523
+ tokens.push({ kind: "text", text: clean.slice(lastIndex) });
43524
+ }
43525
+ return tokens;
43526
+ }
43527
+ function parseHtml(html) {
43528
+ const root = { type: "element", name: "#root", attrs: {}, children: [] };
43529
+ const stack = [root];
43530
+ const top = () => stack[stack.length - 1];
43531
+ for (const token of tokenize(html)) {
43532
+ if (token.kind === "text") {
43533
+ if (token.text) top().children.push({ type: "text", value: token.text });
43534
+ continue;
43535
+ }
43536
+ if (token.kind === "open") {
43537
+ const name = token.name;
43538
+ const closes = IMPLIED_CLOSE[name];
43539
+ if (closes) {
43540
+ while (stack.length > 1 && closes.has(top().name)) stack.pop();
43541
+ }
43542
+ const el = {
43543
+ type: "element",
43544
+ name,
43545
+ attrs: token.attrs ?? {},
43546
+ children: []
43547
+ };
43548
+ top().children.push(el);
43549
+ if (!token.selfClose && !VOID_ELEMENTS.has(name)) {
43550
+ stack.push(el);
43551
+ }
43552
+ continue;
43553
+ }
43554
+ for (let i = stack.length - 1; i > 0; i--) {
43555
+ if (stack[i].name === token.name) {
43556
+ stack.length = i;
43557
+ break;
43558
+ }
43559
+ }
43560
+ }
43561
+ return root.children;
43562
+ }
43563
+ function childElements(el, names) {
43564
+ return el.children.filter((c) => c.type === "element" && names.has(c.name));
43565
+ }
43566
+
43567
+ // src/parser/html/HtmlTableParser.ts
43568
+ var MARK_TAGS = {
43569
+ b: "bold",
43570
+ strong: "bold",
43571
+ i: "italic",
43572
+ em: "italic",
43573
+ sup: "superscript",
43574
+ sub: "subscript",
43575
+ s: "strike",
43576
+ strike: "strike",
43577
+ del: "del",
43578
+ ins: "ins",
43579
+ u: "underline",
43580
+ mark: "highlight",
43581
+ code: "code"
43582
+ };
43583
+ var SECTION_TAGS = /* @__PURE__ */ new Set(["thead", "tbody", "tfoot"]);
43584
+ var ROW_TAGS = /* @__PURE__ */ new Set(["tr"]);
43585
+ var CELL_TAGS = /* @__PURE__ */ new Set(["td", "th"]);
43586
+ var LI_TAGS = /* @__PURE__ */ new Set(["li"]);
43587
+ var VALID_SCOPES = /* @__PURE__ */ new Set(["row", "col", "rowgroup", "colgroup"]);
43588
+ var NAMED_ENTITIES = {
43589
+ amp: "&",
43590
+ lt: "<",
43591
+ gt: ">",
43592
+ quot: '"',
43593
+ apos: "'",
43594
+ nbsp: "\xA0"
43595
+ };
43596
+ function decodeEntities(text) {
43597
+ return text.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);/g, (whole, body) => {
43598
+ if (body[0] === "#") {
43599
+ const code = body[1] === "x" || body[1] === "X" ? Number.parseInt(body.slice(2), 16) : Number.parseInt(body.slice(1), 10);
43600
+ if (Number.isFinite(code) && code >= 0 && code <= 1114111) {
43601
+ try {
43602
+ return String.fromCodePoint(code);
43603
+ } catch {
43604
+ return whole;
43605
+ }
43606
+ }
43607
+ return whole;
43608
+ }
43609
+ return NAMED_ENTITIES[body] ?? whole;
43610
+ });
43611
+ }
43612
+ function intAttr(value) {
43613
+ if (value == null) return void 0;
43614
+ const n = Number.parseInt(value, 10);
43615
+ return Number.isInteger(n) ? n : void 0;
43616
+ }
43617
+ function isElement(node) {
43618
+ return node.type === "element";
43619
+ }
43620
+ var HtmlTableParser2 = class {
43621
+ constructor() {
43622
+ __publicField(this, "keepUnknownTags", false);
43623
+ }
43624
+ /**
43625
+ * Parse an HTML string and return one table bit per top-level `<table>`.
43626
+ */
43627
+ parse(html, options) {
43628
+ this.keepUnknownTags = options?.keepUnknownTags ?? false;
43629
+ const tableFormat = options?.tableFormat ?? "table-extended";
43630
+ const onWarning = options?.onWarning;
43631
+ const tables = this.collectTopLevelTables(parseHtml(html));
43632
+ const bits = [];
43633
+ for (const table of tables) {
43634
+ const bit = this.tableToBit(table, tableFormat, onWarning);
43635
+ if (bit) bits.push(bit);
43636
+ }
43637
+ return bits;
43638
+ }
43639
+ // --- table extraction -----------------------------------------------------
43640
+ /** Collect every `<table>` element, NOT descending into nested tables. */
43641
+ collectTopLevelTables(nodes) {
43642
+ const tables = [];
43643
+ const visit = (node) => {
43644
+ if (!isElement(node)) return;
43645
+ if (node.name === "table") {
43646
+ tables.push(node);
43647
+ return;
43648
+ }
43649
+ node.children.forEach(visit);
43650
+ };
43651
+ nodes.forEach(visit);
43652
+ return tables;
43653
+ }
43654
+ tableToBit(table, tableFormat, onWarning) {
43655
+ const header = [];
43656
+ const body = [];
43657
+ const footer = [];
43658
+ let caption;
43659
+ for (const child of table.children) {
43660
+ if (!isElement(child)) continue;
43661
+ if (child.name === "caption") {
43662
+ const capContent = this.inlineNodes(child.children, []);
43663
+ const trimmed = this.trimInline(capContent);
43664
+ if (trimmed.length > 0) caption = trimmed;
43665
+ } else if (SECTION_TAGS.has(child.name)) {
43666
+ const target = child.name === "thead" ? header : child.name === "tfoot" ? footer : body;
43667
+ for (const tr of childElements(child, ROW_TAGS)) {
43668
+ target.push(this.rowToCells(tr));
43669
+ }
43670
+ } else if (ROW_TAGS.has(child.name)) {
43671
+ body.push(this.rowToCells(child));
43672
+ }
43673
+ }
43674
+ if (header.length === 0 && body.length === 0 && footer.length === 0) {
43675
+ return void 0;
43676
+ }
43677
+ const tableExtended = {};
43678
+ if (header.length > 0) tableExtended.header = { rows: header };
43679
+ if (body.length > 0) tableExtended.body = { rows: body };
43680
+ if (footer.length > 0) tableExtended.footer = { rows: footer };
43681
+ let tableData = tableExtended;
43682
+ if (tableFormat === "table") {
43683
+ if (this.isLossyAsBasic(tableExtended)) {
43684
+ onWarning?.(
43685
+ "Converting an HTML table to [.table] loses rowspan/colspan/scope and multi-section structure; use --tableFormat table-extended to preserve them."
43686
+ );
43687
+ }
43688
+ tableData = convertExtendedToBasicTableFormat(tableExtended);
43689
+ }
43690
+ const bit = {
43691
+ type: tableFormat,
43692
+ format: "bitmark++",
43693
+ table: tableData
43694
+ };
43695
+ if (caption) bit.caption = caption;
43696
+ return bit;
43697
+ }
43698
+ rowToCells(tr) {
43699
+ const cells = [];
43700
+ for (const cell of childElements(tr, CELL_TAGS)) {
43701
+ cells.push(this.cellToJson(cell));
43702
+ }
43703
+ return { cells };
43704
+ }
43705
+ cellToJson(cell) {
43706
+ const json = {
43707
+ content: this.blockNodes(cell.children)
43708
+ };
43709
+ if (cell.name === "th") json.title = true;
43710
+ const rowspan = intAttr(cell.attrs.rowspan);
43711
+ if (rowspan != null && rowspan >= 2) json.rowspan = rowspan;
43712
+ const colspan = intAttr(cell.attrs.colspan);
43713
+ if (colspan != null && colspan >= 2) json.colspan = colspan;
43714
+ const scope = cell.attrs.scope?.toLowerCase();
43715
+ if (scope && VALID_SCOPES.has(scope)) {
43716
+ json.scope = scope;
43717
+ }
43718
+ const width = this.widthFromCell(cell);
43719
+ if (width != null) json.colwidth = width;
43720
+ return json;
43721
+ }
43722
+ widthFromCell(cell) {
43723
+ const attrWidth = intAttr(cell.attrs.width);
43724
+ if (attrWidth != null && attrWidth > 0) return attrWidth;
43725
+ const style = cell.attrs.style;
43726
+ if (style) {
43727
+ const m = style.match(/width\s*:\s*(\d+)\s*px/i);
43728
+ if (m) {
43729
+ const n = Number.parseInt(m[1], 10);
43730
+ if (Number.isInteger(n) && n > 0) return n;
43731
+ }
43732
+ }
43733
+ return void 0;
43734
+ }
43735
+ isLossyAsBasic(table) {
43736
+ if (table.footer) return true;
43737
+ if (table.header && table.header.rows.length > 1) return true;
43738
+ const sections = [table.header, table.body, table.footer];
43739
+ for (const section of sections) {
43740
+ if (!section) continue;
43741
+ for (const row of section.rows) {
43742
+ for (const cell of row.cells) {
43743
+ if (cell.rowspan || cell.colspan || cell.scope) return true;
43744
+ }
43745
+ }
43746
+ }
43747
+ return false;
43748
+ }
43749
+ // --- content conversion (HTML -> TextAst) ---------------------------------
43750
+ /**
43751
+ * Convert a cell/li's child nodes into block-level TextAst nodes (paragraphs, lists, images).
43752
+ */
43753
+ blockNodes(nodes) {
43754
+ const blocks = [];
43755
+ let inline = [];
43756
+ const flush = () => {
43757
+ const trimmed = this.trimInline(inline);
43758
+ inline = [];
43759
+ if (trimmed.length === 0) return;
43760
+ if (trimmed.length === 1 && trimmed[0].type === "imageInline") {
43761
+ blocks.push({ ...trimmed[0], type: "image" });
43762
+ } else {
43763
+ blocks.push({ type: "paragraph", content: trimmed, attrs: {} });
43764
+ }
43765
+ };
43766
+ for (const node of nodes) {
43767
+ if (!isElement(node)) {
43768
+ inline.push(...this.inlineText(node.value, []));
43769
+ continue;
43770
+ }
43771
+ const name = node.name;
43772
+ if (name === "p") {
43773
+ flush();
43774
+ const content = this.trimInline(this.inlineNodes(node.children, []));
43775
+ if (content.length > 0) {
43776
+ blocks.push({ type: "paragraph", content, attrs: {} });
43777
+ }
43778
+ } else if (this.isListTag(name)) {
43779
+ flush();
43780
+ const list = this.listNode(node);
43781
+ if (list) blocks.push(list);
43782
+ } else {
43783
+ inline.push(...this.inlineFromElement(node, []));
43784
+ }
43785
+ }
43786
+ flush();
43787
+ return blocks;
43788
+ }
43789
+ /** Convert child nodes to a flat list of inline TextNodes, applying the given marks. */
43790
+ inlineNodes(nodes, marks) {
43791
+ const out = [];
43792
+ for (const node of nodes) {
43793
+ if (!isElement(node)) {
43794
+ out.push(...this.inlineText(node.value, marks));
43795
+ } else {
43796
+ out.push(...this.inlineFromElement(node, marks));
43797
+ }
43798
+ }
43799
+ return out;
43800
+ }
43801
+ inlineFromElement(el, marks) {
43802
+ const name = el.name;
43803
+ if (name === "br") {
43804
+ return [{ type: "hardBreak" }];
43805
+ }
43806
+ if (name === "img") {
43807
+ return [this.imageNode(el, true)];
43808
+ }
43809
+ const markType = MARK_TAGS[name];
43810
+ if (markType) {
43811
+ return this.inlineNodes(el.children, [...marks, { type: markType }]);
43812
+ }
43813
+ if (name === "a") {
43814
+ const linkMark = {
43815
+ type: "link",
43816
+ attrs: {
43817
+ href: el.attrs.href ?? "",
43818
+ ...el.attrs.target ? { target: el.attrs.target } : {}
43819
+ }
43820
+ };
43821
+ return this.inlineNodes(el.children, [...marks, linkMark]);
43822
+ }
43823
+ if (this.keepUnknownTags) {
43824
+ const open = this.serializeOpenTag(el);
43825
+ const close = `</${name}>`;
43826
+ return [
43827
+ ...this.inlineText(open, marks),
43828
+ ...this.inlineNodes(el.children, marks),
43829
+ ...this.inlineText(close, marks)
43830
+ ];
43831
+ }
43832
+ return this.inlineNodes(el.children, marks);
43833
+ }
43834
+ inlineText(raw, marks) {
43835
+ const text = decodeEntities(raw).replace(/\s+/g, " ");
43836
+ if (text === "") return [];
43837
+ const node = { text, type: "text" };
43838
+ if (marks.length > 0) node.marks = marks.map((m) => ({ ...m }));
43839
+ return [node];
43840
+ }
43841
+ serializeOpenTag(el) {
43842
+ const attrs = Object.entries(el.attrs).map(([k, v]) => v === "" ? ` ${k}` : ` ${k}="${v}"`).join("");
43843
+ return `<${el.name}${attrs}>`;
43844
+ }
43845
+ // --- lists ----------------------------------------------------------------
43846
+ isListTag(name) {
43847
+ return name === "ul" || name === "ol";
43848
+ }
43849
+ listNode(el) {
43850
+ const items = childElements(el, LI_TAGS);
43851
+ if (items.length === 0) return void 0;
43852
+ const isTask = el.name === "ul" && items.some((li) => {
43853
+ const firstEl = li.children.find(isElement);
43854
+ return firstEl?.name === "input" && firstEl.attrs.type?.toLowerCase() === "checkbox";
43855
+ });
43856
+ if (isTask) {
43857
+ return {
43858
+ type: "taskList",
43859
+ content: items.map((li) => this.taskItemNode(li))
43860
+ };
43861
+ }
43862
+ const type = this.listType(el);
43863
+ const node = {
43864
+ type,
43865
+ content: items.map((li) => this.listItemNode(li))
43866
+ };
43867
+ if (el.name === "ol") {
43868
+ const start = intAttr(el.attrs.start);
43869
+ if (start != null) {
43870
+ node.attrs = { start };
43871
+ }
43872
+ }
43873
+ return node;
43874
+ }
43875
+ listType(el) {
43876
+ if (el.name === "ol") {
43877
+ switch (el.attrs.type) {
43878
+ case "i":
43879
+ return "orderedListRomanLower";
43880
+ case "I":
43881
+ return "orderedListRoman";
43882
+ case "a":
43883
+ return "letteredListLower";
43884
+ case "A":
43885
+ return "letteredList";
43886
+ default:
43887
+ return "orderedList";
43888
+ }
43889
+ }
43890
+ const style = el.attrs.style ?? "";
43891
+ if (/list-style(-type)?\s*:\s*none/i.test(style)) return "noBulletList";
43892
+ return "bulletList";
43893
+ }
43894
+ listItemNode(li) {
43895
+ let content = this.blockNodes(li.children);
43896
+ if (content.length === 0) {
43897
+ content = [{ type: "paragraph", content: [], attrs: {} }];
43898
+ }
43899
+ return { type: "listItem", content };
43900
+ }
43901
+ taskItemNode(li) {
43902
+ const checkbox = li.children.find(
43903
+ (c) => isElement(c) && c.name === "input" && c.attrs.type?.toLowerCase() === "checkbox"
43904
+ );
43905
+ const checked = checkbox ? "checked" in checkbox.attrs : false;
43906
+ const rest = li.children.filter((c) => c !== checkbox);
43907
+ let content = this.blockNodes(rest);
43908
+ if (content.length === 0) {
43909
+ content = [{ type: "paragraph", content: [], attrs: {} }];
43910
+ }
43911
+ return { type: "taskItem", attrs: { checked }, content };
43912
+ }
43913
+ // --- images ---------------------------------------------------------------
43914
+ imageNode(el, inline) {
43915
+ const attrs = { src: el.attrs.src ?? "" };
43916
+ attrs.alt = el.attrs.alt ?? null;
43917
+ attrs.title = el.attrs.title ?? null;
43918
+ const width = intAttr(el.attrs.width);
43919
+ if (width != null) attrs.width = width;
43920
+ const height = intAttr(el.attrs.height);
43921
+ if (height != null) attrs.height = height;
43922
+ if (el.attrs.class) attrs.class = el.attrs.class;
43923
+ return { type: inline ? "imageInline" : "image", attrs };
43924
+ }
43925
+ // --- whitespace -----------------------------------------------------------
43926
+ /** Trim leading/trailing whitespace from inline content (edges only). */
43927
+ trimInline(nodes) {
43928
+ const out = nodes.slice();
43929
+ const isWs = (n) => n.type === "text" && /^\s*$/.test(n.text ?? "");
43930
+ while (out.length > 0 && isWs(out[0])) out.shift();
43931
+ if (out.length > 0 && out[0].type === "text") {
43932
+ out[0] = { ...out[0], text: (out[0].text ?? "").replace(/^\s+/, "") };
43933
+ }
43934
+ while (out.length > 0 && isWs(out[out.length - 1])) out.pop();
43935
+ if (out.length > 0 && out[out.length - 1].type === "text") {
43936
+ const last = out.length - 1;
43937
+ out[last] = { ...out[last], text: (out[last].text ?? "").replace(/\s+$/, "") };
43938
+ }
43939
+ return out.filter((n) => !(n.type === "text" && n.text === ""));
43940
+ }
43941
+ };
43942
+
42924
43943
  // src/index.ts
42925
43944
  init();
42926
43945
  export {
@@ -42936,6 +43955,8 @@ export {
42936
43955
  BoundingBoxIndex,
42937
43956
  Builder,
42938
43957
  CardSetVersion,
43958
+ HtmlTableGenerator2 as HtmlTableGenerator,
43959
+ HtmlTableParser2 as HtmlTableParser,
42939
43960
  InfoFormat,
42940
43961
  InfoType,
42941
43962
  Input,