@gmb/bitmark-parser 6.3.0 → 6.3.1

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/index.d.cts CHANGED
@@ -14124,10 +14124,19 @@ declare class Builder {
14124
14124
  * (inline marks become TextAst marks); the composer would otherwise treat
14125
14125
  * them as literal text. Converts top-level JsonText fields in place.
14126
14126
  * Nested (card-content) strings are left literal — documented divergence.
14127
+ *
14128
+ * A string body is dispatched on the bit's resolved text format, as bpg's
14129
+ * buildBody: bitmark text is parsed to TextAst, `json` is JSON.parsed
14130
+ * (unparseable → null), and plain-text formats (text/latex/xml) stay
14131
+ * verbatim. Tag texts are always bitmark text, independent of body format
14132
+ * (bpg TextParser.toAst ignores format; only location matters).
14127
14133
  */
14128
14134
  private parseStringTexts;
14129
- /** Throw bpg's exact unknown-bit-type error (`Config.getBitConfig` parity). */
14130
- private assertKnownBitType;
14135
+ /**
14136
+ * Look up the bit's config (`wasm.info`); throws bpg's exact
14137
+ * unknown-bit-type error (`Config.getBitConfig` parity).
14138
+ */
14139
+ private getBitConfig;
14131
14140
  }
14132
14141
 
14133
14142
  type ResourceMethod = (context: unknown, data: Record<string, unknown> | undefined, __typeAlias?: string) => Record<string, unknown> | undefined;
package/dist/index.d.ts CHANGED
@@ -14124,10 +14124,19 @@ declare class Builder {
14124
14124
  * (inline marks become TextAst marks); the composer would otherwise treat
14125
14125
  * them as literal text. Converts top-level JsonText fields in place.
14126
14126
  * Nested (card-content) strings are left literal — documented divergence.
14127
+ *
14128
+ * A string body is dispatched on the bit's resolved text format, as bpg's
14129
+ * buildBody: bitmark text is parsed to TextAst, `json` is JSON.parsed
14130
+ * (unparseable → null), and plain-text formats (text/latex/xml) stay
14131
+ * verbatim. Tag texts are always bitmark text, independent of body format
14132
+ * (bpg TextParser.toAst ignores format; only location matters).
14127
14133
  */
14128
14134
  private parseStringTexts;
14129
- /** Throw bpg's exact unknown-bit-type error (`Config.getBitConfig` parity). */
14130
- private assertKnownBitType;
14135
+ /**
14136
+ * Look up the bit's config (`wasm.info`); throws bpg's exact
14137
+ * unknown-bit-type error (`Config.getBitConfig` parity).
14138
+ */
14139
+ private getBitConfig;
14131
14140
  }
14132
14141
 
14133
14142
  type ResourceMethod = (context: unknown, data: Record<string, unknown> | undefined, __typeAlias?: string) => Record<string, unknown> | undefined;
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { createRequire } from "module";
10
10
  // src/generated/package_info.ts
11
11
  var PACKAGE_INFO = {
12
12
  "name": "@gmb/bitmark-parser",
13
- "version": "6.3.0",
13
+ "version": "6.3.1",
14
14
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
15
15
  "license": "ISC",
16
16
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -379,6 +379,13 @@ var DEPRECATED_TEXT_FORMATS = {
379
379
  "bitmark--": "bitmark++",
380
380
  "bitmark+": "bitmark++"
381
381
  };
382
+ var CONFIG_BODY_FORMAT_TO_TEXT_FORMAT = {
383
+ bitmark: "bitmark++",
384
+ text: "text",
385
+ json: "json",
386
+ latex: "latex",
387
+ xml: "xml"
388
+ };
382
389
  var TAG_TEXT_KEYS = [
383
390
  "title",
384
391
  "subtitle",
@@ -424,7 +431,7 @@ var Builder = class {
424
431
  const wasm2 = getLegacyWasm();
425
432
  const src = { ...data };
426
433
  const bitType = src.bitType;
427
- this.assertKnownBitType(bitType);
434
+ const bitConfig = this.getBitConfig(bitType);
428
435
  const bit = {};
429
436
  bit.type = bitType;
430
437
  if (src.isCommented) {
@@ -437,6 +444,8 @@ var Builder = class {
437
444
  if (textFormat !== void 0) {
438
445
  bit.format = DEPRECATED_TEXT_FORMATS[textFormat] ?? textFormat;
439
446
  delete src.textFormat;
447
+ } else {
448
+ bit.format = CONFIG_BODY_FORMAT_TO_TEXT_FORMAT[bitConfig.bodyFormat ?? ""] ?? "bitmark++";
440
449
  }
441
450
  delete src.resourceType;
442
451
  const body = src.body;
@@ -528,6 +537,12 @@ var Builder = class {
528
537
  * (inline marks become TextAst marks); the composer would otherwise treat
529
538
  * them as literal text. Converts top-level JsonText fields in place.
530
539
  * Nested (card-content) strings are left literal — documented divergence.
540
+ *
541
+ * A string body is dispatched on the bit's resolved text format, as bpg's
542
+ * buildBody: bitmark text is parsed to TextAst, `json` is JSON.parsed
543
+ * (unparseable → null), and plain-text formats (text/latex/xml) stay
544
+ * verbatim. Tag texts are always bitmark text, independent of body format
545
+ * (bpg TextParser.toAst ignores format; only location matters).
531
546
  */
532
547
  parseStringTexts(bit) {
533
548
  const wasm2 = getLegacyWasm();
@@ -542,29 +557,36 @@ var Builder = class {
542
557
  };
543
558
  const format = bit.format;
544
559
  const bitmarkBody = format === void 0 || format === "bitmark++" || format === "bitmark+";
545
- if (typeof bit.body === "string" && bitmarkBody) {
546
- bit.body = toAst(bit.body, "body");
560
+ if (typeof bit.body === "string") {
561
+ if (format === "json") {
562
+ try {
563
+ bit.body = JSON.parse(bit.body);
564
+ } catch {
565
+ bit.body = null;
566
+ }
567
+ } else if (bitmarkBody) {
568
+ bit.body = toAst(bit.body, "body");
569
+ }
547
570
  }
548
571
  for (const key of TAG_TEXT_KEYS) {
549
572
  const v = bit[key];
550
573
  if (typeof v === "string") bit[key] = toAst(v, "tag");
551
574
  }
552
575
  }
553
- /** Throw bpg's exact unknown-bit-type error (`Config.getBitConfig` parity). */
554
- assertKnownBitType(bitType) {
576
+ /**
577
+ * Look up the bit's config (`wasm.info`); throws bpg's exact
578
+ * unknown-bit-type error (`Config.getBitConfig` parity).
579
+ */
580
+ getBitConfig(bitType) {
555
581
  const wasm2 = getLegacyWasm();
556
- let known = false;
557
582
  if (bitType !== void 0) {
558
583
  try {
559
584
  const info2 = JSON.parse(wasm2.info("bit", "json", bitType, false, 2));
560
- known = info2.error === void 0;
585
+ if (info2.error === void 0) return info2;
561
586
  } catch {
562
- known = false;
563
587
  }
564
588
  }
565
- if (!known) {
566
- throw new Error(`No config found for bit: ${bitType}`);
567
- }
589
+ throw new Error(`No config found for bit: ${bitType}`);
568
590
  }
569
591
  };
570
592
  function stripUndefined(src, exclude) {