@sillsdev/docu-notion 0.11.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.
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/dist/FlatGuidLayoutStrategy.d.ts +6 -0
- package/dist/FlatGuidLayoutStrategy.js +25 -0
- package/dist/HierarchicalNamedLayoutStrategy.d.ts +7 -0
- package/dist/HierarchicalNamedLayoutStrategy.js +80 -0
- package/dist/LayoutStrategy.d.ts +12 -0
- package/dist/LayoutStrategy.js +83 -0
- package/dist/MakeImagePersistencePlan.d.ts +2 -0
- package/dist/MakeImagePersistencePlan.js +66 -0
- package/dist/NotionImage-CaptionReading.spec.d.ts +1 -0
- package/dist/NotionImage-CaptionReading.spec.js +233 -0
- package/dist/NotionPage.d.ts +45 -0
- package/dist/NotionPage.js +229 -0
- package/dist/NotionPage.spec.d.ts +1 -0
- package/dist/NotionPage.spec.js +143 -0
- package/dist/config/configuration.d.ts +5 -0
- package/dist/config/configuration.js +86 -0
- package/dist/config/default.docunotion.config.d.ts +3 -0
- package/dist/config/default.docunotion.config.js +37 -0
- package/dist/images.d.ts +24 -0
- package/dist/images.js +230 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +37 -0
- package/dist/log.d.ts +11 -0
- package/dist/log.js +61 -0
- package/dist/makeImagePersistencePlan.spec.d.ts +1 -0
- package/dist/makeImagePersistencePlan.spec.js +35 -0
- package/dist/notion-styles.css +58 -0
- package/dist/plugins/CalloutTransformer.d.ts +24 -0
- package/dist/plugins/CalloutTransformer.js +88 -0
- package/dist/plugins/CalloutTransformer.spec.d.ts +1 -0
- package/dist/plugins/CalloutTransformer.spec.js +199 -0
- package/dist/plugins/ColumnListTransformer.d.ts +2 -0
- package/dist/plugins/ColumnListTransformer.js +34 -0
- package/dist/plugins/ColumnTransformer.d.ts +2 -0
- package/dist/plugins/ColumnTransformer.js +67 -0
- package/dist/plugins/EscapeHtmlBlockModifier.d.ts +2 -0
- package/dist/plugins/EscapeHtmlBlockModifier.js +41 -0
- package/dist/plugins/EscapeHtmlBlockModifier.spec.d.ts +1 -0
- package/dist/plugins/EscapeHtmlBlockModifier.spec.js +130 -0
- package/dist/plugins/HeadingTranformer.spec.d.ts +1 -0
- package/dist/plugins/HeadingTranformer.spec.js +46 -0
- package/dist/plugins/HeadingTransformer.d.ts +2 -0
- package/dist/plugins/HeadingTransformer.js +63 -0
- package/dist/plugins/NumberedListTransformer.d.ts +2 -0
- package/dist/plugins/NumberedListTransformer.js +55 -0
- package/dist/plugins/NumberedListTransformer.spec.d.ts +1 -0
- package/dist/plugins/NumberedListTransformer.spec.js +86 -0
- package/dist/plugins/TableTransformer.d.ts +5 -0
- package/dist/plugins/TableTransformer.js +70 -0
- package/dist/plugins/embedTweaks.d.ts +5 -0
- package/dist/plugins/embedTweaks.js +46 -0
- package/dist/plugins/embedTweaks.spec.d.ts +1 -0
- package/dist/plugins/embedTweaks.spec.js +230 -0
- package/dist/plugins/externalLinks.d.ts +2 -0
- package/dist/plugins/externalLinks.js +26 -0
- package/dist/plugins/externalLinks.spec.d.ts +1 -0
- package/dist/plugins/externalLinks.spec.js +132 -0
- package/dist/plugins/internalLinks.d.ts +7 -0
- package/dist/plugins/internalLinks.js +102 -0
- package/dist/plugins/internalLinks.spec.d.ts +1 -0
- package/dist/plugins/internalLinks.spec.js +505 -0
- package/dist/plugins/mermaidLinkPlugin.spec.d.ts +1 -0
- package/dist/plugins/mermaidLinkPlugin.spec.js +77 -0
- package/dist/plugins/pluginTestRun.d.ts +10 -0
- package/dist/plugins/pluginTestRun.js +252 -0
- package/dist/plugins/pluginTypes.d.ts +44 -0
- package/dist/plugins/pluginTypes.js +2 -0
- package/dist/pull.d.ts +12 -0
- package/dist/pull.js +255 -0
- package/dist/run.d.ts +1 -0
- package/dist/run.js +35 -0
- package/dist/transform.d.ts +6 -0
- package/dist/transform.js +200 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +2 -0
- package/package.json +103 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const log_1 = require("../log");
|
|
13
|
+
const pluginTestRun_1 = require("./pluginTestRun");
|
|
14
|
+
const externalLinks_1 = require("./externalLinks");
|
|
15
|
+
// If you paste a link in notion and then choose "Create bookmark", the markdown
|
|
16
|
+
// would normally be [bookmark](https://example.com)]. Instead of seeing "bookmark",
|
|
17
|
+
// we change to the url.
|
|
18
|
+
test("links turned into bookmarks", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
(0, log_1.setLogLevel)("debug");
|
|
20
|
+
const results = yield getMarkdown({
|
|
21
|
+
type: "bookmark",
|
|
22
|
+
bookmark: { caption: [], url: "https://github.com" },
|
|
23
|
+
});
|
|
24
|
+
expect(results.trim()).toBe("[https://github.com](https://github.com)");
|
|
25
|
+
}));
|
|
26
|
+
test("external link inside callout", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const results = yield getMarkdown({
|
|
28
|
+
type: "callout",
|
|
29
|
+
callout: {
|
|
30
|
+
rich_text: [
|
|
31
|
+
{
|
|
32
|
+
type: "text",
|
|
33
|
+
text: { content: "Callouts inline ", link: null },
|
|
34
|
+
annotations: {
|
|
35
|
+
bold: false,
|
|
36
|
+
italic: false,
|
|
37
|
+
strikethrough: false,
|
|
38
|
+
underline: false,
|
|
39
|
+
code: false,
|
|
40
|
+
color: "default",
|
|
41
|
+
},
|
|
42
|
+
plain_text: "Callouts inline ",
|
|
43
|
+
href: null,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: {
|
|
48
|
+
content: "great page",
|
|
49
|
+
link: { url: `https://github.com` },
|
|
50
|
+
},
|
|
51
|
+
annotations: {
|
|
52
|
+
bold: false,
|
|
53
|
+
italic: false,
|
|
54
|
+
strikethrough: false,
|
|
55
|
+
underline: false,
|
|
56
|
+
code: false,
|
|
57
|
+
color: "default",
|
|
58
|
+
},
|
|
59
|
+
plain_text: "great page",
|
|
60
|
+
href: `https://github.com`,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: "text",
|
|
64
|
+
text: { content: ".", link: null },
|
|
65
|
+
annotations: {
|
|
66
|
+
bold: false,
|
|
67
|
+
italic: false,
|
|
68
|
+
strikethrough: false,
|
|
69
|
+
underline: false,
|
|
70
|
+
code: false,
|
|
71
|
+
color: "default",
|
|
72
|
+
},
|
|
73
|
+
plain_text: ".",
|
|
74
|
+
href: null,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
icon: { type: "emoji", emoji: "⚠️" },
|
|
78
|
+
color: "gray_background",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
expect(results.trim()).toBe("> ⚠️ Callouts inline [great page](https://github.com).");
|
|
82
|
+
}));
|
|
83
|
+
test("inline links to external site", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
const results = yield getMarkdown({
|
|
85
|
+
type: "paragraph",
|
|
86
|
+
paragraph: {
|
|
87
|
+
rich_text: [
|
|
88
|
+
{
|
|
89
|
+
type: "text",
|
|
90
|
+
text: { content: "Inline ", link: null },
|
|
91
|
+
annotations: {
|
|
92
|
+
bold: false,
|
|
93
|
+
italic: false,
|
|
94
|
+
strikethrough: false,
|
|
95
|
+
underline: false,
|
|
96
|
+
code: false,
|
|
97
|
+
color: "default",
|
|
98
|
+
},
|
|
99
|
+
plain_text: "Inline ",
|
|
100
|
+
href: null,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: "text",
|
|
104
|
+
text: {
|
|
105
|
+
content: "github",
|
|
106
|
+
link: { url: "https://github.com" },
|
|
107
|
+
},
|
|
108
|
+
annotations: {
|
|
109
|
+
bold: false,
|
|
110
|
+
italic: false,
|
|
111
|
+
strikethrough: false,
|
|
112
|
+
underline: false,
|
|
113
|
+
code: false,
|
|
114
|
+
color: "default",
|
|
115
|
+
},
|
|
116
|
+
plain_text: "github",
|
|
117
|
+
href: "https://github.com",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
color: "default",
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
expect(results.trim()).toBe("Inline [github](https://github.com)");
|
|
124
|
+
}));
|
|
125
|
+
function getMarkdown(block) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const config = {
|
|
128
|
+
plugins: [externalLinks_1.standardExternalLinkConversion],
|
|
129
|
+
};
|
|
130
|
+
return yield (0, pluginTestRun_1.oneBlockToMarkdown)(config, block);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IDocuNotionContext, IPlugin } from "./pluginTypes";
|
|
2
|
+
export declare function convertInternalUrl(context: IDocuNotionContext, url: string): string | undefined;
|
|
3
|
+
export declare function parseLinkId(fullLinkId: string): {
|
|
4
|
+
baseLinkId: string;
|
|
5
|
+
fragmentId: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const standardInternalLinkConversion: IPlugin;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.standardInternalLinkConversion = exports.parseLinkId = exports.convertInternalUrl = void 0;
|
|
4
|
+
const log_1 = require("../log");
|
|
5
|
+
// converts a url to a local link, if it is a link to a page in the Notion site
|
|
6
|
+
// only here for plugins, notion won't normally be giving us raw urls (at least not that I've noticed)
|
|
7
|
+
// If it finds a URL but can't find the page it points to, it will return undefined.
|
|
8
|
+
// If it doesn't find a match at all, it returns undefined.
|
|
9
|
+
function convertInternalUrl(context, url) {
|
|
10
|
+
const kGetIDFromNotionURL = /https:\/\/www\.notion\.so\S+-([a-z,0-9]+)+.*/;
|
|
11
|
+
const match = kGetIDFromNotionURL.exec(url);
|
|
12
|
+
if (match === null) {
|
|
13
|
+
(0, log_1.warning)(`[standardInternalLinkConversion] Could not parse link ${url} as a Notion URL`);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const id = match[1];
|
|
17
|
+
const pages = context.pages;
|
|
18
|
+
// find the page where pageId matches hrefFromNotion
|
|
19
|
+
const targetPage = pages.find(p => {
|
|
20
|
+
return p.matchesLinkId(id);
|
|
21
|
+
});
|
|
22
|
+
if (!targetPage) {
|
|
23
|
+
// About this situation. See https://github.com/sillsdev/docu-notion/issues/9
|
|
24
|
+
(0, log_1.warning)(`[standardInternalLinkConversion] Could not find the target of this link. Note that links to outline sections are not supported. ${url}. https://github.com/sillsdev/docu-notion/issues/9`);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return convertLinkHref(context, targetPage, url);
|
|
28
|
+
}
|
|
29
|
+
exports.convertInternalUrl = convertInternalUrl;
|
|
30
|
+
// handles the whole markdown link, including the label
|
|
31
|
+
function convertInternalLink(context, markdownLink) {
|
|
32
|
+
const linkRegExp = /\[([^\]]+)?\]\(\/?([^),^/]+)\)/g;
|
|
33
|
+
const match = linkRegExp.exec(markdownLink);
|
|
34
|
+
if (match === null) {
|
|
35
|
+
(0, log_1.warning)(`[standardInternalLinkConversion] Could not parse link ${markdownLink}`);
|
|
36
|
+
return markdownLink;
|
|
37
|
+
}
|
|
38
|
+
const labelFromNotion = match[1] || "";
|
|
39
|
+
const hrefFromNotion = match[2];
|
|
40
|
+
// verbose(
|
|
41
|
+
// `[standardInternalLinkConversion] Converting ${markdownLink} with has url ${hrefFromNotion}`
|
|
42
|
+
// );
|
|
43
|
+
const pages = context.pages;
|
|
44
|
+
// find the page where pageId matches hrefFromNotion
|
|
45
|
+
const targetPage = pages.find(p => {
|
|
46
|
+
return p.matchesLinkId(hrefFromNotion);
|
|
47
|
+
});
|
|
48
|
+
if (!targetPage) {
|
|
49
|
+
// About this situation. See https://github.com/sillsdev/docu-notion/issues/9
|
|
50
|
+
(0, log_1.warning)(`[standardInternalLinkConversion] Could not find the target of this link. Note that links to outline sections are not supported. ${markdownLink}. https://github.com/sillsdev/docu-notion/issues/9`);
|
|
51
|
+
return "**[Problem Internal Link]**";
|
|
52
|
+
}
|
|
53
|
+
const label = convertLinkLabel(targetPage, labelFromNotion);
|
|
54
|
+
const url = convertLinkHref(context, targetPage, hrefFromNotion);
|
|
55
|
+
return `[${label}](${url})`;
|
|
56
|
+
}
|
|
57
|
+
function convertLinkLabel(targetPage, text) {
|
|
58
|
+
// In Notion, if you just add a link to a page without linking it to any text, then in Notion
|
|
59
|
+
// you see the name of the page as the text of the link. But when Notion gives us that same
|
|
60
|
+
// link, it uses "link_to_page" as the text. So we have to look up the name of the page in
|
|
61
|
+
// order to fix that.;
|
|
62
|
+
if (text !== "link_to_page")
|
|
63
|
+
return text;
|
|
64
|
+
else
|
|
65
|
+
return targetPage.nameOrTitle;
|
|
66
|
+
}
|
|
67
|
+
function convertLinkHref(context, targetPage, url) {
|
|
68
|
+
let convertedLink = context.layoutStrategy.getLinkPathForPage(targetPage);
|
|
69
|
+
/*****************************
|
|
70
|
+
NOTE: as of this writing, the official Notion API completely drops links
|
|
71
|
+
to headings, unless they are part of a inline link.
|
|
72
|
+
*******************************/
|
|
73
|
+
// Include the fragment (# and after) if it exists
|
|
74
|
+
const { fragmentId } = parseLinkId(url);
|
|
75
|
+
//verbose(`Parsed ${url} and got Fragment ID: ${fragmentId}`);
|
|
76
|
+
convertedLink += fragmentId;
|
|
77
|
+
//verbose(`Converting Link ${url} --> ${convertedLink}`);
|
|
78
|
+
return convertedLink;
|
|
79
|
+
}
|
|
80
|
+
// Parse the link ID to get the base (before the #) and the fragment (# and after).
|
|
81
|
+
function parseLinkId(fullLinkId) {
|
|
82
|
+
const iHash = fullLinkId.indexOf("#");
|
|
83
|
+
if (iHash >= 0) {
|
|
84
|
+
return {
|
|
85
|
+
baseLinkId: fullLinkId.substring(0, iHash),
|
|
86
|
+
fragmentId: fullLinkId.substring(iHash),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return { baseLinkId: fullLinkId, fragmentId: "" };
|
|
90
|
+
}
|
|
91
|
+
exports.parseLinkId = parseLinkId;
|
|
92
|
+
exports.standardInternalLinkConversion = {
|
|
93
|
+
name: "standard internal link conversion",
|
|
94
|
+
linkModifier: {
|
|
95
|
+
// from notion (or notion-md?) we get slightly different hrefs depending on whether the links is "inline"
|
|
96
|
+
// (has some other text that's been turned into a link) or "raw".
|
|
97
|
+
// Raw links come in without a leading slash, e.g. [link_to_page](4a6de8c0-b90b-444b-8a7b-d534d6ec71a4)
|
|
98
|
+
// Inline links come in with a leading slash, e.g. [pointer to the introduction](/4a6de8c0b90b444b8a7bd534d6ec71a4)
|
|
99
|
+
match: /\[([^\]]+)?\]\((?!mailto:)(\/?[^),^/]+)\)/,
|
|
100
|
+
convert: convertInternalLink,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|