Markdown - 为什么不推荐在 Markdown 文档中插入原始 html 元素?

Markdown - why inserting raw html element in markdown document is not recommended?

我以前用 markdown 写 posts。

当我在降价文档中插入 html 元素时,markdownlint 告诉我该文档违反了降价规则“MD033 - 内联 html”。

规则“MD033 - 内联 html”在降价文档中使用原始 HTML 时触发。

但是,我不知道为什么 markdown 文档中不允许内联 html 元素。

我在google里找过,没找到

如果读过这篇post的人知道这一点,请告诉我。

永远谢谢。

Linters 鼓励最佳实践,并且通常比语法规则 and/or parser/compiler 更严格。 Wikipedia 声明“linter 是一种静态代码分析工具,用于标记编程错误、漏洞、文体错误和可疑结构。”

虽然编程错误会导致事情崩溃,但文体错误可能只能通过查看文档来识别。因此,组织通常会定义 style guide 他们要求项目的所有贡献者都遵循的规则。

A style guide or manual of style is a set of standards for the writing, formatting and design of documents. ... A style guide establishes standard style requirements to improve communication by ensuring consistency both within a document, and across multiple documents. Because practices vary, a style guide may set out standards to be used in areas such as punctuation, capitalization, citing sources, formatting of numbers and dates, table appearance and other areas. The style guide may require certain best practices in usage, language composition, visual composition, orthography and typography.

显然,linter 非常适合标记任何不符合组织风格指南的内容。

也就是说,有些人可能只使用 linter 来标记编程错误和错误,而不关心“风格错误”,这不会改变输出的行为。例如,Markdown linter 可能需要在 header 和它后面的段落之间有一个空行,而 Markdown 并不严格要求在该位置有一个空行。如果您没有需要空行的样式指南,那么您可能不希望 linter 强制执行该空行。

因此,linter 是可定制的。您可以将 linter 配置为仅 运行 与您的风格指南匹配的规则子集。一些规则甚至可能接受不同的配置选项,这些选项会改变他们认为可接受的内容。

一般来说,linter 将默认使用大多数用户常用的配置。但是,每个组织都可能需要进行一些小的调整。因此,您可能需要配置您正在使用的 linter 以满足您的要求。

那么,为什么样式指南(以及扩展的 linter)可能不允许内联原始 HTML?这很难说。您需要询问编写这些风格指南的人。不过,我们可以做出一些猜测。

可能是样式指南还要求对文档的文本只进行非常基本的内联样式设置。也许任何允许的事情都可以使用 Markdown 语法完全实现。在这种情况下,不允许内联原始 HTML 的 linter 规则是执行样式指南要求的一种简单有效的方法。

另一个考虑因素是 Markdown 本身背后的哲学。作为 Markdown 的创造者 explains:

Markdown is intended to be as easy-to-read and easy-to-write as is feasible.

Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.

原始 HTML 标签有损于该目标,因此许多人认为它们在他们的 Markdown 文档中是不受欢迎的。我怀疑这就是 linter 默认为这种行为的原因,但您需要询问 linter 的开发人员才能确定。

当然,如果这不能满足您的需要,或者您不太关心可读性,那么您可以随意在文档中包含任意数量的原始 HTML 标签。但是,您随后还需要自定义配置您使用的任何 linter,以便它忽略规则“MD033”。