souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.08k stars 89 forks source link

Ordered list parsed as unordered list #108

Open ddsuhaimi opened 3 months ago

ddsuhaimi commented 3 months ago

notion-md-version: 3.1.1

A notion block with type numbered_list_item got parse as unordered list. You can check out minimal working example here:

const { Client } = require('@notionhq/client');
const { NotionToMarkdown } = require('notion-to-md');

const blocks = [
  {
    object: 'block',
    id: 'xxxxxxxxx',
    parent: { type: 'page_id', page_id: 'pxxxxxxxxxx' },
    created_time: '2023-12-13T16:55:00.000Z',
    last_edited_time: '2023-12-15T07:32:00.000Z',
    created_by: { object: 'user', id: 'userxxxxxxx' },
    last_edited_by: {
      object: 'user',
      id: 'userxxxxxxx',
    },
    has_children: false,
    archived: false,
    in_trash: false,
    type: 'numbered_list_item',
    numbered_list_item: {
      rich_text: [
        {
          type: 'text',
          text: { content: 'Numbered Item 1', link: null },
          annotations: {
            bold: false,
            italic: false,
            strikethrough: false,
            underline: false,
            code: false,
            color: 'default',
          },
          plain_text: 'Numbered Item 1',
          href: null,
        },
      ],
      color: 'default',
    },
  },
  {
    object: 'block',
    id: 'xxxxxxxxx',
    parent: { type: 'page_id', page_id: 'pxxxxxxxxxx' },
    created_time: '2023-12-13T16:55:00.000Z',
    last_edited_time: '2023-12-15T07:32:00.000Z',
    created_by: { object: 'user', id: 'userxxxxxxx' },
    last_edited_by: {
      object: 'user',
      id: 'userxxxxxxx',
    },
    has_children: false,
    archived: false,
    in_trash: false,
    type: 'numbered_list_item',
    numbered_list_item: {
      rich_text: [
        {
          type: 'text',
          text: { content: 'Numbered Item 2', link: null },
          annotations: {
            bold: false,
            italic: false,
            strikethrough: false,
            underline: false,
            code: false,
            color: 'default',
          },
          plain_text: 'Numbered Item 2',
          href: null,
        },
      ],
      color: 'default',
    },
  },
];

const notion = new Client({
  auth: '',
});

const n2m = new NotionToMarkdown({ notionClient: notion });

async function run() {
  const mdblocks = await n2m.blocksToMarkdown(blocks);
  const mdstring = n2m.toMarkdownString(mdblocks);
  console.log(mdstring.parent);
}

run();

Result:

- Numbered Item 1
- Numbered Item 2

Expected:

1. Numbered Item 1
2. Numbered Item 2

EDIT: apparently it works if we get the blocks from n2m.pageToMarkdown("target_page_id") instead of using blocks response from notion API. So might not be an issue :)