mrkdwn.js 7.0.1 → 8.0.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.
@@ -92,12 +92,13 @@ function emitCellTag(cell, isHeader, context) {
92
92
  return `<${tag}${attrs.length > 0 ? ` ${attrs.join(" ")}` : ""}>${emitCellHtml(cell, context)}</${tag}>`;
93
93
  }
94
94
  function emitHtmlTable(table, context) {
95
- const [header, ...body] = table.rows;
96
- const lines = ["<table>"];
97
- if (header !== void 0) lines.push(`<tr>${header.cells.map((cell) => emitCellTag(cell, true, context)).join("")}</tr>`);
98
- for (const row of body) lines.push(`<tr>${row.cells.map((cell) => emitCellTag(cell, false, context)).join("")}</tr>`);
99
- lines.push("</table>");
100
- return lines.join("\n");
95
+ return [
96
+ "<table>",
97
+ ...(0, document_schema_js.walkTableGrid)(table).map((positions, rowIndex) => {
98
+ return `<tr>${positions.flatMap((position) => position.anchorRowIndex === void 0 ? [emitCellTag(position.cell, rowIndex === 0, context)] : []).join("")}</tr>`;
99
+ }),
100
+ "</table>"
101
+ ].join("\n");
101
102
  }
102
103
  //#endregion
103
104
  exports.emitHtmlTable = emitHtmlTable;
@@ -1,6 +1,6 @@
1
1
  import { MarkdownDiagnosticCodes } from "../diagnostics/diagnostics.js";
2
2
  import "../shared/style-constants.js";
3
- import { colorToRgbHex } from "document-schema.js";
3
+ import { colorToRgbHex, walkTableGrid } from "document-schema.js";
4
4
  //#region src/emit/html-table.ts
5
5
  function escapeHtmlText(text) {
6
6
  return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
@@ -91,12 +91,13 @@ function emitCellTag(cell, isHeader, context) {
91
91
  return `<${tag}${attrs.length > 0 ? ` ${attrs.join(" ")}` : ""}>${emitCellHtml(cell, context)}</${tag}>`;
92
92
  }
93
93
  function emitHtmlTable(table, context) {
94
- const [header, ...body] = table.rows;
95
- const lines = ["<table>"];
96
- if (header !== void 0) lines.push(`<tr>${header.cells.map((cell) => emitCellTag(cell, true, context)).join("")}</tr>`);
97
- for (const row of body) lines.push(`<tr>${row.cells.map((cell) => emitCellTag(cell, false, context)).join("")}</tr>`);
98
- lines.push("</table>");
99
- return lines.join("\n");
94
+ return [
95
+ "<table>",
96
+ ...walkTableGrid(table).map((positions, rowIndex) => {
97
+ return `<tr>${positions.flatMap((position) => position.anchorRowIndex === void 0 ? [emitCellTag(position.cell, rowIndex === 0, context)] : []).join("")}</tr>`;
98
+ }),
99
+ "</table>"
100
+ ].join("\n");
100
101
  }
101
102
  //#endregion
102
103
  export { emitHtmlTable, tableNeedsHtmlFallback };
@@ -202,20 +202,20 @@ function buildCell(cell, contentWidthPt) {
202
202
  ...background === void 0 ? {} : { background }
203
203
  };
204
204
  }
205
+ const NO_DECLARED_COLUMN_COUNT = 0;
205
206
  function parseTableRows(inner, contentWidthPt) {
206
207
  const rowElements = extractTopLevelElements(inner, ["tr"]);
207
208
  if (rowElements === void 0 || rowElements.length === 0) return;
208
- const rows = [];
209
+ const anchorRows = [];
209
210
  for (const row of rowElements) {
210
211
  const cellElements = extractTopLevelElements(row.inner, ["td", "th"]);
211
212
  if (cellElements === void 0 || cellElements.length === 0) return;
212
- rows.push({ cells: cellElements.map((cell) => buildCell(cell, contentWidthPt)) });
213
+ anchorRows.push({ cells: cellElements.map((cell) => buildCell(cell, contentWidthPt)) });
213
214
  }
214
- return rows;
215
+ return (0, document_schema_js.placeAnchorTableRows)(anchorRows, NO_DECLARED_COLUMN_COUNT);
215
216
  }
216
217
  function buildContentTable(rows, contentWidthPt) {
217
- const header = rows[0];
218
- const columnCount = Math.max(1, header.cells.reduce((sum, cell) => sum + (cell.colSpan ?? 1), 0));
218
+ const columnCount = rows[0].cells.length;
219
219
  return {
220
220
  kind: "table",
221
221
  rows,
@@ -1,6 +1,6 @@
1
1
  import { resolveMarkdownImage } from "../lower/image.js";
2
2
  import { MONOSPACE_FONT_FAMILY } from "../shared/style-constants.js";
3
- import { rgbHexToColor } from "document-schema.js";
3
+ import { placeAnchorTableRows, rgbHexToColor } from "document-schema.js";
4
4
  //#region src/html/html-table.ts
5
5
  function findBalancedClose(text, openEnd, tagNames) {
6
6
  const names = tagNames.join("|");
@@ -201,20 +201,20 @@ function buildCell(cell, contentWidthPt) {
201
201
  ...background === void 0 ? {} : { background }
202
202
  };
203
203
  }
204
+ const NO_DECLARED_COLUMN_COUNT = 0;
204
205
  function parseTableRows(inner, contentWidthPt) {
205
206
  const rowElements = extractTopLevelElements(inner, ["tr"]);
206
207
  if (rowElements === void 0 || rowElements.length === 0) return;
207
- const rows = [];
208
+ const anchorRows = [];
208
209
  for (const row of rowElements) {
209
210
  const cellElements = extractTopLevelElements(row.inner, ["td", "th"]);
210
211
  if (cellElements === void 0 || cellElements.length === 0) return;
211
- rows.push({ cells: cellElements.map((cell) => buildCell(cell, contentWidthPt)) });
212
+ anchorRows.push({ cells: cellElements.map((cell) => buildCell(cell, contentWidthPt)) });
212
213
  }
213
- return rows;
214
+ return placeAnchorTableRows(anchorRows, NO_DECLARED_COLUMN_COUNT);
214
215
  }
215
216
  function buildContentTable(rows, contentWidthPt) {
216
- const header = rows[0];
217
- const columnCount = Math.max(1, header.cells.reduce((sum, cell) => sum + (cell.colSpan ?? 1), 0));
217
+ const columnCount = rows[0].cells.length;
218
218
  return {
219
219
  kind: "table",
220
220
  rows,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mrkdwn.js",
3
- "version": "7.0.1",
3
+ "version": "8.0.1",
4
4
  "description": "Hand-written CommonMark+GFM <-> DocumentTree codec, built on document-schema.js",
5
5
  "type": "module",
6
6
  "repository": {
@@ -56,8 +56,8 @@
56
56
  ],
57
57
  "license": "MIT",
58
58
  "dependencies": {
59
- "byte-codec": "1.6.3",
60
- "document-schema.js": "7.11.5",
59
+ "byte-codec": "1.7.0",
60
+ "document-schema.js": "7.12.0",
61
61
  "zod": "4.4.3"
62
62
  },
63
63
  "devDependencies": {