Using Markdown, how do I center an image and its caption?

前端 未结 7 876
小鲜肉
小鲜肉 2021-01-31 08:08

I want to end up with:

Hello there!

      
      This is an image

Hi!

Where the image and the text This is an image

7条回答
  •  耶瑟儿~
    2021-01-31 08:31

    I think I have a simple solution that will work given that you can define CSS. It also does not require any extensions or HTML! First your markdown image code:

    ![my image](/img/myImage.jpg#center)  
    

    Note the added url hash #center.

    Now add this rule in CSS:

    img[src*='#center'] { 
        display: block;
        margin: auto;
    }
    

    You should be able to use a url hash like this, almost like defining a class name.

    To see this in action, check out my JSFiddle using SnarkDown to parse MarkDown in a textarea - https://jsfiddle.net/tremor/6s30e8vr/

提交回复
热议问题