@podlite/markdown 0.0.49 → 0.0.51

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/lib/index.esm.js CHANGED
@@ -18738,14 +18738,20 @@ var require_grammarfc = __commonJS({
18738
18738
  s3 = [];
18739
18739
  s4 = peg$parsecode_C();
18740
18740
  if (s4 === peg$FAILED) {
18741
- s4 = peg$parsetext_L();
18741
+ s4 = peg$parsecode_2();
18742
+ if (s4 === peg$FAILED) {
18743
+ s4 = peg$parsetext_L();
18744
+ }
18742
18745
  }
18743
18746
  if (s4 !== peg$FAILED) {
18744
18747
  while (s4 !== peg$FAILED) {
18745
18748
  s3.push(s4);
18746
18749
  s4 = peg$parsecode_C();
18747
18750
  if (s4 === peg$FAILED) {
18748
- s4 = peg$parsetext_L();
18751
+ s4 = peg$parsecode_2();
18752
+ if (s4 === peg$FAILED) {
18753
+ s4 = peg$parsetext_L();
18754
+ }
18749
18755
  }
18750
18756
  }
18751
18757
  } else {
@@ -22450,6 +22456,69 @@ var makeAttrs = (node, ctx = {}) => {
22450
22456
  };
22451
22457
  var config_default = makeAttrs;
22452
22458
 
22459
+ // ../podlite-schema/esm/ast-helpers.js
22460
+ var getNodeId = (node, ctx) => {
22461
+ const conf = config_default(node, ctx);
22462
+ if (conf.exists("id")) {
22463
+ return conf.getFirstValue("id");
22464
+ }
22465
+ return node.id;
22466
+ };
22467
+ var toFragment = (value) => {
22468
+ const collapsed = value.trim().split(/[\s\-\u2013\u2014]+/).filter(Boolean).join("-");
22469
+ const cleaned = collapsed.replace(/[^\p{L}\p{N}\-_]/gu, "");
22470
+ return cleaned.replace(/^-+|-+$/g, "");
22471
+ };
22472
+ var htmlStyle = { shape: toFragment, firstRepeat: 2 };
22473
+ var takeUnique = (fragment, taken, firstRepeat) => {
22474
+ if (!fragment)
22475
+ return fragment;
22476
+ let result = fragment;
22477
+ while (taken.has(result)) {
22478
+ const used = (taken.get(fragment) || 0) + 1;
22479
+ taken.set(fragment, used);
22480
+ result = `${fragment}-${used + firstRepeat - 1}`;
22481
+ }
22482
+ taken.set(result, taken.get(result) || 0);
22483
+ return result;
22484
+ };
22485
+ var walkNodes = (node, visit) => {
22486
+ if (Array.isArray(node)) {
22487
+ for (const child of node)
22488
+ walkNodes(child, visit);
22489
+ return;
22490
+ }
22491
+ if (!node || typeof node !== "object")
22492
+ return;
22493
+ visit(node);
22494
+ if ("content" in node)
22495
+ walkNodes(node.content, visit);
22496
+ };
22497
+ var assignAnchors = (heads, style) => {
22498
+ const byNode = /* @__PURE__ */ new Map();
22499
+ const byName = /* @__PURE__ */ new Map();
22500
+ const taken = /* @__PURE__ */ new Map();
22501
+ for (const node of heads) {
22502
+ const id = getNodeId(node, {});
22503
+ if (id == null)
22504
+ continue;
22505
+ const name = id.toString();
22506
+ const anchor = takeUnique(style.shape(name), taken, style.firstRepeat);
22507
+ byNode.set(node, anchor);
22508
+ if (!byName.has(name))
22509
+ byName.set(name, anchor);
22510
+ }
22511
+ return { byNode, byName, shape: style.shape };
22512
+ };
22513
+ var indexAnchors = (tree, style = htmlStyle) => {
22514
+ const heads = [];
22515
+ walkNodes(tree, (node) => {
22516
+ if (node.name === "head")
22517
+ heads.push(node);
22518
+ });
22519
+ return assignAnchors(heads, style);
22520
+ };
22521
+
22453
22522
  // ../podlite-schema/esm/helpers/makeInterator.js
22454
22523
  function flattenDeep(arr) {
22455
22524
  if (!Array.isArray(arr)) {
@@ -22661,7 +22730,7 @@ var toAny = (options = {}, plugins = []) => {
22661
22730
  let newFns = fns.slice();
22662
22731
  newFns.reverse();
22663
22732
  const interator = makeInterator_default(newFns.map((rule) => makeRule(rule.rule, rule.fn(writer, processor, tree))).reverse());
22664
- const context = { ...options.context || {} };
22733
+ const context = { __anchors: indexAnchors(tree), ...options.context || {} };
22665
22734
  writer.startWrite(tree);
22666
22735
  const result = interator(tree, context);
22667
22736
  writer.endWrite();
@@ -23484,25 +23553,19 @@ var plugin_tables_default = () => (tree) => {
23484
23553
  const makeCell = (text4) => makeBlock("cell", { type: "text", value: text4 });
23485
23554
  const columnTemplate = makeMask(lines, separators);
23486
23555
  const seenSeparatorKinds = new Set(lines.map(detectLineSeparator));
23487
- const hasVisible = seenSeparatorKinds.has("pipe") || seenSeparatorKinds.has("plus");
23488
- const hasWhitespace = seenSeparatorKinds.has("whitespace");
23489
- const useMixedSplitting = hasVisible && hasWhitespace;
23556
+ const useMixedSplitting = (seenSeparatorKinds.has("pipe") || seenSeparatorKinds.has("plus")) && seenSeparatorKinds.has("whitespace");
23557
+ const splitsItself = (line) => useMixedSplitting || detectLineSeparator(line) === "whitespace";
23490
23558
  const splitToCells = (rowValue) => {
23491
- if (useMixedSplitting) {
23492
- const rowLines = rowValue.split(/\r?\n/).filter((l) => l.trim() !== "");
23493
- if (rowLines.length <= 1)
23494
- return rowToCells(rowValue);
23495
- }
23559
+ const rowLines = rowValue.split(/\r?\n/).filter((l) => l.trim() !== "");
23560
+ if (rowLines.length <= 1 && splitsItself(rowValue))
23561
+ return rowToCells(rowValue);
23496
23562
  return extractColumnsByTemplate(rowValue, columnTemplate);
23497
23563
  };
23498
23564
  const res = makeTransformer_default({
23499
23565
  "row:text": (row) => {
23500
23566
  if (textRows.length == 1) {
23501
23567
  const textRowsLines = flattenDeep3([row.value].map(splitToLines));
23502
- if (useMixedSplitting) {
23503
- return textRowsLines.map((line) => makeRow(splitLineCells(line).map(makeCell)));
23504
- }
23505
- return textRowsLines.map((line) => makeRow(extractColumnsByTemplate(line, columnTemplate).map(makeCell)));
23568
+ return textRowsLines.map((line) => makeRow((splitsItself(line) ? splitLineCells(line) : extractColumnsByTemplate(line, columnTemplate)).map(makeCell)));
23506
23569
  }
23507
23570
  return makeRow(splitToCells(row.value).map(makeCell));
23508
23571
  },