-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: Add image captions support #586
base: master
Are you sure you want to change the base?
feat: Add image captions support #586
Conversation
@@ -92,6 +92,52 @@ type Opts = SVGOpts & ImageOpts; | |||
const index: MarkdownItPluginCb<Opts> = (md, opts) => { | |||
md.assets = []; | |||
|
|||
md.inline.ruler.after('image', 'image_caption', (state, silent) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is yet another attribute parser.
Can we use already implemented instead of this?
There was attached markdown-it-attrs plugin.
So at this time (when we process something after image) image token should already contain target parsed attribute.
Or we can attach parser in next way:
md.core.ruler.after('curly_attributes', 'image_caption', imageCaption);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg, that's what I needed, it could save 2 days if I knew about it. Updated the implementation using markdown-it-attrs plugin
|
||
while (j < childrenTokens.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace default token image
with image_with_caption
can be wery destructive for external plugins, which searches for image
token only.
I propose to implement this in other way:
- Check what image token has
caption
attr. - Then generate new token
image_caption
after this one. - Add renderer for
image_caption
which will generate all required a11y compatible html. - Convert
caption
attr on image to some class attrimage.attrSet('class', image.attrGet('class') + ' yfm-image-with-caption')
- Add some styles to main css.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I got rid of image_with_caption
token
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @osulyanov, for your contribution. The PR description was great, making it easy to understand all the changes. I've added some comments to help reduce the impact of the change. Check out this comment, where I discuss the issue of backward compatibility. |
Don't use separate image_capture tag that potentially can break other image-related plugings
@3y3 Thanks for the fast review and valuable and well-described comments. I made the changes to align with them, please have a look if it works. |
This looks like approvable PR. I will merge it at the end of week. I'm also not sure what this four lines are required, but I need to test it later |
Add support for image captions using
figcaption
tagDescription
Added support for image captions using HTML's semantic
figure
andfigcaption
tags.This enhances image context and improves document accessibility by providing visual relationships between images and their captions.
Features
![Alt text](image.jpg "Caption text" =100x100){ caption }
![Alt text](image.jpg "Title" =100x100){ caption="Custom caption text" }
<figure>
and<figcaption>
tagsExample
Input:
Output:
Documentation
Corresponding documentation PR: diplodoc-platform/docs#80
Technical Changes
Testing
Closes DOCSTOOLS-3428
Related issue: #514