Skip to content
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

Question: example "notion-to-md" repositories? #84

Open
hecker opened this issue May 14, 2023 · 6 comments
Open

Question: example "notion-to-md" repositories? #84

hecker opened this issue May 14, 2023 · 6 comments
Labels
question Further information is requested

Comments

@hecker
Copy link

hecker commented May 14, 2023

Hello, I currently have a problem because I don't know how to put blocks like "video" into nice html. Even after following your wiki you provided. Here is my current code: https://github.com/hecker/hecker.vc/blob/main/lib/notion.ts

My question is: do you know if there are any repositories that are open-source and already use notion-to-md so I can check how it works and get some inspiration?

@that-ambuj
Copy link
Contributor

Have you tried using the n2m.setCustomTransformer("video", cb-function) method to handle videos as the way you want? You can checkout the example for custom transformers to achieve the required results.

@souvikinator
Copy link
Owner

Like @that-ambuj mentioned you can use the setCustomTransformer method to render the element the way you want. Here is a simple example:

n2m.setCustomTransformer("video", async (block) => {
  const { video } = block as any;
  const { type } = video;
  const video_url = video[type].url;
  return `
    <video src="${video_url}" controls>
      Your browser does not support the video tag.
    </video>
  `;
});

do you know if there are any repositories that are open-source and already use notion-to-md so I can check how it works and get some inspiration?

As far as your question is concerned I would suggest checking out the used by section on the right sidebar of the repo or here is the link

@souvikinator souvikinator added the question Further information is requested label May 20, 2023
@hecker
Copy link
Author

hecker commented May 21, 2023

Thanks your the help! Now this is what I get... I am pretty new to web dev so I am not sure how to program it that it recognizes

Screenshot 2023-05-21 at 17 08 22

@souvikinator
Copy link
Owner

souvikinator commented May 21, 2023

So it's a minor fix. In the code sample, I have provided, there is leading space in the string due to which it is rendered as a code block. Here is how you can fix it:

n2m.setCustomTransformer("video", async (block) => {
  const { video } = block as any;
  const { type } = video;
  const video_url = video[type].url;
  return `<video src="${video_url}" controls> Your browser does not support the video tag. </video>`;
});

or

n2m.setCustomTransformer("video", async (block) => {
  const { video } = block as any;
  const { type } = video;
  const video_url = video[type].url;
  return (`
      <video src="${video_url}" controls>
         your browser does not support the video tag.
     </video>
  `).trim();
});

@hecker
Copy link
Author

hecker commented May 21, 2023

Thanks! But it is still displayed as text (not code, but normal text). Maybe it's about how I implemented it?

Screenshot 2023-05-21 at 17 29 30

My implementation:

<section>
      <h1 className="font-bold text-3xl font-serif mb-5">
        {blogPost.metadata.title}
      </h1>
      <article className="prose dark:prose-invert prose-code">
        {blogPost.metadata.updated && (
          <Callout
            text={"Last updated in " + blogPost.metadata.updated + "."}
            emoji="🗓️"
          />
        )}
        <ReactMarkdown>{blogPost.content}</ReactMarkdown>
      </article>
    </section>

@souvikinator
Copy link
Owner

I believe react-markdown doesn't render HTML by default you need to use another package as a plugin.

Refer to this: https://stackoverflow.com/a/70548866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants