arve0/markdown-it-implicit-figures

Get caption from title

john-cj opened this issue · 3 comments

Hi! Thanks for this plugin.

Can you please tell, how I should modify the code to get the caption from title?

Source:

![](image.png "Foo")

Desired result:

<figure>
    <img src="image.png" alt="">
    <figcaption>Foo</figcaption>
</figure>

Update

Well, I see @mshick is already mentioned about this feature:

I can imagine a config option / variant to instead stick the title text in there. If that's desirable maybe a new issue can be opened.

#5

But, I still don't know how it can be done.

arve0 commented

Hi! I'll accept PRs with such an option. Please read markdown-it documentation and this plugin source code to grasp how to implement it yourself: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md

Are you still open to PRs for this? I might be able to implement this. I think some tests for title might be helpful too.

I would recommend changing the figcaption config option to a string accepting "title" or "alt". The boolean values of true and false can continue to mean the same thing ("alt" and no caption respectively).

I thought about the option to make a breaking change by making the default value "title" but anyone using the title would see a change and there isn't much of a benefit. IMO using the title should be the default to encourage people to use alt text to describe the image content as opposed to captions for context. However I don't want to introduce a breaking change unnecessarily.

arve0 commented

Are you still open to PRs for this?

Yes👍

Breaking change sounds like the correct way and can be published by bumping the major version. People wanting the old behavior can stay at current version. Give it a go 🙂