问题
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:
- This library converts the raw markup to HTML. See the list of supported markup formats below.
- The HTML is sanitized, aggressively removing things that could harm you and your kin—such as
script
tags, inline-styles, andclass
orid
attributes. See the sanitization filter for the full whitelist.- Syntax highlighting is performed on code blocks. See github/linguist for more information about syntax highlighting.
- 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.
- 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