add caption for markdown images
This commit is contained in:
parent
2f67067e8f
commit
39e9c09015
2 changed files with 32 additions and 1 deletions
|
|
@ -56,9 +56,29 @@ const markdownLib = markdownIt({
|
|||
decoding: 'async',
|
||||
sizes: '90vw'
|
||||
},
|
||||
// prepend src for markdown images
|
||||
// prepend src for markdown images
|
||||
resolvePath: (filepath, env) => {
|
||||
return path.join('src', filepath);
|
||||
},
|
||||
renderImage(image, attributes) {
|
||||
const [Image, options] = image;
|
||||
const [src, attrs] = attributes;
|
||||
|
||||
Image(src, options);
|
||||
|
||||
const metadata = Image.statsSync(src, options);
|
||||
const imageMarkup = Image.generateHTML(metadata, attrs, {
|
||||
whitespaceMode: 'inline'
|
||||
});
|
||||
|
||||
const imageElement = attrs.title
|
||||
? `<figure class="flow">
|
||||
${imageMarkup}
|
||||
<figcaption>${attrs.title}</figcaption>
|
||||
</figure>`
|
||||
: `${imageMarkup}`;
|
||||
|
||||
return imageElement;
|
||||
}
|
||||
})
|
||||
.use(markdownItFootnote)
|
||||
|
|
|
|||
|
|
@ -67,9 +67,20 @@ The class names are passed in the outer container, the `<picture>` or `<figure>`
|
|||
|
||||
Thanks to the [markdown-it-eleventy-img](https://github.com/solution-loisir/markdown-it-eleventy-img) package markdown also has it own image syntax. `src` is already prepended here, see `config/plugins/markdown.js`.
|
||||
|
||||
### Picture element
|
||||
|
||||
```markdown
|
||||

|
||||

|
||||
```
|
||||
|
||||

|
||||
|
||||
### Figure element with caption
|
||||
|
||||
```markdown
|
||||

|
||||

|
||||
```
|
||||
|
||||

|
||||
|
|
|
|||
Loading…
Reference in a new issue