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

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

![drawing](drawing.jpg)

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


当前回答

如果您正在为PanDoc编写MarkDown,可以执行以下操作:

![drawing](drawing.jpg){ width=50% }

这会将style=“width:50%;”添加到HTML<img>标记中,或将[width=0.5\textwidth]添加到LaTeX中的\includegraphics中。

资料来源:http://pandoc.org/MANUAL.html#extension-链接属性

其他回答

对于R-Markdown,以上两种解决方案都不适用于我,所以我转向了常规的LaTeX语法,这很好。

\begin{figure}
 \includegraphics[width=300pt, height = 125 pt]{drawing.jpg}
\end{figure}

然后,可以使用例如\ begin{center}语句将图像居中。

当使用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}

也许这一点最近有所改变,但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上工作。

这会奏效的

<style>
img{width: 50%;}
#foo {color: red;}
</style>

<p id="foo">foo</p>

<p style="color: blue">bar</p>

代替[title](imageurl.type)与<img src=“https://image-url.type“width=”200“height=”200“/>