gpt4 book ai didi

Markdown 和换行

转载 作者:行者123 更新时间:2023-12-04 12:05:08 30 4
gpt4 key购买 nike

大多数情况下,Markdown 文件被视为源代码:它们位于 VCS 中,参与拉取请求和/或审查,并且格式良好。就像在源代码中一样,我经常看到以特定长度插入的换行符——就像代码格式化程序那样。

许多编辑器根据当前窗口大小(也称为自动换行)动态地执行此操作。此外,Markdown 主要用于生成 HTML 页面、PDF 文档或其他格式。在这些情况下,手动插入的换行符通常会导致文本渲染困惑。

在特定的行长处包装 Markdown 是好是坏?话题好像是controversial ,即使是当前的 CommonMark 规范( v0.29 )也有点犹豫不决:

A regular line break (not in a code span or HTML tag) that is not preceded by two or more spaces or a backslash is parsed as a softbreak. (A softbreak may be rendered in HTML either as a line ending or as a space. The result will be the same in browsers. In the examples here, a line ending will be used.)

[…]

A conforming parser may render a soft line break in HTML either as a line break or as a space.

A renderer may also provide an option to render soft line breaks as hard line breaks.



然而, John Gruber said回到 2004 年:

The implication of the “one or more consecutive lines of text” rule is that Markdown supports “hard-wrapped” text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type’s “Convert Line Breaks” option) which translate every line break character in a paragraph into a <br /> tag.

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Yes, this takes a tad more effort to create a <br />, but a simplistic “every line break is a <br />” rule wouldn’t work for Markdown. Markdown’s email-style blockquoting and multi-paragraph list items work best — and look better — when you format them with hard breaks.

最佳答案

大多数 Markdown 渲染器会忽略单个换行符,因此将文本围绕一些商定的长度包装不会影响渲染结果。
然而,它可能会使代码更容易维护。
所以它不是一种反模式,一些项目甚至在他们的编码标准中要求它。来自 libstoragemgmt-doc 的示例:

" Set text width as 72.
autocmd Filetype markdown set tw=72

关于Markdown 和换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41513565/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com