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.11k stars 91 forks source link

A "raw" link to another notion page is dropped #31

Closed hatton closed 2 years ago

hatton commented 2 years ago

A raw link to another website, e.g. This is a bare to google https://www.google.com/ is emitted as This is a bare to google [https://www.google.com/](https://www.google.com/)

A bit of text with an underlying link to another page image

is emitted as This is an inline link another page [Apples](/c62dbc3fede94264a1d5e0245fa4be73).

However, if you have a link without a text label, then notion-to-md just drops it. This image is emitted as This is a raw link to the intro:

In the content returned by the API, this last case comes as this kind of block

 {
      "object": "block",
      "id": "5f4fdb6f-8adb-4cff-9137-2168530b78bf",
      <snip>
      "type": "link_to_page",
      "link_to_page": {
        "type": "page_id",
        "page_id": "8b16a919-6add-4e37-b1a4-4103feb24d5d"
      }
}
souvikinator commented 2 years ago

Hey there, Thanks for reporting the issue.

Had a look at the notionhq API response for all the above you have mentioned cases:

image

and here is the response:

image

here you can see the raw link to the page is not yet supported by notion API so that is something I can't help you out with.

It would be great if you can verify the same from yourside.

hatton commented 2 years ago

I appreciate you looking into this. I don't know exactly what kind of object it told you was unsupported. For me, @notionhq/client gives the result I showed in the original report.

The API has supported linked pages since November 2021. See Synced Block, Link to Page and Template block types are now supported in the API. @notionhq/client has supported it since 0.4.8. https://github.com/makenotion/notion-sdk-js/releases/tag/v0.4.8.

souvikinator commented 2 years ago

May I know the version of @notionhq/client you are using? This side it's v1.0.4 (latest). I tired it on different notion pages and databases as well but it still shows type: unsupported.

Mind sharing the code snippet you are using to get the response object?

hatton commented 2 years ago

Sure, here are full steps:

1) Duplicate this page: https://hattonjohn.notion.site/link_page-sample-a73ae52733ae4e98bc46923f0e7459b6 image

2) Share your own integration with your page

3) Code like this:

 "@notionhq/client": "^1.0.4",
import { Client } from "@notionhq/client";
import { env } from "process";

const notionClient = new Client({
  auth: env.YOUR_INTEGRATION_TOKEN,
});

notionClient.blocks.children
  .list({
    block_id: "<YOUR PAGE ID>",
  })
  .then(b => console.log(JSON.stringify(b, null, 2)))
  .catch(e => console.error(e));

$ ts-node src/link_page.ts
{
 ...
    {
      "object": "block",
      "id": "426ae49a-7373-47a8-992c-c5df7a9bf588",
      "created_time": "2022-05-27T14:00:00.000Z",
      "last_edited_time": "2022-05-27T14:00:00.000Z",
      "created_by": {
        "object": "user",
        "id": "11fb7f16-0560-4aee-ab88-ed75a850cfc4"
      },
      "last_edited_by": {
        "object": "user",
        "id": "11fb7f16-0560-4aee-ab88-ed75a850cfc4"
      },
      "has_children": false,
      "archived": false,
      "type": "link_to_page",
      "link_to_page": {                      <-------------------
        "type": "page_id",
        "page_id": "5d4f91d1-80cd-4a36-a284-905905c92001"
      }
    }
}
``
hatton commented 2 years ago

Submitted PR #32

souvikinator commented 2 years ago

hey there @hatton Thanks for the snippet, I used the same snippet and got following results:

image

so not sure what's the issue over here and the same goes for the changes in PR #32 Is the PR working for you?

hatton commented 2 years ago

Is the PR working for you?

Yes, of course. It seems like at this point maybe you could file a bug report with Notion to try and figure out what is going on with your account. For me, everything is working according to the Notion API documentation.

souvikinator commented 2 years ago

Yes, I did that already and waiting for their response on slack. Once it is resolved I'll merge and create a release.

souvikinator commented 2 years ago

@hatton Seems like no one is responding but if the PR works for you I'll merge it and create a new release.