@podlite/markdown 0.0.50 → 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
@@ -22456,6 +22456,69 @@ var makeAttrs = (node, ctx = {}) => {
22456
22456
  };
22457
22457
  var config_default = makeAttrs;
22458
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
+
22459
22522
  // ../podlite-schema/esm/helpers/makeInterator.js
22460
22523
  function flattenDeep(arr) {
22461
22524
  if (!Array.isArray(arr)) {
@@ -22667,7 +22730,7 @@ var toAny = (options = {}, plugins = []) => {
22667
22730
  let newFns = fns.slice();
22668
22731
  newFns.reverse();
22669
22732
  const interator = makeInterator_default(newFns.map((rule) => makeRule(rule.rule, rule.fn(writer, processor, tree))).reverse());
22670
- const context = { ...options.context || {} };
22733
+ const context = { __anchors: indexAnchors(tree), ...options.context || {} };
22671
22734
  writer.startWrite(tree);
22672
22735
  const result = interator(tree, context);
22673
22736
  writer.endWrite();
@@ -23490,25 +23553,19 @@ var plugin_tables_default = () => (tree) => {
23490
23553
  const makeCell = (text4) => makeBlock("cell", { type: "text", value: text4 });
23491
23554
  const columnTemplate = makeMask(lines, separators);
23492
23555
  const seenSeparatorKinds = new Set(lines.map(detectLineSeparator));
23493
- const hasVisible = seenSeparatorKinds.has("pipe") || seenSeparatorKinds.has("plus");
23494
- const hasWhitespace = seenSeparatorKinds.has("whitespace");
23495
- const useMixedSplitting = hasVisible && hasWhitespace;
23556
+ const useMixedSplitting = (seenSeparatorKinds.has("pipe") || seenSeparatorKinds.has("plus")) && seenSeparatorKinds.has("whitespace");
23557
+ const splitsItself = (line) => useMixedSplitting || detectLineSeparator(line) === "whitespace";
23496
23558
  const splitToCells = (rowValue) => {
23497
- if (useMixedSplitting) {
23498
- const rowLines = rowValue.split(/\r?\n/).filter((l) => l.trim() !== "");
23499
- if (rowLines.length <= 1)
23500
- return rowToCells(rowValue);
23501
- }
23559
+ const rowLines = rowValue.split(/\r?\n/).filter((l) => l.trim() !== "");
23560
+ if (rowLines.length <= 1 && splitsItself(rowValue))
23561
+ return rowToCells(rowValue);
23502
23562
  return extractColumnsByTemplate(rowValue, columnTemplate);
23503
23563
  };
23504
23564
  const res = makeTransformer_default({
23505
23565
  "row:text": (row) => {
23506
23566
  if (textRows.length == 1) {
23507
23567
  const textRowsLines = flattenDeep3([row.value].map(splitToLines));
23508
- if (useMixedSplitting) {
23509
- return textRowsLines.map((line) => makeRow(splitLineCells(line).map(makeCell)));
23510
- }
23511
- 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)));
23512
23569
  }
23513
23570
  return makeRow(splitToCells(row.value).map(makeCell));
23514
23571
  },