Skip to content

Creating captions for images? #4633

Answered by cmdcolin
cmdcolin asked this question in Q&A
Apr 16, 2021 · 5 comments · 11 replies
Discussion options

You must be logged in to vote

Went ahead and did some MDX :)

I created figures.jsx

/* eslint-disable react/prop-types,import/no-unresolved */
import React from 'react'
import useBaseUrl from '@docusaurus/useBaseUrl'

export default function Figure({ src, caption }) {
  return (
    <figure style={{ border: '1px solid #888', padding: 20 }}>
      <img src={useBaseUrl(src)} alt={caption} />
      <figcaption>{`Figure: ${caption}`}</figcaption>
    </figure>
  )
}

Then in my markdown/mdx files I use

import Figure from './figure'
<Figure caption="Caption for my picture" src="/img/mypicture.png" />

Replies: 5 comments 11 replies

Comment options

You must be logged in to vote
4 replies
@MyBaBB
Comment options

@slorber
Comment options

@Sugamgoel28
Comment options

@slorber
Comment options

Answer selected by slorber
Comment options

You must be logged in to vote
2 replies
@cmdcolin
Comment options

@slorber
Comment options

Comment options

You must be logged in to vote
4 replies
@cmdcolin
Comment options

@zeluspudding
Comment options

@cmdcolin
Comment options

@zeluspudding
Comment options

Comment options

You must be logged in to vote
1 reply
@xendarboh
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
9 participants