-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for Notion callout blocks #66
base: master
Are you sure you want to change the base?
feat: Add support for Notion callout blocks #66
Conversation
This looks super cool! So I don't think this should be enabled by default, but it would be a cool feature to put behind some kind of flag! |
I could change it to use the GFM syntax by default, and add a flag that uses the "enhanced" ReadMe markdown version instead (or as well?), which would allow more callout "titles", icons (emojis) and colors (based on the emoji to color map). What do you think @EndBug? |
@EndBug I added the GFM syntax now as the default callout syntax. The ReadMe markdown syntax (emoji callouts) now need to be enabled by setting: const options = {
enableEmojiCallouts: true,
}; Would this work for you? |
2e27970
to
496fee9
Compare
@EndBug Thanks for improving the implementation! |
@EndBug I just took a closer look, and I am curious as to why you removed the In function parseBlockquote(
element: md.Blockquote,
options: BlocksOptions
): notion.Block {
const firstChild = element.children[0];
const firstTextNode =
firstChild?.type === 'paragraph'
? (firstChild as md.Paragraph).children[0]
: null;
if (firstTextNode?.type === 'text') {
// Helper to parse subsequent blocks
const parseSubsequentBlocks = () =>
element.children.length > 1
? element.children.slice(1).flatMap(child => parseNode(child, options))
: [];
// Check for GFM alert syntax first (both escaped and unescaped)
const firstLine = firstTextNode.value.split('\n')[0];
const gfmMatch = firstLine.match(
/^(?:\\\[|\[)!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]$/
);
if (gfmMatch && notion.isGfmAlertType(gfmMatch[1])) {
const alertType = gfmMatch[1];
const alertConfig = notion.GFM_ALERT_MAP[alertType];
const displayType =
alertType.charAt(0).toUpperCase() + alertType.slice(1).toLowerCase();
const children = [];
const contentLines = firstTextNode.value.split('\n').slice(1);
if (contentLines.length > 0) {
children.push(
notion.paragraph(
parseInline({
type: 'text',
value: contentLines.join('\n'),
})
)
);
}
children.push(...parseSubsequentBlocks());
return notion.callout(
[notion.richText(displayType)],
alertConfig.emoji,
alertConfig.color,
children
);
}
// Check for emoji syntax if enabled
if (options.enableEmojiCallouts) {
const emojiData = notion.parseCalloutEmoji(firstTextNode.value);
if (emojiData) {
const paragraph = firstChild as md.Paragraph;
const textWithoutEmoji = firstTextNode.value
.slice(emojiData.emoji.length)
.trimStart();
// Process inline content from first paragraph
const richText = paragraph.children.flatMap(child =>
child === firstTextNode
? textWithoutEmoji
? parseInline({type: 'text', value: textWithoutEmoji})
: []
: parseInline(child)
);
return notion.callout(
richText,
emojiData.emoji,
emojiData.color,
parseSubsequentBlocks()
);
}
}
}
const children = element.children.flatMap(child => parseNode(child, options));
return notion.blockquote([], children);
} I added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heyy
So I did push a commit, but I then removed it because I saw it didn't match Notion's API.
I now fixed a couple of issues, but I think the main one is that the Notion client library is not up to date
We shuould try updating that to see if they have better typings
@EndBug I have a clean branch from master where I have updated the Notion client library here: I will make it into a PR, then if we can merge that successfully, we can use that to finalise this implementation. |
This PR adds support for Notion callout blocks with emoji-based styling, following ReadMe's markdown callout syntax.
Changes
Supported callout styles
Example usage