Specify image size in GitHub markdown using ems (or other unit)

百般思念 提交于 2020-01-30 11:33:04

问题


I've seen that it's possible to specify the image size using pixels, but pixels isn't a great way to specify image size. I've tried

<img src="myimg.png" style="width:20em" />

but that didn't work (although Markdown Viewer for Chrome rendered it)

Is it even possible to specify the size with another size unit other than pixels?


回答1:


No, you need to define width and/or height attributes to define an image's size, and those attributes only support pixel units. GitHub does no support using the style attribute.

As documented in the github/markup project:

This library is the first step of a journey that every markup file in a repository goes on before it is rendered on GitHub.com:

  1. This library converts the raw markup to HTML. See the list of supported markup formats below.
  2. The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes. See the sanitization filter for the full whitelist.
  3. Syntax highlighting is performed on code blocks. See github/linguist for more information about syntax highlighting.
  4. The HTML is passed through other filters in the html-pipeline that add special sauce, such as emoji, task lists, named anchors, CDN caching for images, and autolinking.
  5. The resulting HTML is rendered on GitHub.com.

Of note is step 2. Specifically style tags are stripped from any user provided content on GitHub's website. However, a review of the sanitation filter indicates that height and width attributes are whitelisted and not stripped. Note that width and height attributes can only use pixels as units. Therefore, you cannot us any other type of units to define an image size. Your img tag may look like this:

<img src="myimg.png" width="20" />

Of course, you'll need to adjust the actual size to your desired value.



来源:https://stackoverflow.com/questions/51453901/specify-image-size-in-github-markdown-using-ems-or-other-unit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!