@sillsdev/docu-notion 0.16.0 → 0.16.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.
|
@@ -29,7 +29,8 @@ function convertInternalUrl(context, url) {
|
|
|
29
29
|
exports.convertInternalUrl = convertInternalUrl;
|
|
30
30
|
// handles the whole markdown link, including the label
|
|
31
31
|
function convertInternalLink(context, markdownLink) {
|
|
32
|
-
|
|
32
|
+
// match both [foo](/123) and [bar](https://www.notion.so/123) <-- the "mention" link style
|
|
33
|
+
const linkRegExp = /\[([^\]]+)?\]\((?:https?:\/\/www\.notion\.so\/|\/)?([^),^/]+)\)/g;
|
|
33
34
|
const match = linkRegExp.exec(markdownLink);
|
|
34
35
|
if (match === null) {
|
|
35
36
|
(0, log_1.warning)(`[standardInternalLinkConversion] Could not parse link ${markdownLink}`);
|
|
@@ -96,7 +97,9 @@ exports.standardInternalLinkConversion = {
|
|
|
96
97
|
// (has some other text that's been turned into a link) or "raw".
|
|
97
98
|
// Raw links come in without a leading slash, e.g. [link_to_page](4a6de8c0-b90b-444b-8a7b-d534d6ec71a4)
|
|
98
99
|
// Inline links come in with a leading slash, e.g. [pointer to the introduction](/4a6de8c0b90b444b8a7bd534d6ec71a4)
|
|
99
|
-
|
|
100
|
+
// "Mention" links come in as full URLs, e.g. [link_to_page](https://www.notion.so/62f1187010214b0883711a1abb277d31)
|
|
101
|
+
// YOu can create them either with @+the name of a page, or by pasting a URL and then selecting the "Mention" option.
|
|
102
|
+
match: /\[([^\]]+)?\]\((?!mailto:)(https:\/\/www\.notion\.so\/[^),^/]+|\/?[^),^/]+)\)/,
|
|
100
103
|
convert: convertInternalLink,
|
|
101
104
|
},
|
|
102
105
|
};
|
|
@@ -38,6 +38,43 @@ test("urls that show up as raw text get left that way", () => __awaiter(void 0,
|
|
|
38
38
|
});
|
|
39
39
|
expect(results.trim()).toBe("https://github.com");
|
|
40
40
|
}));
|
|
41
|
+
// See https://github.com/sillsdev/docu-notion/issues/97
|
|
42
|
+
test("mention-style link to an existing page", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const targetPageId = "123";
|
|
44
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
45
|
+
slug: undefined,
|
|
46
|
+
name: "Hello World",
|
|
47
|
+
id: targetPageId,
|
|
48
|
+
});
|
|
49
|
+
const results = yield getMarkdown({
|
|
50
|
+
type: "paragraph",
|
|
51
|
+
paragraph: {
|
|
52
|
+
rich_text: [
|
|
53
|
+
{
|
|
54
|
+
type: "mention",
|
|
55
|
+
mention: {
|
|
56
|
+
type: "page",
|
|
57
|
+
page: {
|
|
58
|
+
id: `${targetPageId}`,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
annotations: {
|
|
62
|
+
bold: false,
|
|
63
|
+
italic: false,
|
|
64
|
+
strikethrough: false,
|
|
65
|
+
underline: false,
|
|
66
|
+
code: false,
|
|
67
|
+
color: "default",
|
|
68
|
+
},
|
|
69
|
+
plain_text: "foo",
|
|
70
|
+
href: `https://www.notion.so/${targetPageId}`,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
color: "default",
|
|
74
|
+
},
|
|
75
|
+
}, targetPage);
|
|
76
|
+
expect(results.trim()).toBe(`[foo](/${targetPageId})`);
|
|
77
|
+
}));
|
|
41
78
|
test("link to an existing page on this site that has no slug", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
79
|
const targetPageId = "123";
|
|
43
80
|
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
@@ -517,7 +554,78 @@ test("internal link inside codeblock ignored", () => __awaiter(void 0, void 0, v
|
|
|
517
554
|
}, targetPage);
|
|
518
555
|
expect(results.trim()).toContain("this should not change [link](https://www.notion.so/native/metapages/mypage)");
|
|
519
556
|
}));
|
|
520
|
-
|
|
557
|
+
test("multiple internal links in a paragraph", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
558
|
+
const targetPageAId = "123";
|
|
559
|
+
const targetPageA = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
560
|
+
slug: undefined,
|
|
561
|
+
name: "Hello World A",
|
|
562
|
+
id: targetPageAId,
|
|
563
|
+
});
|
|
564
|
+
const targetPageBId = "456";
|
|
565
|
+
const targetPageB = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
566
|
+
slug: undefined,
|
|
567
|
+
name: "Hello World B",
|
|
568
|
+
id: targetPageBId,
|
|
569
|
+
});
|
|
570
|
+
const results = yield getMarkdown({
|
|
571
|
+
type: "paragraph",
|
|
572
|
+
paragraph: {
|
|
573
|
+
rich_text: [
|
|
574
|
+
{
|
|
575
|
+
type: "text",
|
|
576
|
+
text: {
|
|
577
|
+
content: "A",
|
|
578
|
+
link: { url: `/${targetPageAId}` },
|
|
579
|
+
},
|
|
580
|
+
annotations: {
|
|
581
|
+
bold: false,
|
|
582
|
+
italic: false,
|
|
583
|
+
strikethrough: false,
|
|
584
|
+
underline: false,
|
|
585
|
+
code: false,
|
|
586
|
+
color: "default",
|
|
587
|
+
},
|
|
588
|
+
plain_text: "A",
|
|
589
|
+
href: `/${targetPageAId}`,
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
type: "text",
|
|
593
|
+
text: { content: " ", link: null },
|
|
594
|
+
annotations: {
|
|
595
|
+
bold: false,
|
|
596
|
+
italic: false,
|
|
597
|
+
strikethrough: false,
|
|
598
|
+
underline: false,
|
|
599
|
+
code: false,
|
|
600
|
+
color: "default",
|
|
601
|
+
},
|
|
602
|
+
plain_text: " ",
|
|
603
|
+
href: null,
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
type: "text",
|
|
607
|
+
text: {
|
|
608
|
+
content: "B",
|
|
609
|
+
link: { url: `/${targetPageBId}` },
|
|
610
|
+
},
|
|
611
|
+
annotations: {
|
|
612
|
+
bold: false,
|
|
613
|
+
italic: false,
|
|
614
|
+
strikethrough: false,
|
|
615
|
+
underline: false,
|
|
616
|
+
code: false,
|
|
617
|
+
color: "default",
|
|
618
|
+
},
|
|
619
|
+
plain_text: "B",
|
|
620
|
+
href: `/${targetPageBId}`,
|
|
621
|
+
},
|
|
622
|
+
],
|
|
623
|
+
color: "default",
|
|
624
|
+
},
|
|
625
|
+
}, targetPageA, targetPageB);
|
|
626
|
+
expect(results.trim()).toBe(`[A](/${targetPageAId}) [B](/${targetPageBId})`);
|
|
627
|
+
}));
|
|
628
|
+
function getMarkdown(block, targetPage, targetPage2) {
|
|
521
629
|
return __awaiter(this, void 0, void 0, function* () {
|
|
522
630
|
const config = {
|
|
523
631
|
plugins: [
|
|
@@ -526,6 +634,6 @@ function getMarkdown(block, targetPage) {
|
|
|
526
634
|
externalLinks_1.standardExternalLinkConversion,
|
|
527
635
|
],
|
|
528
636
|
};
|
|
529
|
-
return yield (0, pluginTestRun_1.oneBlockToMarkdown)(config, block, targetPage);
|
|
637
|
+
return yield (0, pluginTestRun_1.oneBlockToMarkdown)(config, block, targetPage, targetPage2);
|
|
530
638
|
});
|
|
531
639
|
}
|
|
@@ -7,4 +7,4 @@ export declare function makeSamplePageObject(options: {
|
|
|
7
7
|
name?: string;
|
|
8
8
|
id?: string;
|
|
9
9
|
}): NotionPage;
|
|
10
|
-
export declare function oneBlockToMarkdown(config: IDocuNotionConfig, block: Record<string, unknown>, targetPage?: NotionPage): Promise<string>;
|
|
10
|
+
export declare function oneBlockToMarkdown(config: IDocuNotionConfig, block: Record<string, unknown>, targetPage?: NotionPage, targetPage2?: NotionPage): Promise<string>;
|
|
@@ -226,7 +226,7 @@ function makeSamplePageObject(options) {
|
|
|
226
226
|
return p;
|
|
227
227
|
}
|
|
228
228
|
exports.makeSamplePageObject = makeSamplePageObject;
|
|
229
|
-
function oneBlockToMarkdown(config, block, targetPage) {
|
|
229
|
+
function oneBlockToMarkdown(config, block, targetPage, targetPage2) {
|
|
230
230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
231
231
|
// just in case someone expects these other properties that aren't normally relevant,
|
|
232
232
|
// we merge the given block properties into an actual, full block
|
|
@@ -258,7 +258,7 @@ function oneBlockToMarkdown(config, block, targetPage) {
|
|
|
258
258
|
slug: "dummy2",
|
|
259
259
|
name: "Dummy2",
|
|
260
260
|
});
|
|
261
|
-
return yield blocksToMarkdown(config, [fullBlock], targetPage ? [dummyPage1, targetPage, dummyPage2] : undefined);
|
|
261
|
+
return yield blocksToMarkdown(config, [fullBlock], targetPage ? [dummyPage1, targetPage, targetPage2 !== null && targetPage2 !== void 0 ? targetPage2 : dummyPage2] : undefined);
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
264
|
exports.oneBlockToMarkdown = oneBlockToMarkdown;
|
package/dist/pull.js
CHANGED
|
@@ -163,7 +163,7 @@ function getPagesRecursively(options, incomingContext, pageIdOfThisParent, order
|
|
|
163
163
|
if (!rootLevel &&
|
|
164
164
|
pageInfo.hasParagraphs &&
|
|
165
165
|
pageInfo.childPageIdsAndOrder.length) {
|
|
166
|
-
(0, log_1.error)(`Skipping "${pageInTheOutline.nameOrTitle}" and its children. docu-notion does not support pages that are both levels and have content at the same time.`);
|
|
166
|
+
(0, log_1.error)(`Skipping "${pageInTheOutline.nameOrTitle}" and its children. docu-notion does not support pages that are both levels and have text content (paragraphs) at the same time. Normally outline pages should just be composed of 1) links to other pages and 2) child pages (other levels of the outline). Note that @-mention style links appear as text paragraphs to docu-notion so must not be used to form the outline.`);
|
|
167
167
|
++counts.skipped_because_level_cannot_have_content;
|
|
168
168
|
return;
|
|
169
169
|
}
|
package/dist/transform.js
CHANGED
|
@@ -149,7 +149,7 @@ function doNotionToMarkdown(docunotionContext, blocks) {
|
|
|
149
149
|
// Raw links come in without a leading slash, e.g. [link_to_page](4a6de8c0-b90b-444b-8a7b-d534d6ec71a4)
|
|
150
150
|
// Inline links come in with a leading slash, e.g. [pointer to the introduction](/4a6de8c0b90b444b8a7bd534d6ec71a4)
|
|
151
151
|
function doLinkFixes(context, markdown, config) {
|
|
152
|
-
const linkRegExp = /\[
|
|
152
|
+
const linkRegExp = /\[.*?\]\([^\)]*?\)/g;
|
|
153
153
|
(0, log_1.logDebug)("markdown before link fixes", markdown);
|
|
154
154
|
let match;
|
|
155
155
|
// since we're going to make changes to the markdown,
|
package/package.json
CHANGED