英文:
How to have blockquotes inside of a paragraph in Markdown?
问题
我在想是否有办法在段落中间插入一个引用块?
有点像这样:
这是句子的开头,说一些东西—
> 这是一个引用块
—然后是那个句子继续,有一个短划线,然后结束。
但它总是被渲染成这样:
这是句子的开头,说一些东西—
> 这是一个引用块
> —但那句子的第二部分不幸地被放在引用块里!
不幸的是,我不希望换行的行为也不起作用:
这是另一句话:
> 这是另一个引用块,它结束了这个段落。
另一方面,这是一个新段落。
是否有任何语法可以让我将句子的第二部分视为换行符,从而退出引用块,而不仅仅是引用块内的换行符?
如果没有的话,我也使用Obsidian,所以如果有人能指点我一个能做到这一点的插件,那就太好了。
英文:
I was wondering if there was any way of having a blockquote in the middle of a paragraph?
Sort of like this:
This is the beginning of a sentence, saying things—
> this is a blockquote
—this is then that sentence continued with a dash, then ended.
But it would always get rendered like this:
This is the beginning of a sentence, saying things—
> this is a blockquote
> —but the second part of that sentence unfortunately gets put inside the blockquote!
Unfortunately I don’t want the behaviour that putting in a new line does neither:
This is another sentence:
> this is another blockquote, which ends this paragraph.
This on the other hand is a new paragraph.
Is there any syntax that would allow me to have the second part of the sentence treated as a linebreak – which exits the blockquote – and not just as a linebreak in the blockquote?
If there isn’t, I also use Obsidian, so if someone could point me towards a plugin to do this that would be great too.
答案1
得分: 1
这是不可能的。作为提醒,Markdown 是 HTML 的一个子集,并以 HTML 渲染。实际上,查看 HTML 规范 显示,不允许在段落元素内部包含块引用。事实上,规范明确指出块引用的起始标记会自动关闭其前面的段落。
> 如果 p
元素的结束标记可以省略,如果 p
元素紧随其后是 blockquote
元素...
因此,如果 Markdown 按照您的要求解析源文本,它将呈现以下(无效的)HTML:
<p>This is the beginning of a sentence, saying things—
<blockquote> this is a blockquote</blockquote>
—this is then that sentence continued with a dash, then ended.</p>
然而,浏览器/WebView 会解析和解释为以下HTML(或多或少):
<p>This is the beginning of a sentence, saying things—</p>
<blockquote> this is a blockquote</blockquote>
—this is then that sentence continued with a dash, then ended.<p></p>
请注意,在第一行的末尾插入了关闭的 </p>
标记。这是规范要求的行为,如上所引用的。因此,Markdown 不允许此行为,并始终假定块引用结束前面的段落。
有趣的是,规范在一个注释中对这种行为进行了评论(引用列表而不是块引用,但逻辑是相同的)。我引用了以下注释(没有示例)。
> 列表元素(特别是 ol
和 ul
元素)不能是 p
元素的子元素。因此,当一个句子包含一个项目符号列表时,人们可能会想知道应该如何标记它。
> 解决方案是认识到,从HTML角度看,段落不是逻辑概念,而是结构概念。在上面的奇妙示例中,根据这个规范的定义,实际上有五个段落:列表之前的一个,每个项目符号之前都有一个,以及列表之后一个。
> 希望方便地为这样的“逻辑”段落(由多个“结构”段落组成)设置样式的作者可以使用 div
元素而不是 p
元素。
虽然在HTML中使用 div
当然可以工作,但Markdown 中并没有专门支持它。尽管如此,可以在Markdown中使用原始HTML。但是,这不会改变元素在浏览器/WebView中的呈现方式,也无法解决此处提出的问题。除非还包括一些自定义CSS。也许 Obsidian 有一种定义自定义CSS 的机制/插件?
1: https://html.spec.whatwg.org/#the-p-element
英文:
This is not possible. As a reminder, Markdown is a subset of HTML and is rendered as HTML. In fact, a look at the HTML spec shows that a blockquote is not allowed inside a paragraph element. In fact, the spec specifically states that the opening tag of a blockquote will automatically close the paragraph preceding it.
> A p
element's end tag can be omitted if the p
element is immediately followed by an... blockquote
... element...
Therefore, if Markdown would parse you source text as you desire, it would render the following (invalid) HTML:
<p>This is the beginning of a sentence, saying things—
<blockquote> this is a blockquote</blockquote>
—this is then that sentence continued with a dash, then ended.</p>
However, a browser/webview would parse and interpret that as this HTML (more or less):
<p>This is the beginning of a sentence, saying things—</p>
<blockquote> this is a blockquote</blockquote>
—this is then that sentence continued with a dash, then ended.<p></p>
Notice that the closing </p>
tag was inserted at the end of the first line. This is required behavior by the spec, as quoted above. Therefore, Markdown does not allow this behavior and always assumes that a blockquote ends the preceding paragraph.
Interestingly, the spec comments on this behavior in a Note (referencing lists not blockquotes, but the logic is the same). I have quoted the note below (without the examples).
> List elements (in particular, ol
and ul
elements) cannot be children
> of p
elements. When a sentence contains a bulleted list, therefore,
> one might wonder how it should be marked up.
>
> The solution is to realize that a paragraph, in HTML terms, is not a
> logical concept, but a structural one. In the fantastic example above,
> there are actually five paragraphs as defined by this specification:
> one before the list, one for each bullet, and one after the list.
>
> Authors wishing to conveniently style such "logical" paragraphs
> consisting of multiple "structural" paragraphs can use the div
element
> instead of the p
element.
While using a div
certainly works for HTML, there is not specific support for it in Markdown. Although, one could use raw HTML in their Markdown. But, that is not going to alter how the elements are rendered in a browser/webview and doesn't resolve the issue raised here. That is unless some custom CSS was also included. Maybe Obsidian have a mechanism/plugin for defining custom CSS?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论