Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/notion-to-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class NotionToMarkdown {
switch (type) {
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");
Copy link

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:


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.

Suggested change
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.

const language = block.code.language || "plaintext";
parsedData = md.codeBlock(codeContent, language);
}
Expand Down