@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,505 @@
|
|
|
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 CalloutTransformer_1 = require("./CalloutTransformer");
|
|
15
|
+
const externalLinks_1 = require("./externalLinks");
|
|
16
|
+
const internalLinks_1 = require("./internalLinks");
|
|
17
|
+
const NumberedListTransformer_1 = require("./NumberedListTransformer");
|
|
18
|
+
test("urls that show up as raw text get left that way", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const results = yield getMarkdown({
|
|
20
|
+
type: "paragraph",
|
|
21
|
+
paragraph: {
|
|
22
|
+
rich_text: [
|
|
23
|
+
{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: { content: "https://github.com", link: null },
|
|
26
|
+
annotations: {
|
|
27
|
+
bold: false,
|
|
28
|
+
italic: false,
|
|
29
|
+
strikethrough: false,
|
|
30
|
+
underline: false,
|
|
31
|
+
code: false,
|
|
32
|
+
color: "default",
|
|
33
|
+
},
|
|
34
|
+
plain_text: "https://github.com",
|
|
35
|
+
href: null,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
expect(results.trim()).toBe("https://github.com");
|
|
41
|
+
}));
|
|
42
|
+
test("link to an existing page on this site that has no slug", () => __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: "text",
|
|
55
|
+
text: { content: "Inline ", link: null },
|
|
56
|
+
annotations: {
|
|
57
|
+
bold: false,
|
|
58
|
+
italic: false,
|
|
59
|
+
strikethrough: false,
|
|
60
|
+
underline: false,
|
|
61
|
+
code: false,
|
|
62
|
+
color: "default",
|
|
63
|
+
},
|
|
64
|
+
plain_text: "Inline ",
|
|
65
|
+
href: null,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: "text",
|
|
69
|
+
text: {
|
|
70
|
+
content: "great page",
|
|
71
|
+
link: { url: `/${targetPageId}` },
|
|
72
|
+
},
|
|
73
|
+
annotations: {
|
|
74
|
+
bold: false,
|
|
75
|
+
italic: false,
|
|
76
|
+
strikethrough: false,
|
|
77
|
+
underline: false,
|
|
78
|
+
code: false,
|
|
79
|
+
color: "default",
|
|
80
|
+
},
|
|
81
|
+
plain_text: "great page",
|
|
82
|
+
href: `/${targetPageId}`,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: "text",
|
|
86
|
+
text: { content: " the end.", link: null },
|
|
87
|
+
annotations: {
|
|
88
|
+
bold: false,
|
|
89
|
+
italic: false,
|
|
90
|
+
strikethrough: false,
|
|
91
|
+
underline: false,
|
|
92
|
+
code: false,
|
|
93
|
+
color: "default",
|
|
94
|
+
},
|
|
95
|
+
plain_text: " the end.",
|
|
96
|
+
href: null,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
color: "default",
|
|
100
|
+
},
|
|
101
|
+
}, targetPage);
|
|
102
|
+
expect(results.trim()).toBe(`Inline [great page](/${targetPageId}) the end.`);
|
|
103
|
+
}));
|
|
104
|
+
test("link to a heading block on a page", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
const targetPageId = "123";
|
|
106
|
+
const blocks = {
|
|
107
|
+
type: "paragraph",
|
|
108
|
+
paragraph: {
|
|
109
|
+
rich_text: [
|
|
110
|
+
{
|
|
111
|
+
type: "text",
|
|
112
|
+
text: { content: "(Inline ", link: null },
|
|
113
|
+
annotations: {
|
|
114
|
+
bold: false,
|
|
115
|
+
italic: false,
|
|
116
|
+
strikethrough: false,
|
|
117
|
+
underline: false,
|
|
118
|
+
code: false,
|
|
119
|
+
color: "default",
|
|
120
|
+
},
|
|
121
|
+
plain_text: "(Inline ",
|
|
122
|
+
href: null,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: "text",
|
|
126
|
+
text: {
|
|
127
|
+
content: "heading on some page",
|
|
128
|
+
link: { url: `/${targetPageId}#456` },
|
|
129
|
+
},
|
|
130
|
+
annotations: {
|
|
131
|
+
bold: false,
|
|
132
|
+
italic: false,
|
|
133
|
+
strikethrough: false,
|
|
134
|
+
underline: false,
|
|
135
|
+
code: false,
|
|
136
|
+
color: "default",
|
|
137
|
+
},
|
|
138
|
+
plain_text: "heading on some page",
|
|
139
|
+
href: `/${targetPageId}#456`,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: "text",
|
|
143
|
+
text: { content: " the end.)", link: null },
|
|
144
|
+
annotations: {
|
|
145
|
+
bold: false,
|
|
146
|
+
italic: false,
|
|
147
|
+
strikethrough: false,
|
|
148
|
+
underline: false,
|
|
149
|
+
code: false,
|
|
150
|
+
color: "default",
|
|
151
|
+
},
|
|
152
|
+
plain_text: " the end.)",
|
|
153
|
+
href: null,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
color: "default",
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
(0, log_1.setLogLevel)("verbose");
|
|
160
|
+
const noSlugTargetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
161
|
+
slug: undefined,
|
|
162
|
+
name: "Hello World",
|
|
163
|
+
id: targetPageId,
|
|
164
|
+
});
|
|
165
|
+
const noSlugResults = yield getMarkdown(blocks, noSlugTargetPage);
|
|
166
|
+
// the ending parentheses messed up a regex at one point.
|
|
167
|
+
expect(noSlugResults.trim()).toBe(`(Inline [heading on some page](/${targetPageId}#456) the end.)`);
|
|
168
|
+
const slugTargetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
169
|
+
slug: "hello-world",
|
|
170
|
+
name: "Hello World",
|
|
171
|
+
id: targetPageId,
|
|
172
|
+
});
|
|
173
|
+
const slugResults = yield getMarkdown(blocks, slugTargetPage);
|
|
174
|
+
expect(slugResults.trim()).toBe(`(Inline [heading on some page](/hello-world#456) the end.)`);
|
|
175
|
+
}));
|
|
176
|
+
// Text that has been selected and turned into a link to one of our pages
|
|
177
|
+
test("inline link to an existing page on this site uses slug", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
const targetPageId = "123";
|
|
179
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
180
|
+
slug: "hello-world",
|
|
181
|
+
name: "Hello World",
|
|
182
|
+
id: targetPageId,
|
|
183
|
+
});
|
|
184
|
+
const results = yield getMarkdown({
|
|
185
|
+
type: "paragraph",
|
|
186
|
+
paragraph: {
|
|
187
|
+
rich_text: [
|
|
188
|
+
{
|
|
189
|
+
type: "text",
|
|
190
|
+
text: { content: "Inline ", link: null },
|
|
191
|
+
annotations: {
|
|
192
|
+
bold: false,
|
|
193
|
+
italic: false,
|
|
194
|
+
strikethrough: false,
|
|
195
|
+
underline: false,
|
|
196
|
+
code: false,
|
|
197
|
+
color: "default",
|
|
198
|
+
},
|
|
199
|
+
plain_text: "Inline ",
|
|
200
|
+
href: null,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
type: "text",
|
|
204
|
+
text: {
|
|
205
|
+
content: "It’s good",
|
|
206
|
+
link: { url: `/${targetPageId}` },
|
|
207
|
+
},
|
|
208
|
+
annotations: {
|
|
209
|
+
bold: false,
|
|
210
|
+
italic: false,
|
|
211
|
+
strikethrough: false,
|
|
212
|
+
underline: false,
|
|
213
|
+
code: false,
|
|
214
|
+
color: "default",
|
|
215
|
+
},
|
|
216
|
+
plain_text: "It’s good",
|
|
217
|
+
href: `/${targetPageId}`,
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
color: "default",
|
|
221
|
+
},
|
|
222
|
+
}, targetPage);
|
|
223
|
+
expect(results.trim()).toBe("Inline [It’s good](/hello-world)");
|
|
224
|
+
}));
|
|
225
|
+
// this is the kind of link you get if you just insert a "link to page" to Notion
|
|
226
|
+
test("raw link to an existing page on this site that has a slug", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
227
|
+
const targetPageId = "123";
|
|
228
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
229
|
+
slug: "point-to-me",
|
|
230
|
+
name: "Point to Me",
|
|
231
|
+
id: targetPageId,
|
|
232
|
+
});
|
|
233
|
+
const results = yield getMarkdown({
|
|
234
|
+
object: "block",
|
|
235
|
+
id: "2051d790-e527-4b4e-b145-ec0beee2addf",
|
|
236
|
+
parent: {
|
|
237
|
+
type: "page_id",
|
|
238
|
+
page_id: "333",
|
|
239
|
+
},
|
|
240
|
+
created_time: "2023-06-14T20:09:00.000Z",
|
|
241
|
+
last_edited_time: "2023-06-14T20:09:00.000Z",
|
|
242
|
+
has_children: false,
|
|
243
|
+
archived: false,
|
|
244
|
+
type: "link_to_page",
|
|
245
|
+
link_to_page: {
|
|
246
|
+
type: "page_id",
|
|
247
|
+
page_id: targetPageId,
|
|
248
|
+
},
|
|
249
|
+
}, targetPage);
|
|
250
|
+
expect(results.trim()).toBe("[Point to Me](/point-to-me)");
|
|
251
|
+
}));
|
|
252
|
+
test("link in a bulleted list", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
253
|
+
const targetPageId = "123";
|
|
254
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
255
|
+
slug: "the-page",
|
|
256
|
+
name: "Something",
|
|
257
|
+
id: targetPageId,
|
|
258
|
+
});
|
|
259
|
+
const results = yield getMarkdown({
|
|
260
|
+
type: "bulleted_list_item",
|
|
261
|
+
bulleted_list_item: {
|
|
262
|
+
rich_text: [
|
|
263
|
+
{
|
|
264
|
+
type: "text",
|
|
265
|
+
text: {
|
|
266
|
+
content: "item",
|
|
267
|
+
link: { url: "/123" },
|
|
268
|
+
},
|
|
269
|
+
annotations: {
|
|
270
|
+
bold: false,
|
|
271
|
+
italic: false,
|
|
272
|
+
strikethrough: false,
|
|
273
|
+
underline: false,
|
|
274
|
+
code: false,
|
|
275
|
+
color: "default",
|
|
276
|
+
},
|
|
277
|
+
plain_text: "item",
|
|
278
|
+
href: "/123",
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
color: "default",
|
|
282
|
+
},
|
|
283
|
+
}, targetPage);
|
|
284
|
+
expect(results.trim()).toBe("- [item](/the-page)");
|
|
285
|
+
}));
|
|
286
|
+
test("link to an a heading on a page on this site uses slug", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
287
|
+
const targetPageId = "123";
|
|
288
|
+
const headingBlockId = "456";
|
|
289
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
290
|
+
slug: "hello-world",
|
|
291
|
+
name: "Hello World",
|
|
292
|
+
id: targetPageId,
|
|
293
|
+
});
|
|
294
|
+
const results = yield getMarkdown({
|
|
295
|
+
type: "paragraph",
|
|
296
|
+
paragraph: {
|
|
297
|
+
rich_text: [
|
|
298
|
+
{
|
|
299
|
+
type: "text",
|
|
300
|
+
text: {
|
|
301
|
+
content: "see this heading",
|
|
302
|
+
link: { url: `/${targetPageId}#${headingBlockId}` },
|
|
303
|
+
},
|
|
304
|
+
annotations: {
|
|
305
|
+
bold: false,
|
|
306
|
+
italic: false,
|
|
307
|
+
strikethrough: false,
|
|
308
|
+
underline: false,
|
|
309
|
+
code: false,
|
|
310
|
+
color: "default",
|
|
311
|
+
},
|
|
312
|
+
plain_text: "see this heading",
|
|
313
|
+
href: `/${targetPageId}#${headingBlockId}`,
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
color: "default",
|
|
317
|
+
},
|
|
318
|
+
}, targetPage);
|
|
319
|
+
expect(results.trim()).toBe(`[see this heading](/hello-world#${headingBlockId})`);
|
|
320
|
+
}));
|
|
321
|
+
test("does not interfere with mailto links", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
322
|
+
const results = yield getMarkdown({
|
|
323
|
+
type: "paragraph",
|
|
324
|
+
paragraph: {
|
|
325
|
+
rich_text: [
|
|
326
|
+
{
|
|
327
|
+
type: "text",
|
|
328
|
+
text: {
|
|
329
|
+
content: "mailme",
|
|
330
|
+
link: { url: `mailto:foo@example.com` },
|
|
331
|
+
},
|
|
332
|
+
annotations: {
|
|
333
|
+
bold: false,
|
|
334
|
+
italic: false,
|
|
335
|
+
strikethrough: false,
|
|
336
|
+
underline: false,
|
|
337
|
+
code: false,
|
|
338
|
+
color: "default",
|
|
339
|
+
},
|
|
340
|
+
plain_text: "mailme",
|
|
341
|
+
href: `mailto:foo@example.com`,
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
color: "default",
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
expect(results.trim()).toBe(`[mailme](mailto:foo@example.com)`);
|
|
348
|
+
}));
|
|
349
|
+
test("links to other notion pages that are not in this site give PROBLEM LINK", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
350
|
+
const results = yield getMarkdown({
|
|
351
|
+
type: "paragraph",
|
|
352
|
+
paragraph: {
|
|
353
|
+
rich_text: [
|
|
354
|
+
{
|
|
355
|
+
type: "text",
|
|
356
|
+
text: { content: "Inline ", link: null },
|
|
357
|
+
annotations: {
|
|
358
|
+
bold: false,
|
|
359
|
+
italic: false,
|
|
360
|
+
strikethrough: false,
|
|
361
|
+
underline: false,
|
|
362
|
+
code: false,
|
|
363
|
+
color: "default",
|
|
364
|
+
},
|
|
365
|
+
plain_text: "Inline ",
|
|
366
|
+
href: null,
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
type: "text",
|
|
370
|
+
text: {
|
|
371
|
+
content: "links page",
|
|
372
|
+
link: { url: "/pretendidofpagewedonothaveinthissite" },
|
|
373
|
+
},
|
|
374
|
+
annotations: {
|
|
375
|
+
bold: false,
|
|
376
|
+
italic: false,
|
|
377
|
+
strikethrough: false,
|
|
378
|
+
underline: false,
|
|
379
|
+
code: false,
|
|
380
|
+
color: "default",
|
|
381
|
+
},
|
|
382
|
+
plain_text: "links page",
|
|
383
|
+
href: "/pretendidofpagewedonothaveinthissite",
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
color: "default",
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
expect(results.trim()).toBe("Inline **[Problem Internal Link]**");
|
|
390
|
+
}));
|
|
391
|
+
test("internal link inside callout", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
392
|
+
const targetPageId = "123";
|
|
393
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
394
|
+
slug: "hello-world",
|
|
395
|
+
name: "Hello World",
|
|
396
|
+
id: targetPageId,
|
|
397
|
+
});
|
|
398
|
+
const results = yield getMarkdown({
|
|
399
|
+
type: "callout",
|
|
400
|
+
callout: {
|
|
401
|
+
rich_text: [
|
|
402
|
+
{
|
|
403
|
+
type: "text",
|
|
404
|
+
text: { content: "Callouts inline ", link: null },
|
|
405
|
+
annotations: {
|
|
406
|
+
bold: false,
|
|
407
|
+
italic: false,
|
|
408
|
+
strikethrough: false,
|
|
409
|
+
underline: false,
|
|
410
|
+
code: false,
|
|
411
|
+
color: "default",
|
|
412
|
+
},
|
|
413
|
+
plain_text: "Callouts inline ",
|
|
414
|
+
href: null,
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
type: "text",
|
|
418
|
+
text: {
|
|
419
|
+
content: "great page",
|
|
420
|
+
link: { url: `/${targetPageId}` },
|
|
421
|
+
},
|
|
422
|
+
annotations: {
|
|
423
|
+
bold: false,
|
|
424
|
+
italic: false,
|
|
425
|
+
strikethrough: false,
|
|
426
|
+
underline: false,
|
|
427
|
+
code: false,
|
|
428
|
+
color: "default",
|
|
429
|
+
},
|
|
430
|
+
plain_text: "great page",
|
|
431
|
+
href: `/${targetPageId}`,
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
type: "text",
|
|
435
|
+
text: { content: ".", link: null },
|
|
436
|
+
annotations: {
|
|
437
|
+
bold: false,
|
|
438
|
+
italic: false,
|
|
439
|
+
strikethrough: false,
|
|
440
|
+
underline: false,
|
|
441
|
+
code: false,
|
|
442
|
+
color: "default",
|
|
443
|
+
},
|
|
444
|
+
plain_text: ".",
|
|
445
|
+
href: null,
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
icon: { type: "emoji", emoji: "⚠️" },
|
|
449
|
+
color: "gray_background",
|
|
450
|
+
},
|
|
451
|
+
}, targetPage);
|
|
452
|
+
expect(results.trim()).toBe(`:::caution
|
|
453
|
+
|
|
454
|
+
Callouts inline [great page](/hello-world).
|
|
455
|
+
|
|
456
|
+
:::`);
|
|
457
|
+
}));
|
|
458
|
+
test("internal link inside codeblock ignored", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
459
|
+
const targetPageId = "123";
|
|
460
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
461
|
+
slug: "hello-world",
|
|
462
|
+
name: "Hello World",
|
|
463
|
+
id: targetPageId,
|
|
464
|
+
});
|
|
465
|
+
const results = yield getMarkdown({
|
|
466
|
+
type: "code",
|
|
467
|
+
code: {
|
|
468
|
+
caption: [],
|
|
469
|
+
rich_text: [
|
|
470
|
+
{
|
|
471
|
+
type: "text",
|
|
472
|
+
text: {
|
|
473
|
+
content: "this should not change [link](https://www.notion.so/native/metapages/mypage)",
|
|
474
|
+
link: null,
|
|
475
|
+
},
|
|
476
|
+
annotations: {
|
|
477
|
+
bold: false,
|
|
478
|
+
italic: false,
|
|
479
|
+
strikethrough: false,
|
|
480
|
+
underline: false,
|
|
481
|
+
code: false,
|
|
482
|
+
color: "default",
|
|
483
|
+
},
|
|
484
|
+
plain_text: "this should not change [link](https://www.notion.so/native/metapages/mypage)",
|
|
485
|
+
href: null,
|
|
486
|
+
},
|
|
487
|
+
],
|
|
488
|
+
language: "javascript", // notion assumed javascript in my test in which I didn't specify a language
|
|
489
|
+
},
|
|
490
|
+
}, targetPage);
|
|
491
|
+
expect(results.trim()).toContain("this should not change [link](https://www.notion.so/native/metapages/mypage)");
|
|
492
|
+
}));
|
|
493
|
+
function getMarkdown(block, targetPage) {
|
|
494
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
495
|
+
const config = {
|
|
496
|
+
plugins: [
|
|
497
|
+
CalloutTransformer_1.standardCalloutTransformer,
|
|
498
|
+
NumberedListTransformer_1.standardNumberedListTransformer,
|
|
499
|
+
internalLinks_1.standardInternalLinkConversion,
|
|
500
|
+
externalLinks_1.standardExternalLinkConversion,
|
|
501
|
+
],
|
|
502
|
+
};
|
|
503
|
+
return yield (0, pluginTestRun_1.oneBlockToMarkdown)(config, block, targetPage);
|
|
504
|
+
});
|
|
505
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
test("raw url inside a mermaid codeblock gets converted to path using slug of that page", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const targetPageId = "123";
|
|
16
|
+
const targetPage = (0, pluginTestRun_1.makeSamplePageObject)({
|
|
17
|
+
slug: "slug-of-target",
|
|
18
|
+
name: "My Target Page",
|
|
19
|
+
id: targetPageId,
|
|
20
|
+
});
|
|
21
|
+
const input = {
|
|
22
|
+
type: "code",
|
|
23
|
+
code: {
|
|
24
|
+
caption: [],
|
|
25
|
+
rich_text: [
|
|
26
|
+
{
|
|
27
|
+
type: "text",
|
|
28
|
+
text: {
|
|
29
|
+
content: `click A "https://www.notion.so/native/metapages/A-Page-${targetPageId}"`,
|
|
30
|
+
link: null,
|
|
31
|
+
},
|
|
32
|
+
annotations: {
|
|
33
|
+
bold: false,
|
|
34
|
+
italic: false,
|
|
35
|
+
strikethrough: false,
|
|
36
|
+
underline: false,
|
|
37
|
+
code: false,
|
|
38
|
+
color: "default",
|
|
39
|
+
},
|
|
40
|
+
plain_text: `click A "https://www.notion.so/native/metapages/A-Page-${targetPageId}"`,
|
|
41
|
+
href: null,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
language: "mermaid", // notion assumed javascript in my test in which I didn't specify a language
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
const mermaidLinks = {
|
|
48
|
+
name: "mermaidLinks",
|
|
49
|
+
regexMarkdownModifications: [
|
|
50
|
+
{
|
|
51
|
+
regex: /```mermaid\n.*"(https:\/\/www\.notion\.so\S+)"/,
|
|
52
|
+
includeCodeBlocks: true,
|
|
53
|
+
getReplacement: (context, match) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const url = match[1];
|
|
55
|
+
const docusaurusUrl = context.convertNotionLinkToLocalDocusaurusLink(url);
|
|
56
|
+
if (docusaurusUrl) {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
58
|
+
return yield match[0].replace(url, docusaurusUrl);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
(0, log_1.error)(`Could not convert link ${url} to a local docusaurus link`);
|
|
62
|
+
return match[0];
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
const config = {
|
|
69
|
+
plugins: [
|
|
70
|
+
// standardInternalLinkConversion,
|
|
71
|
+
// standardExternalLinkConversion,
|
|
72
|
+
mermaidLinks,
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
const results = yield (0, pluginTestRun_1.oneBlockToMarkdown)(config, input, targetPage);
|
|
76
|
+
expect(results.trim()).toContain(`click A "/slug-of-target"`);
|
|
77
|
+
}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NotionPage } from "../NotionPage";
|
|
2
|
+
import { IDocuNotionConfig } from "../config/configuration";
|
|
3
|
+
import { NotionBlock } from "../types";
|
|
4
|
+
export declare function blocksToMarkdown(config: IDocuNotionConfig, blocks: NotionBlock[], pages?: NotionPage[]): Promise<string>;
|
|
5
|
+
export declare function makeSamplePageObject(options: {
|
|
6
|
+
slug?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
}): NotionPage;
|
|
10
|
+
export declare function oneBlockToMarkdown(config: IDocuNotionConfig, block: object, targetPage?: NotionPage): Promise<string>;
|