1
0
mirror of https://github.com/danog/blackfriday.git synced 2024-11-26 20:14:43 +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:
Vytautas Šaltenis 2015-10-29 20:06:27 +02:00
parent 607f2ceb8a
commit 15eb452ae4
2 changed files with 82 additions and 0 deletions

View File

@ -909,7 +909,17 @@ func (p *parser) quote(out *bytes.Buffer, data []byte) int {
beg, end := 0, 0
for beg < len(data) {
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' {
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++

View File

@ -1065,6 +1065,78 @@ func TestFencedCodeBlock(t *testing.T) {
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) {
var tests = []string{
"a | b\n---|---\nc | d\n",