我刚开始接触Markdown。我喜欢它,但有一件事困扰着我:如何使用Markdown更改图像的大小?

文档仅为图像提供以下建议:

![drawing](drawing.jpg)

如果可能的话,我希望图片也居中。我问的是Markdown将军,而不仅仅是GitHub是如何做到的。


当前回答

这一条对我有用,它不在一条线上,但我希望它对你有用。

<div>
<img src="attachment:image.png" width="500" height="300"/>
</div>

其他回答

如果您正在使用kramdown,可以执行以下操作:

{:.foo}
![drawing](drawing.jpg)

然后将其添加到自定义CSS中:

.foo {
  text-align: center;
  width: 100px;
}

通过纯向后兼容MD:

![<alt>](<imguri>#<w>x<h> "<title>")

其中w,h定义了要纵横适配的边界框,例如在Flutter包中https://pub.dev/packages/flutter_markdown

代码:https://github.com/flutter/packages/blob/9e8f5227ac14026c419f481ed1dfcb7b53961475/packages/flutter_markdown/lib/src/builder.dart#L473

重新考虑破坏兼容性的html解决方案,因为人们可能会使用本机/非html组件/应用程序来显示标记。

也许这一点最近有所改变,但Kramdown文档显示了一个简单的解决方案。

从文档中

Here is an inline ![smiley](smiley.png){:height="36px" width="36px"}.

And here is a referenced ![smile]

[smile]: smile.png
{: height="36px" width="36px"}

与Jekyll和Kramdown一起在github上工作。

当使用Flask时(我将其用于平面页面)。。。我发现,在markdown调用中的扩展中显式地启用(由于某种原因,默认情况下不是这样)“attr_list”可以实现这一点,然后可以使用属性(对于访问CSS也非常有用-例如,class=“my class”…)。

FLATPAGES_HML_RENDERER=prerender_jinja

以及功能:

def prerender_jinja(text):
    prerendered_body = render_template_string(Markup(text))
    pygmented_body   = markdown.markdown(prerendered_body, extensions=['codehilite', 'fenced_code', 'tables', 'attr_list'])
    return pygmented_body

然后在Markdown中:

![image](https://octodex.github.com/images/yaktocat.png "This is a tooltip"){: width=200px}

有添加类和css样式的方法

!〔pic〕〔logo〕{.classname}

然后在下面写下链接和css

[logo]: (picurl)

<style type="text/css">
    .classname{
        width: 200px;
    }
</style>

此处引用