我正在使用 Pug 模板编写 HTML 文章,并且在将标签插入纯文本时遇到了超长行的问题。例如:
blockquote(cite='https://lwn.net/Articles/806776/').
It is an ABI break for the operating system,
but that is no big deal for OpenBSD.
De Raadt #[a(href='https://lwn.net/Articles/806869/') said]:
#[q(cite='https://lwn.net/Articles/806869/') we here at OpenBSD are the kings of ABI-instability].
He #[a(href='https://lwn.net/Articles/806870/') suggested] that
relying on the OpenBSD ABI is fraught with peril:
#[blockquote(cite='https://lwn.net/Articles/806870/') Program to the API rather than the ABI. When we see benefits, we change the ABI more often than the API. I have altered the ABI. Pray I do not alter it further.]
请注意极长的行,尤其是末尾的最后一个块引用元素。即使在我最大的显示器上,它也很难阅读并且溢出。在真实的源文件中,这个问题甚至更严重,因为它有几个深层次的识别级别。
如何分解?
我尝试了以下方法:
#[blockquote(cite='https://lwn.net/Articles/806870/').
Program to the API rather than the ABI.
When we see benefits,
we change the ABI more often than the API.
I have altered the ABI.
Pray I do not alter it further.]
但是,这给了我以下错误:
已到达行尾,没有用于插值的右括号。
这表明 pug 根本不支持在标签插值期间解析多行。
有没有办法做到这一点,或者我应该在 GitHub 上提出有关它的问题吗?
为此,请使用 管道文本语法 而不是标签语法中的块。
blockquote(cite='https://lwn.net/Articles/806776/')
| It is an ABI break for the operating system,
| but that is no big deal for OpenBSD.
| De Raadt #[a(href='https://lwn.net/Articles/806869/') said]:
q(cite='https://lwn.net/Articles/806869/') we here at OpenBSD are the kings of ABI-instability].
| He #[a(href='https://lwn.net/Articles/806870/') suggested] that
| relying on the OpenBSD ABI is fraught with peril:
blockquote(cite='https://lwn.net/Articles/806870/') Program to the API rather than the ABI. When we see benefits, we change the ABI more often than the API. I have altered the ABI. Pray I do not alter it further.
请注意,这并不是真正的最佳实践,因为您必须在每行末尾添加一个尾随空格,以便在编译时保留单词之间的空格。大多数代码编辑器都有一个“软换行”选项,可以根据窗口宽度动态换行代码(无需实际插入任何换行符)。