@sillsdev/docu-notion 1.0.0-alpha.1 → 1.0.0-alpha.2
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.
|
@@ -74,6 +74,14 @@ test("Adds anchor to headings", () => __awaiter(void 0, void 0, void 0, function
|
|
|
74
74
|
]);
|
|
75
75
|
expect(result.trim()).toBe(`# Heading One {/* #${headingBlockId.replaceAll("-", "")} */}`);
|
|
76
76
|
}));
|
|
77
|
+
test("Adds anchor to H4 headings", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
const headingBlockId = "86f746f4-1c79-4ba1-a2f6-a1d59c2f9d23";
|
|
79
|
+
const config = { plugins: [HeadingTransformer_1.standardHeadingTransformer] };
|
|
80
|
+
const result = yield (0, pluginTestRun_1.blocksToMarkdown)(config, [
|
|
81
|
+
makeHeadingBlock(headingBlockId, "Heading Four", "heading_4"),
|
|
82
|
+
]);
|
|
83
|
+
expect(result.trim()).toBe(`#### Heading Four {/* #${headingBlockId.replaceAll("-", "")} */}`);
|
|
84
|
+
}));
|
|
77
85
|
test("docusaurus-v2 flag keeps legacy heading id syntax", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
86
|
const headingBlockId = "86f746f4-1c79-4ba1-a2f6-a1d59c2f9d23";
|
|
79
87
|
const config = { plugins: [HeadingTransformer_1.standardHeadingTransformer] };
|
|
@@ -11,13 +11,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.standardHeadingTransformer = void 0;
|
|
13
13
|
const log_1 = require("../log");
|
|
14
|
+
function renderHeadingText(context, block, type) {
|
|
15
|
+
// Work around notion-to-md only shipping built-in heading renderers for
|
|
16
|
+
// heading_1 through heading_3. For heading_4 and above we still reuse its
|
|
17
|
+
// inline annotation logic, but we assemble the heading markdown ourselves.
|
|
18
|
+
const headingBlock = block[type];
|
|
19
|
+
const blockContent = (headingBlock === null || headingBlock === void 0 ? void 0 : headingBlock.text) || (headingBlock === null || headingBlock === void 0 ? void 0 : headingBlock.rich_text) || [];
|
|
20
|
+
return blockContent
|
|
21
|
+
.map((content) => {
|
|
22
|
+
if (content.type === "equation" && content.equation) {
|
|
23
|
+
return `$${content.equation.expression}$`;
|
|
24
|
+
}
|
|
25
|
+
let plainText = context.notionToMarkdown.annotatePlainText(content.plain_text, content.annotations);
|
|
26
|
+
if (content.href) {
|
|
27
|
+
plainText = `[${plainText}](${content.href})`;
|
|
28
|
+
}
|
|
29
|
+
return plainText;
|
|
30
|
+
})
|
|
31
|
+
.join("");
|
|
32
|
+
}
|
|
14
33
|
// Makes links to headings work in docusaurus
|
|
15
34
|
// https://github.com/sillsdev/docu-notion/issues/20
|
|
16
35
|
function headingTransformer(context, block) {
|
|
17
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
37
|
// First, remove the prefix we added to the heading type
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
const type = block.type.replace("DN_", "");
|
|
39
|
+
block.type = type;
|
|
40
|
+
const headingLevel = Number(type.replace("heading_", ""));
|
|
41
|
+
const markdown = headingLevel <= 3
|
|
42
|
+
? yield context.notionToMarkdown.blockToMarkdown(block)
|
|
43
|
+
// notion-to-md 3.1.1 falls through on heading_4+ and crashes trying to
|
|
44
|
+
// read block[type].text, so render those levels locally.
|
|
45
|
+
: `${"#".repeat(headingLevel)} ${renderHeadingText(context, block, type)}`;
|
|
21
46
|
(0, log_1.logDebug)("headingTransformer, markdown of a heading before adding id", markdown);
|
|
22
47
|
// To make heading links work in Docusaurus, we add a stable block-id anchor.
|
|
23
48
|
// Docusaurus v2 uses explicit heading IDs, while the v3 default can use the
|
|
@@ -61,5 +86,11 @@ exports.standardHeadingTransformer = {
|
|
|
61
86
|
type: "DN_heading_3",
|
|
62
87
|
getStringFromBlock: (context, block) => headingTransformer(context, block),
|
|
63
88
|
},
|
|
89
|
+
{
|
|
90
|
+
type: "DN_heading_4",
|
|
91
|
+
// Keep this explicit so H4 blocks take the local workaround path instead
|
|
92
|
+
// of being handed back to notion-to-md's unsupported default branch.
|
|
93
|
+
getStringFromBlock: (context, block) => headingTransformer(context, block),
|
|
94
|
+
},
|
|
64
95
|
],
|
|
65
96
|
};
|
package/package.json
CHANGED