@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.
Binary file
@@ -474,7 +474,7 @@ var bitmark_wasm_default = __wbg_init;
474
474
  // src/generated/package_info.ts
475
475
  var PACKAGE_INFO = {
476
476
  "name": "@gmb/bitmark-parser",
477
- "version": "6.3.0",
477
+ "version": "6.3.1",
478
478
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
479
479
  "license": "ISC",
480
480
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -807,6 +807,13 @@ var DEPRECATED_TEXT_FORMATS = {
807
807
  "bitmark--": "bitmark++",
808
808
  "bitmark+": "bitmark++"
809
809
  };
810
+ var CONFIG_BODY_FORMAT_TO_TEXT_FORMAT = {
811
+ bitmark: "bitmark++",
812
+ text: "text",
813
+ json: "json",
814
+ latex: "latex",
815
+ xml: "xml"
816
+ };
810
817
  var TAG_TEXT_KEYS = [
811
818
  "title",
812
819
  "subtitle",
@@ -852,7 +859,7 @@ var Builder = class {
852
859
  const wasm2 = getLegacyWasm();
853
860
  const src = { ...data };
854
861
  const bitType = src.bitType;
855
- this.assertKnownBitType(bitType);
862
+ const bitConfig = this.getBitConfig(bitType);
856
863
  const bit = {};
857
864
  bit.type = bitType;
858
865
  if (src.isCommented) {
@@ -865,6 +872,8 @@ var Builder = class {
865
872
  if (textFormat !== void 0) {
866
873
  bit.format = DEPRECATED_TEXT_FORMATS[textFormat] ?? textFormat;
867
874
  delete src.textFormat;
875
+ } else {
876
+ bit.format = CONFIG_BODY_FORMAT_TO_TEXT_FORMAT[bitConfig.bodyFormat ?? ""] ?? "bitmark++";
868
877
  }
869
878
  delete src.resourceType;
870
879
  const body = src.body;
@@ -956,6 +965,12 @@ var Builder = class {
956
965
  * (inline marks become TextAst marks); the composer would otherwise treat
957
966
  * them as literal text. Converts top-level JsonText fields in place.
958
967
  * Nested (card-content) strings are left literal — documented divergence.
968
+ *
969
+ * A string body is dispatched on the bit's resolved text format, as bpg's
970
+ * buildBody: bitmark text is parsed to TextAst, `json` is JSON.parsed
971
+ * (unparseable → null), and plain-text formats (text/latex/xml) stay
972
+ * verbatim. Tag texts are always bitmark text, independent of body format
973
+ * (bpg TextParser.toAst ignores format; only location matters).
959
974
  */
960
975
  parseStringTexts(bit) {
961
976
  const wasm2 = getLegacyWasm();
@@ -970,29 +985,36 @@ var Builder = class {
970
985
  };
971
986
  const format = bit.format;
972
987
  const bitmarkBody = format === void 0 || format === "bitmark++" || format === "bitmark+";
973
- if (typeof bit.body === "string" && bitmarkBody) {
974
- bit.body = toAst(bit.body, "body");
988
+ if (typeof bit.body === "string") {
989
+ if (format === "json") {
990
+ try {
991
+ bit.body = JSON.parse(bit.body);
992
+ } catch {
993
+ bit.body = null;
994
+ }
995
+ } else if (bitmarkBody) {
996
+ bit.body = toAst(bit.body, "body");
997
+ }
975
998
  }
976
999
  for (const key of TAG_TEXT_KEYS) {
977
1000
  const v = bit[key];
978
1001
  if (typeof v === "string") bit[key] = toAst(v, "tag");
979
1002
  }
980
1003
  }
981
- /** Throw bpg's exact unknown-bit-type error (`Config.getBitConfig` parity). */
982
- assertKnownBitType(bitType) {
1004
+ /**
1005
+ * Look up the bit's config (`wasm.info`); throws bpg's exact
1006
+ * unknown-bit-type error (`Config.getBitConfig` parity).
1007
+ */
1008
+ getBitConfig(bitType) {
983
1009
  const wasm2 = getLegacyWasm();
984
- let known = false;
985
1010
  if (bitType !== void 0) {
986
1011
  try {
987
1012
  const info3 = JSON.parse(wasm2.info("bit", "json", bitType, false, 2));
988
- known = info3.error === void 0;
1013
+ if (info3.error === void 0) return info3;
989
1014
  } catch {
990
- known = false;
991
1015
  }
992
1016
  }
993
- if (!known) {
994
- throw new Error(`No config found for bit: ${bitType}`);
995
- }
1017
+ throw new Error(`No config found for bit: ${bitType}`);
996
1018
  }
997
1019
  };
998
1020
  function stripUndefined(src, exclude) {