splitbee / react-notion

A fast React renderer for Notion pages
https://react-notion.com
MIT License
2.86k stars 151 forks source link

Fix page link and render line break #40

Closed tdloi closed 2 years ago

tdloi commented 3 years ago

Notion Page: https://www.notion.so/tdloi/Page-1-8ac0c155447d44d699fd8e8007d3ca69 Preview: https://csb-x51vy.netlify.app/ CodeSandbox source: https://codesandbox.io/s/laughing-frog-x51vy?file=/src/App.js (preview will not work because fail to install directly from Github repo, but deploy to Netlify work)

tanishqkancharla commented 3 years ago

I was worried my links would lead outside the block map I looked at, so I did this instead:

const PageTitle: React.FC<{ id: string }> = ({ id }) => {
  const [title, setTitle] = React.useState<null | string>(null)
  getPage(id).then((blockmap) => {
    setTitle(blockmap[id].value.properties?.title)
  })
  if (title) {
    return <a href={`/${id}`}>{title}</a>
  } else {
    return <a style={{ fontSize: '85%' }}>Loading...</a>
  }
}
janniks commented 3 years ago

I'll chime in, regarding the missing line-breaks: In vue-notion, we solved this via CSS white-space: pre-line (which collapses similarly to normal/default, but preserves line-breaks). I think it's a more simple fix than adding an \n parsing functionality with the complexity of adding more fragments.

src/style.css

.notion-callout-text {
  margin-left: 8px;
+  white-space: pre-line;
}

This comment is only regarding the line-break issue, NOT the page link issue

tdloi commented 2 years ago

Sorry for late reply, I will close this PR as t's been a long time and I don't have time working on this Actually I didn't blog much :smile: