@podlite/markdown 0.0.32 → 0.0.33
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.cjs +16 -16
- package/lib/index.cjs.map +3 -3
- package/lib/index.esm.js +31 -7
- package/lib/index.esm.js.map +2 -2
- package/package.json +2 -2
package/lib/index.esm.js
CHANGED
|
@@ -25644,7 +25644,7 @@ var require_package = __commonJS({
|
|
|
25644
25644
|
"../podlite-schema/package.json"(exports, module) {
|
|
25645
25645
|
module.exports = {
|
|
25646
25646
|
name: "@podlite/schema",
|
|
25647
|
-
version: "0.0.
|
|
25647
|
+
version: "0.0.40",
|
|
25648
25648
|
description: "AST tools and schema for Podlite markup language \u2014 validate, traverse, and transform document trees",
|
|
25649
25649
|
main: "./src/index.ts",
|
|
25650
25650
|
homepage: "https://podlite.org",
|
|
@@ -27086,6 +27086,28 @@ function parseTsv(text4) {
|
|
|
27086
27086
|
const rows = lines.map((line) => line.split(" "));
|
|
27087
27087
|
return rows.filter((r) => !(r.length === 1 && r[0].trim() === ""));
|
|
27088
27088
|
}
|
|
27089
|
+
function parseMimeType(raw) {
|
|
27090
|
+
if (!raw || typeof raw !== "string")
|
|
27091
|
+
return { type: "", params: {} };
|
|
27092
|
+
const parts = raw.split(";").map((s) => s.trim());
|
|
27093
|
+
const type = (parts.shift() || "").toLowerCase();
|
|
27094
|
+
const params = {};
|
|
27095
|
+
for (const p of parts) {
|
|
27096
|
+
if (!p)
|
|
27097
|
+
continue;
|
|
27098
|
+
const eq = p.indexOf("=");
|
|
27099
|
+
if (eq < 0)
|
|
27100
|
+
continue;
|
|
27101
|
+
const key = p.slice(0, eq).trim().toLowerCase();
|
|
27102
|
+
let value = p.slice(eq + 1).trim();
|
|
27103
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
27104
|
+
value = value.slice(1, -1);
|
|
27105
|
+
}
|
|
27106
|
+
if (key)
|
|
27107
|
+
params[key] = value;
|
|
27108
|
+
}
|
|
27109
|
+
return { type, params };
|
|
27110
|
+
}
|
|
27089
27111
|
function findDataBlockByKey(tree, key) {
|
|
27090
27112
|
let found = null;
|
|
27091
27113
|
const walk = (node) => {
|
|
@@ -27158,10 +27180,10 @@ function buildRowBlock(cells, isHeader) {
|
|
|
27158
27180
|
}
|
|
27159
27181
|
return block;
|
|
27160
27182
|
}
|
|
27161
|
-
function csvToTableContent(csvRows) {
|
|
27162
|
-
return csvRows.map((row) => {
|
|
27183
|
+
function csvToTableContent(csvRows, hasHeader = false) {
|
|
27184
|
+
return csvRows.map((row, i) => {
|
|
27163
27185
|
const cells = row.map((v) => buildCellBlock(v.trim()));
|
|
27164
|
-
return buildRowBlock(cells,
|
|
27186
|
+
return buildRowBlock(cells, hasHeader && i === 0);
|
|
27165
27187
|
});
|
|
27166
27188
|
}
|
|
27167
27189
|
function normalizeCellCounts(tableNode, source = "table") {
|
|
@@ -27364,7 +27386,8 @@ var plugin_tables_default = () => (tree) => {
|
|
|
27364
27386
|
console.warn(`[table] no =data block found for data:${ref.target} \u2014 rendered as empty`);
|
|
27365
27387
|
return { ...node, content: [] };
|
|
27366
27388
|
}
|
|
27367
|
-
const
|
|
27389
|
+
const rawMime = config_default(dataBlock, {}).getFirstValue("mime-type");
|
|
27390
|
+
const { type: mimeType, params: mimeParams } = parseMimeType(rawMime);
|
|
27368
27391
|
const isCsv = mimeType === "text/csv";
|
|
27369
27392
|
const isTsv = mimeType === "text/tab-separated-values";
|
|
27370
27393
|
if (isCsv || isTsv) {
|
|
@@ -27376,11 +27399,12 @@ var plugin_tables_default = () => (tree) => {
|
|
|
27376
27399
|
);
|
|
27377
27400
|
return { ...node, content: [] };
|
|
27378
27401
|
}
|
|
27379
|
-
const
|
|
27402
|
+
const hasHeader = mimeParams.header === "present";
|
|
27403
|
+
const filledNode = { ...node, content: csvToTableContent(rows2, hasHeader) };
|
|
27380
27404
|
return normalizeCellCounts(filledNode, `table data:${ref.target}`);
|
|
27381
27405
|
}
|
|
27382
27406
|
console.warn(
|
|
27383
|
-
`[table] =data :key<${ref.target}> has non-tabular mime-type ${
|
|
27407
|
+
`[table] =data :key<${ref.target}> has non-tabular mime-type ${rawMime || "(none)"} \u2014 rendered as =code`
|
|
27384
27408
|
);
|
|
27385
27409
|
return buildCodeFromDataBlock(node, dataBlock);
|
|
27386
27410
|
}
|