-
-
Notifications
You must be signed in to change notification settings - Fork 117
change rich_text to text for code. #157
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe change updates the way code content is extracted from Notion "code" blocks by switching from using the Changes
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
| case "code": | ||
| { | ||
| const codeContent = block.code.rich_text.map((t: any) => t.plain_text).join("\n"); | ||
| const codeContent = block.code.text.map((t: any) => t.plain_text).join("\n"); |
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.
💡 Verification agent
🧩 Analysis chain
Verify that block.code.text is the correct property according to the Notion API.
The change from block.code.rich_text to block.code.text looks syntactically correct and maintains the same extraction logic. However, please confirm that the text property exists on code blocks and has the expected structure with plain_text fields.
🌐 Web query:
What is the correct property name for extracting text content from Notion code blocks according to the latest Notion API documentation?
💡 Result:
According to the latest Notion API documentation, to extract the text content from a Notion code block, you should reference the rich_text array within the block’s type-specific object, and then access the plain_text property of the rich text elements.
For a code block object, the structure is:
{
"object": "block",
"type": "code",
"code": {
"caption": [ ... ],
"rich_text": [
{
"type": "text",
"plain_text": "your code here",
...
}
],
"language": "python"
}
}- The correct property path to the text content is:
code.rich_text[].plain_text
You need to iterate through the rich_text array inside the code object and concatenate the plain_text fields to obtain the full text content of the code block[10].
All rich_text objects will include a plain_text property, which provides a convenient way for developers to access unformatted text from the Notion block[10].
This approach is consistent for extracting plain text from other rich-text-based block types (e.g., paragraphs, headings) as well[3][10].
Summary:
- Use code.rich_text[].plain_text to extract the text content of a Notion code block via the Notion API[10].
Citations:
- 1: https://community.zapier.com/featured-articles-65/workaround-how-to-extract-page-content-from-notion-40099
- 2: https://community.latenode.com/t/using-the-notion-api-with-python-to-retrieve-block-mentions/22170
- 3: https://community.make.com/t/best-way-to-extract-content-from-notion-page/49450
- 4: https://developers.notion.com/reference/block
- 5: https://community.latenode.com/t/how-do-i-extract-content-from-a-notion-page-using-the-notion-api/5474
- 6: https://community.latenode.com/t/trouble-extracting-notion-page-title-via-api/15515
- 7: https://developers.notion.com/docs/working-with-page-content
- 8: https://community.make.com/t/extract-text-content-from-a-list-page-contents-notion-module/38406
- 9: https://www.notion.com/help/formula-syntax
- 10: https://developers.notion.com/reference/rich-text
Use code.rich_text instead of code.text for Notion code blocks
The Notion API places code content in block.code.rich_text, not block.code.text. Please revert the property change to match the official spec.
• Location to fix:
- src/notion-to-md.ts, line 503
• Updated snippet:
- const codeContent = block.code.text.map((t: any) => t.plain_text).join("\n");
+ const codeContent = block.code.rich_text.map((t: any) => t.plain_text).join("\n");📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const codeContent = block.code.text.map((t: any) => t.plain_text).join("\n"); | |
| const codeContent = block.code.rich_text.map((t: any) => t.plain_text).join("\n"); |
🤖 Prompt for AI Agents
In src/notion-to-md.ts at line 503, the code incorrectly accesses code content
using block.code.text, but according to the Notion API spec, the correct
property is block.code.rich_text. Update the code to use block.code.rich_text
instead of block.code.text to properly retrieve the code content.
|
Hi @Doradx thanks for the PR. Can you elaborate the issue that you faced and how this fixes it? Looking at Notion docs I can see the current logic works fine. |
Summary by CodeRabbit