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

Caption for images #63

Open
zirkelc opened this issue Apr 4, 2023 · 6 comments
Open

Caption for images #63

zirkelc opened this issue Apr 4, 2023 · 6 comments

Comments

@zirkelc
Copy link
Contributor

zirkelc commented Apr 4, 2023

It's quite easy to implement caption for images:

n2m.setCustomTransformer('image', async (block) => {
  const { image } = block as ImageBlockObjectResponse;
  const src = image.type === 'external' ? image.external.url : image.file.url;
  const caption = image.caption ? image.caption[0]?.plain_text : '';

  return `
  <figure>
    <img src="${src}" alt=${caption} />
    <figcaption>${caption}</figcaption>
  </figure>`;
});

I was wondering why that's not the default behaviour?

@that-ambuj
Copy link
Contributor

that-ambuj commented May 15, 2023

I assume the reason why it is not the default behaviour might because of:

  • This behaviour returns html instead of markdown and might be confusing to someone expecting just plain markdown.
  • Image captions are handled differently by different markdown parsers and this type of behaviour can be implemented in Hugo and Zola with custom markups and shortcodes.

I might be wrong here and above are just my assumptions. Of couse, we should take @souvikinator's opinion on this.

@zirkelc
Copy link
Contributor Author

zirkelc commented May 17, 2023

Yes, I wasn't aware that markdown doesn't support captions natively. Maybe this could be implemented as GitHub flavored markdown mode that can be turned on optionally.

@that-ambuj
Copy link
Contributor

This sounds like a major feature addition and I think @souvikinator should decide on this one.

@souvikinator
Copy link
Owner

@that-ambuj made valid points. Including HTML tags in content can be tricky due to rendering variations in different markdown parsers.

I believe it's time to work on feature allowing people to choose the markdown flavour they want the output in (as @zirkelc mentioned)

It's going to take some time but definitely will be a huge game changer.

Would love to know your thoughts on this.

@souvikinator
Copy link
Owner

Btw just came across this, it's worth checking out:

| ![space-1.jpg](http://www.storywarren.com/wp-content/uploads/2016/09/space-1.jpg) | 
|:--:| 
| *caption here* |

and here is the result

space-1.jpg
caption here

thoughts on this?

@souvikinator
Copy link
Owner

Also

![image](https://picsum.photos/200)
*image_caption*

produces same output as

 <figure>
    <img src="https://picsum.photos/200" alt="image_caption" />
    <figcaption>image_caption</figcaption>
  </figure>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

3 participants