使用 ems(或其他单位)在 GitHub markdown 中指定图像大小
Specify image size in GitHub markdown using ems (or other unit)
我发现可以 specify the image size using pixels,但像素并不是指定图像大小的好方法。我试过了
<img src="myimg.png" style="width:20em" />
但这没有用(尽管 Markdown Viewer for Chrome 渲染了它)
是否可以使用像素以外的其他尺寸单位来指定尺寸?
不,您需要定义 width
and/or height
属性来定义图像的大小,并且这些属性仅支持像素单位。 GitHub 不支持使用 style
属性。
如 github/markup 项目中所述:
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, and class
or
id
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.
值得注意的是第 2 步。具体来说,style
标签会从 GitHub 网站上任何用户提供的内容中删除。但是,对卫生过滤器的审查表明 height and width 属性已列入白名单且未被删除。注意 width
和 height
属性只能以像素为单位。因此,您不能使用任何其他类型的单位来定义图像大小。您的 img
标签可能如下所示:
<img src="myimg.png" width="20" />
当然,您需要将实际尺寸调整到您想要的值。
我发现可以 specify the image size using pixels,但像素并不是指定图像大小的好方法。我试过了
<img src="myimg.png" style="width:20em" />
但这没有用(尽管 Markdown Viewer for Chrome 渲染了它)
是否可以使用像素以外的其他尺寸单位来指定尺寸?
不,您需要定义 width
and/or height
属性来定义图像的大小,并且这些属性仅支持像素单位。 GitHub 不支持使用 style
属性。
如 github/markup 项目中所述:
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.
值得注意的是第 2 步。具体来说,style
标签会从 GitHub 网站上任何用户提供的内容中删除。但是,对卫生过滤器的审查表明 height and width 属性已列入白名单且未被删除。注意 width
和 height
属性只能以像素为单位。因此,您不能使用任何其他类型的单位来定义图像大小。您的 img
标签可能如下所示:
<img src="myimg.png" width="20" />
当然,您需要将实际尺寸调整到您想要的值。