@moxn/kb-migrate 0.4.15 → 0.4.16
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 +57 -2
- package/package.json +1 -1
package/dist/targets/notion.js
CHANGED
|
@@ -184,6 +184,49 @@ 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. This function detects the emoji
|
|
192
|
+
* prefix pattern and converts matching quotes back to native Notion `callout` blocks.
|
|
193
|
+
*/
|
|
194
|
+
function reconstructCallouts(blocks) {
|
|
195
|
+
const emojiPrefixRe = /^(\p{Emoji_Presentation}|\p{Emoji}\uFE0F?)\s/u;
|
|
196
|
+
return blocks.map((block) => {
|
|
197
|
+
if (block.type !== 'quote')
|
|
198
|
+
return block;
|
|
199
|
+
const richText = block.quote?.rich_text;
|
|
200
|
+
if (!richText?.length)
|
|
201
|
+
return block;
|
|
202
|
+
const firstSegment = richText[0];
|
|
203
|
+
if (firstSegment.type !== 'text' || !firstSegment.text?.content)
|
|
204
|
+
return block;
|
|
205
|
+
const match = firstSegment.text.content.match(emojiPrefixRe);
|
|
206
|
+
if (!match)
|
|
207
|
+
return block;
|
|
208
|
+
const emoji = match[1];
|
|
209
|
+
const strippedContent = firstSegment.text.content.slice(match[0].length);
|
|
210
|
+
const updatedRichText = [
|
|
211
|
+
{ ...firstSegment, text: { ...firstSegment.text, content: strippedContent }, plain_text: strippedContent },
|
|
212
|
+
...richText.slice(1),
|
|
213
|
+
].filter((rt) => {
|
|
214
|
+
const seg = rt;
|
|
215
|
+
return seg.text?.content || seg.plain_text;
|
|
216
|
+
});
|
|
217
|
+
const quoteBlock = block;
|
|
218
|
+
return {
|
|
219
|
+
object: 'block',
|
|
220
|
+
type: 'callout',
|
|
221
|
+
callout: {
|
|
222
|
+
rich_text: updatedRichText,
|
|
223
|
+
icon: { type: 'emoji', emoji },
|
|
224
|
+
color: 'default',
|
|
225
|
+
...(quoteBlock.quote?.children ? { children: quoteBlock.quote.children } : {}),
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
}
|
|
187
230
|
/**
|
|
188
231
|
* Convert KB document sections to Notion blocks.
|
|
189
232
|
*
|
|
@@ -206,7 +249,7 @@ async function sectionsToNotionBlocks(sections, options) {
|
|
|
206
249
|
return;
|
|
207
250
|
const md = pendingMarkdown.join('\n').trim();
|
|
208
251
|
if (md) {
|
|
209
|
-
allBlocks.push(...markdownToBlocks(md));
|
|
252
|
+
allBlocks.push(...reconstructCallouts(markdownToBlocks(md)));
|
|
210
253
|
}
|
|
211
254
|
pendingMarkdown = [];
|
|
212
255
|
}
|
|
@@ -222,7 +265,19 @@ async function sectionsToNotionBlocks(sections, options) {
|
|
|
222
265
|
allReferences.push(...references);
|
|
223
266
|
}
|
|
224
267
|
text = stripInvalidLinks(text);
|
|
225
|
-
|
|
268
|
+
// Split on standalone --- dividers and emit native Notion divider blocks
|
|
269
|
+
const parts = text.split(/\n---\n/);
|
|
270
|
+
for (let i = 0; i < parts.length; i++) {
|
|
271
|
+
if (i > 0) {
|
|
272
|
+
flushText();
|
|
273
|
+
allBlocks.push({ object: 'block', type: 'divider', divider: {} });
|
|
274
|
+
}
|
|
275
|
+
// Handle --- at start (empty first part) or end (empty last part)
|
|
276
|
+
const part = parts[i];
|
|
277
|
+
if (part.trim()) {
|
|
278
|
+
pendingMarkdown.push(part);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
226
281
|
pendingMarkdown.push('');
|
|
227
282
|
}
|
|
228
283
|
else if (block.blockType === 'image' && block.url) {
|
package/package.json
CHANGED