全角 Markdown 表格
Full-width Markdown tables
到目前为止,我已经在 Markdown tables 中格式化和居中文本,但我没有发现控制相对于外部容器的 table 尺寸(至少除了当它太大时它会通过换行自动缩小。)
是否可以在 Markdown 中创建一个延伸至可用全宽的 table?如果是这样,您是如何实现的?
为 table 定义一个 CSS 样式:
table {
width:100%;
}
作为 the Markdown rules 状态:
Markdown’s syntax is intended for one purpose: to be used as a format
for writing for the web.
Markdown is not a replacement for HTML, or even close to it. ... The
idea for Markdown is to make it easy to read, write, and edit prose.
HTML is a publishing format; Markdown is a writing format. Thus,
Markdown’s formatting syntax only addresses issues that can be
conveyed in plain text.
由于 Markdown 是一种“写作格式”,而不是一种发布格式,因此它不提供“样式化”文本的方法。当然,默认情况下,Markdown 会生成 HTML,因此要问的适当问题是如何在 HTML 中完成您想要的样式。答案是使用 CSS 将宽度设置为 100%
(参见 HTML table span entire width)。
下一个问题是如何让输出使用那个 CSS 定义。答案取决于 Markdown 的呈现方式和位置。如果您拥有完全控制权,那么您可能会在站点现有的 CSS 规则中包含 CSS 规则。至少,您可以将规则包含在文档的 <head>
中的 <style>
标记中。
如果您无法控制整个页面,那么您可以简单地在 Markdown 本身的某处包含一个样式标签。 Markdown 通过 HTML 未修改,因此不会破坏任何东西。像这样:
<style>
table {
width: 100%;
}
</style>
也可以选择在 HTML <table>
标签中内联定义样式,但这只有在您手动制作 HTML 时才有效。由于您希望 Markdown 为您生成 HTML,因此这不是一个有用的选项。
最后,如果您的 Markdown 是由第三方网站(如 Stack Overflow 或 GitHub)呈现的,该网站可能会采取各种安全措施,这将使所有这些选项都无法实现。例如,参见
与 一样,Markdown 关心内容,而不是表示。如果您可以控制内容的呈现位置和呈现方式,他的解决方案就会奏效。
但在某些情况下,例如在 GitHub,您没有此控件。作为其 Markdown 的一部分 rendering pipeline:
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.
在 GitHub 上,您将不得不忍受 GitHub 的渲染规则。
到目前为止,我已经在 Markdown tables 中格式化和居中文本,但我没有发现控制相对于外部容器的 table 尺寸(至少除了当它太大时它会通过换行自动缩小。)
是否可以在 Markdown 中创建一个延伸至可用全宽的 table?如果是这样,您是如何实现的?
为 table 定义一个 CSS 样式:
table {
width:100%;
}
作为 the Markdown rules 状态:
Markdown’s syntax is intended for one purpose: to be used as a format for writing for the web.
Markdown is not a replacement for HTML, or even close to it. ... The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.
由于 Markdown 是一种“写作格式”,而不是一种发布格式,因此它不提供“样式化”文本的方法。当然,默认情况下,Markdown 会生成 HTML,因此要问的适当问题是如何在 HTML 中完成您想要的样式。答案是使用 CSS 将宽度设置为 100%
(参见 HTML table span entire width)。
下一个问题是如何让输出使用那个 CSS 定义。答案取决于 Markdown 的呈现方式和位置。如果您拥有完全控制权,那么您可能会在站点现有的 CSS 规则中包含 CSS 规则。至少,您可以将规则包含在文档的 <head>
中的 <style>
标记中。
如果您无法控制整个页面,那么您可以简单地在 Markdown 本身的某处包含一个样式标签。 Markdown 通过 HTML 未修改,因此不会破坏任何东西。像这样:
<style>
table {
width: 100%;
}
</style>
也可以选择在 HTML <table>
标签中内联定义样式,但这只有在您手动制作 HTML 时才有效。由于您希望 Markdown 为您生成 HTML,因此这不是一个有用的选项。
最后,如果您的 Markdown 是由第三方网站(如 Stack Overflow 或 GitHub)呈现的,该网站可能会采取各种安全措施,这将使所有这些选项都无法实现。例如,参见
与
但在某些情况下,例如在 GitHub,您没有此控件。作为其 Markdown 的一部分 rendering pipeline:
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.
在 GitHub 上,您将不得不忍受 GitHub 的渲染规则。