mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-30 04:29:13 +01:00
Fix fenced code processing inside blockquotes
Add a call to fenced code block processor inside the loop that's responsible for collecting the quoted lines. Grok all the fenced code block as a part of the quoted text. Closes #122.
This commit is contained in:
parent
607f2ceb8a
commit
15eb452ae4
10
block.go
10
block.go
@ -909,7 +909,17 @@ func (p *parser) quote(out *bytes.Buffer, data []byte) int {
|
|||||||
beg, end := 0, 0
|
beg, end := 0, 0
|
||||||
for beg < len(data) {
|
for beg < len(data) {
|
||||||
end = beg
|
end = beg
|
||||||
|
// Step over whole lines, collecting them. While doing that, check for
|
||||||
|
// fenced code and if one's found, incorporate it altogether,
|
||||||
|
// irregardless of any contents inside it
|
||||||
for data[end] != '\n' {
|
for data[end] != '\n' {
|
||||||
|
if p.flags&EXTENSION_FENCED_CODE != 0 {
|
||||||
|
if i := p.fencedCode(out, data[end:], false); i > 0 {
|
||||||
|
// -1 to compensate for the extra end++ after the loop:
|
||||||
|
end += i - 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
end++
|
end++
|
||||||
}
|
}
|
||||||
end++
|
end++
|
||||||
|
@ -1065,6 +1065,78 @@ func TestFencedCodeBlock(t *testing.T) {
|
|||||||
doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
|
doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFencedCodeInsideBlockquotes(t *testing.T) {
|
||||||
|
var tests = []string{
|
||||||
|
"> ```go\n" +
|
||||||
|
"package moo\n\n" +
|
||||||
|
"```\n",
|
||||||
|
`<blockquote>
|
||||||
|
<pre><code class="language-go">package moo
|
||||||
|
|
||||||
|
</code></pre>
|
||||||
|
</blockquote>
|
||||||
|
`,
|
||||||
|
// -------------------------------------------
|
||||||
|
"> foo\n" +
|
||||||
|
"> \n" +
|
||||||
|
"> ```go\n" +
|
||||||
|
"package moo\n" +
|
||||||
|
"```\n" +
|
||||||
|
"> \n" +
|
||||||
|
"> goo.\n",
|
||||||
|
`<blockquote>
|
||||||
|
<p>foo</p>
|
||||||
|
|
||||||
|
<pre><code class="language-go">package moo
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>goo.</p>
|
||||||
|
</blockquote>
|
||||||
|
`,
|
||||||
|
// -------------------------------------------
|
||||||
|
"> foo\n" +
|
||||||
|
"> \n" +
|
||||||
|
"> quote\n" +
|
||||||
|
"continues\n" +
|
||||||
|
"```\n",
|
||||||
|
"<blockquote>\n" +
|
||||||
|
"<p>foo</p>\n\n" +
|
||||||
|
"<p>quote\n" +
|
||||||
|
"continues\n" +
|
||||||
|
"```</p>\n" +
|
||||||
|
"</blockquote>\n",
|
||||||
|
|
||||||
|
"> foo\n" +
|
||||||
|
"> \n" +
|
||||||
|
"> ```go\n" +
|
||||||
|
"package moo\n" +
|
||||||
|
"```\n" +
|
||||||
|
"> \n" +
|
||||||
|
"> goo.\n" +
|
||||||
|
"> \n" +
|
||||||
|
"> ```go\n" +
|
||||||
|
"package zoo\n" +
|
||||||
|
"```\n" +
|
||||||
|
"> \n" +
|
||||||
|
"> woo.\n",
|
||||||
|
`<blockquote>
|
||||||
|
<p>foo</p>
|
||||||
|
|
||||||
|
<pre><code class="language-go">package moo
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>goo.</p>
|
||||||
|
|
||||||
|
<pre><code class="language-go">package zoo
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>woo.</p>
|
||||||
|
</blockquote>
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTable(t *testing.T) {
|
func TestTable(t *testing.T) {
|
||||||
var tests = []string{
|
var tests = []string{
|
||||||
"a | b\n---|---\nc | d\n",
|
"a | b\n---|---\nc | d\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user