@threadlabs/looma 0.46.2 → 0.46.3
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/docs/catalog.json +1 -1
- package/editor/chunks/expressmark.js +51 -5
- package/editor/expressmark.d.ts +3 -1
- package/package.json +2 -2
package/docs/catalog.json
CHANGED
|
@@ -541,6 +541,49 @@ function headingsOf(document, references) {
|
|
|
541
541
|
visit(document);
|
|
542
542
|
return headings;
|
|
543
543
|
}
|
|
544
|
+
function tocBody(headings, depth, ordered) {
|
|
545
|
+
const ids = assignLoomaHeadingIds(headings);
|
|
546
|
+
const roots = [];
|
|
547
|
+
const stack = [];
|
|
548
|
+
headings.forEach((heading, index) => {
|
|
549
|
+
const level = Number(heading.node.attrs?.level ?? 1);
|
|
550
|
+
if (level > depth || !heading.text) return;
|
|
551
|
+
while (stack.length && stack[stack.length - 1].level >= level) stack.pop();
|
|
552
|
+
const item = {
|
|
553
|
+
type: "listItem",
|
|
554
|
+
body: [{
|
|
555
|
+
type: "paragraph",
|
|
556
|
+
children: [{
|
|
557
|
+
type: "link",
|
|
558
|
+
url: `#${ids[index]}`,
|
|
559
|
+
value: heading.text,
|
|
560
|
+
attributes: {
|
|
561
|
+
target: "_self",
|
|
562
|
+
rel: "noopener noreferrer"
|
|
563
|
+
}
|
|
564
|
+
}]
|
|
565
|
+
}]
|
|
566
|
+
};
|
|
567
|
+
const parent = stack[stack.length - 1]?.item;
|
|
568
|
+
const destination = parent ? parent.body ??= [] : roots;
|
|
569
|
+
let list = destination[destination.length - 1];
|
|
570
|
+
if (list?.type !== "list") {
|
|
571
|
+
list = {
|
|
572
|
+
type: "list",
|
|
573
|
+
ordered,
|
|
574
|
+
...ordered ? { start: 1 } : {},
|
|
575
|
+
children: []
|
|
576
|
+
};
|
|
577
|
+
destination.push(list);
|
|
578
|
+
}
|
|
579
|
+
list.children.push(item);
|
|
580
|
+
stack.push({
|
|
581
|
+
level,
|
|
582
|
+
item
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
return roots;
|
|
586
|
+
}
|
|
544
587
|
function customHeadings(headings) {
|
|
545
588
|
const marked = /* @__PURE__ */ new Set();
|
|
546
589
|
for (;;) {
|
|
@@ -896,7 +939,7 @@ function toBareNode(node, path, context) {
|
|
|
896
939
|
fields(node, ["format", "depth"], path);
|
|
897
940
|
const depth = Number(attrs.depth ?? 3);
|
|
898
941
|
const format = string(attrs.format, "plain");
|
|
899
|
-
if (!node.content?.length) {
|
|
942
|
+
if (!node.content?.length && context.tableOfContents !== "entries") {
|
|
900
943
|
const attributes = {};
|
|
901
944
|
if (depth !== 3) attributes.depth = String(depth);
|
|
902
945
|
if (format !== "plain") attributes.format = format;
|
|
@@ -913,7 +956,7 @@ function toBareNode(node, path, context) {
|
|
|
913
956
|
depth: String(depth),
|
|
914
957
|
format
|
|
915
958
|
},
|
|
916
|
-
body: blocks()
|
|
959
|
+
body: node.content?.length ? blocks() : tocBody(context.headings, depth, format === "numbered")
|
|
917
960
|
};
|
|
918
961
|
}
|
|
919
962
|
default: return fail(path, `node ${node.type ?? "unknown"}`);
|
|
@@ -923,7 +966,7 @@ function toBareNode(node, path, context) {
|
|
|
923
966
|
* Maps an editor's saved JSON to the independent Expressive Markdown AST without DOM access.
|
|
924
967
|
* @contract Unsupported nodes, marks and durable attributes throw with their location; input is never
|
|
925
968
|
* mutated. Footnote and link definitions stay where they are, and a table of contents stays a
|
|
926
|
-
* placeholder unless it holds authored navigation.
|
|
969
|
+
* placeholder unless it holds authored navigation or `tableOfContents: "entries"` is requested.
|
|
927
970
|
*/
|
|
928
971
|
function editorDocumentToExpressmark(document, options = {}) {
|
|
929
972
|
if (document.type !== "doc") fail("document", "non-document root");
|
|
@@ -990,7 +1033,9 @@ function editorDocumentToExpressmark(document, options = {}) {
|
|
|
990
1033
|
const context = {
|
|
991
1034
|
custom: customHeadings(headings),
|
|
992
1035
|
definitions,
|
|
993
|
-
references
|
|
1036
|
+
references,
|
|
1037
|
+
headings,
|
|
1038
|
+
tableOfContents: options.tableOfContents
|
|
994
1039
|
};
|
|
995
1040
|
return {
|
|
996
1041
|
type: "document",
|
|
@@ -1505,7 +1550,8 @@ function keepAuthored(source, edited, options) {
|
|
|
1505
1550
|
for (let index = 0; index < current.length;) {
|
|
1506
1551
|
const found = keys.findIndex((key, block) => block > used && key.length > 0 && key.every((value, at) => current[index + at] === value));
|
|
1507
1552
|
if (found >= 0) {
|
|
1508
|
-
|
|
1553
|
+
const original = source.body[found];
|
|
1554
|
+
body.push(options.tableOfContents === "entries" && original.type === "leaf" && original.subType === "toc" ? edited.body[index] : original);
|
|
1509
1555
|
index += keys[found].length;
|
|
1510
1556
|
used = found;
|
|
1511
1557
|
continue;
|
package/editor/expressmark.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { type LoomaReferenceMap } from "./reference-display.js";
|
|
|
4
4
|
/** Conversion-time display snapshot, independent from the authored editor document. */
|
|
5
5
|
export interface EditorMarkdownConversionOptions extends ConversionOptions {
|
|
6
6
|
references?: LoomaReferenceMap;
|
|
7
|
+
/** Write current links for portable exports; authored navigation is always preserved. Defaults to a reader-built placeholder. */
|
|
8
|
+
tableOfContents?: "placeholder" | "entries";
|
|
7
9
|
/**
|
|
8
10
|
* The Markdown the document was read from. Its front matter, every block the editor left
|
|
9
11
|
* unchanged and the spacing between them are written back byte for byte; an edited block keeps
|
|
@@ -24,7 +26,7 @@ export declare class EditorMarkdownConversionError extends Error {
|
|
|
24
26
|
* Maps an editor's saved JSON to the independent Expressive Markdown AST without DOM access.
|
|
25
27
|
* @contract Unsupported nodes, marks and durable attributes throw with their location; input is never
|
|
26
28
|
* mutated. Footnote and link definitions stay where they are, and a table of contents stays a
|
|
27
|
-
* placeholder unless it holds authored navigation.
|
|
29
|
+
* placeholder unless it holds authored navigation or `tableOfContents: "entries"` is requested.
|
|
28
30
|
*/
|
|
29
31
|
export declare function editorDocumentToExpressmark(document: JSONContent, options?: EditorMarkdownConversionOptions): Document;
|
|
30
32
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadlabs/looma",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Looma components as HTML, Vue, and plain DOM, with design tokens.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"highlight.js": "11.11.2",
|
|
114
114
|
"lowlight": "^3.3.0",
|
|
115
115
|
"lucide": "~0.554.0",
|
|
116
|
-
"expressmark": ">=0.
|
|
116
|
+
"expressmark": ">=0.5.1 <1",
|
|
117
117
|
"parse5": "^8.0.1"
|
|
118
118
|
},
|
|
119
119
|
"peerDependencies": {
|