@moxn/kb-migrate 0.4.15 → 0.4.17
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/dist/targets/notion.js +71 -2
- package/package.json +1 -1
package/dist/targets/notion.js
CHANGED
|
@@ -184,6 +184,55 @@ async function uploadFileToNotion(client, url, filename, contentType) {
|
|
|
184
184
|
return null;
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Post-process martian output to reconstruct callout blocks.
|
|
189
|
+
*
|
|
190
|
+
* Callouts are stored as blockquotes with an emoji prefix (e.g., `> 💡 tip text`).
|
|
191
|
+
* Martian converts these to Notion `quote` blocks with the actual text inside
|
|
192
|
+
* `children[].paragraph.rich_text` (not the top-level `rich_text`).
|
|
193
|
+
* This function detects the emoji prefix pattern in the first child paragraph
|
|
194
|
+
* and converts matching quotes to native Notion `callout` blocks.
|
|
195
|
+
*/
|
|
196
|
+
function reconstructCallouts(blocks) {
|
|
197
|
+
const emojiPrefixRe = /^(\p{Emoji_Presentation}|\p{Emoji}\uFE0F?)\s/u;
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
199
|
+
return blocks.map((block) => {
|
|
200
|
+
if (block.type !== 'quote')
|
|
201
|
+
return block;
|
|
202
|
+
const children = block.quote?.children;
|
|
203
|
+
if (!children?.length)
|
|
204
|
+
return block;
|
|
205
|
+
// Find the first child paragraph with text
|
|
206
|
+
const firstChild = children[0];
|
|
207
|
+
if (firstChild.type !== 'paragraph' || !firstChild.paragraph?.rich_text?.length)
|
|
208
|
+
return block;
|
|
209
|
+
const firstSegment = firstChild.paragraph.rich_text[0];
|
|
210
|
+
if (firstSegment.type !== 'text' || !firstSegment.text?.content)
|
|
211
|
+
return block;
|
|
212
|
+
const match = firstSegment.text.content.match(emojiPrefixRe);
|
|
213
|
+
if (!match)
|
|
214
|
+
return block; // No emoji prefix — keep as regular quote
|
|
215
|
+
const emoji = match[1];
|
|
216
|
+
const strippedContent = firstSegment.text.content.slice(match[0].length);
|
|
217
|
+
// Build the callout's rich_text from the first child paragraph (stripped of emoji)
|
|
218
|
+
const calloutRichText = [
|
|
219
|
+
{ ...firstSegment, text: { ...firstSegment.text, content: strippedContent } },
|
|
220
|
+
...firstChild.paragraph.rich_text.slice(1),
|
|
221
|
+
].filter((rt) => rt.text?.content);
|
|
222
|
+
// Remaining children become the callout's children
|
|
223
|
+
const remainingChildren = children.slice(1);
|
|
224
|
+
return {
|
|
225
|
+
object: 'block',
|
|
226
|
+
type: 'callout',
|
|
227
|
+
callout: {
|
|
228
|
+
rich_text: calloutRichText,
|
|
229
|
+
icon: { type: 'emoji', emoji },
|
|
230
|
+
color: 'default',
|
|
231
|
+
...(remainingChildren.length > 0 ? { children: remainingChildren } : {}),
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
}
|
|
187
236
|
/**
|
|
188
237
|
* Convert KB document sections to Notion blocks.
|
|
189
238
|
*
|
|
@@ -206,7 +255,7 @@ async function sectionsToNotionBlocks(sections, options) {
|
|
|
206
255
|
return;
|
|
207
256
|
const md = pendingMarkdown.join('\n').trim();
|
|
208
257
|
if (md) {
|
|
209
|
-
allBlocks.push(...markdownToBlocks(md));
|
|
258
|
+
allBlocks.push(...reconstructCallouts(markdownToBlocks(md)));
|
|
210
259
|
}
|
|
211
260
|
pendingMarkdown = [];
|
|
212
261
|
}
|
|
@@ -222,7 +271,27 @@ async function sectionsToNotionBlocks(sections, options) {
|
|
|
222
271
|
allReferences.push(...references);
|
|
223
272
|
}
|
|
224
273
|
text = stripInvalidLinks(text);
|
|
225
|
-
|
|
274
|
+
// Split on standalone --- dividers and emit native Notion divider blocks.
|
|
275
|
+
// Pad with newlines so --- at start/end of text is also caught.
|
|
276
|
+
const padded = '\n' + text + '\n';
|
|
277
|
+
const rawParts = padded.split('\n---\n');
|
|
278
|
+
const parts = rawParts.map((p, idx) => {
|
|
279
|
+
if (idx === 0)
|
|
280
|
+
p = p.slice(1); // remove leading \n pad
|
|
281
|
+
if (idx === rawParts.length - 1)
|
|
282
|
+
p = p.slice(0, -1); // remove trailing \n pad
|
|
283
|
+
return p;
|
|
284
|
+
});
|
|
285
|
+
for (let i = 0; i < parts.length; i++) {
|
|
286
|
+
if (i > 0) {
|
|
287
|
+
flushText();
|
|
288
|
+
allBlocks.push({ object: 'block', type: 'divider', divider: {} });
|
|
289
|
+
}
|
|
290
|
+
const part = parts[i];
|
|
291
|
+
if (part.trim()) {
|
|
292
|
+
pendingMarkdown.push(part);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
226
295
|
pendingMarkdown.push('');
|
|
227
296
|
}
|
|
228
297
|
else if (block.blockType === 'image' && block.url) {
|
package/package.json
CHANGED