Don't expand tabs inside fenced code blocks.

Still do normalize newlines inside fenced code blocks.
pull/61/head
Dmitri Shuralyov 2014-04-12 14:45:25 -07:00
parent 8df342acd5
commit ad246ef7a5
2 changed files with 7 additions and 3 deletions

View File

@ -638,7 +638,7 @@ func TestPreformattedHtmlLax(t *testing.T) {
func TestFencedCodeBlock(t *testing.T) {
var tests = []string{
"``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",
"<pre><code class=\"go\">func foo() bool {\n return true;\n}\n</code></pre>\n",
"<pre><code class=\"go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",
"``` c\n/* special & char < > \" escaping */\n```\n",
"<pre><code class=\"c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",
@ -978,7 +978,7 @@ func TestOrderedList_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
var tests = []string{
"``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",
"<pre><code class=\"go\">func foo() bool {\n return true;\n}\n</code></pre>\n",
"<pre><code class=\"go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",
"``` c\n/* special & char < > \" escaping */\n```\n",
"<pre><code class=\"c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",

View File

@ -343,7 +343,11 @@ func firstPass(p *parser, input []byte) []byte {
// add the line body if present
if end > beg {
expandTabs(&out, input[beg:end], tabSize)
if end < lastFencedCodeBlockEnd { // Do not expand tabs while inside fenced code blocks.
out.Write(input[beg:end])
} else {
expandTabs(&out, input[beg:end], tabSize)
}
}
out.WriteByte('\n')