Browse Source

Partially fix tabs inside code blocks

pull/293/head
Alex Kocharin 8 years ago
parent
commit
e5696e5b36
  1. 8
      lib/rules_block/state_block.js
  2. 52
      test/fixtures/commonmark/bad.txt
  3. 31
      test/fixtures/commonmark/good.txt

8
lib/rules_block/state_block.js

@ -194,7 +194,13 @@ StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF
first++; first++;
} }
queue[i] = this.src.slice(first, last); if (lineIndent > indent) {
// partially expanding tabs in code blocks, e.g '\t\tfoobar'
// with indent=2 becomes ' \tfoobar'
queue[i] = new Array(lineIndent - indent + 1).join(' ') + this.src.slice(first, last);
} else {
queue[i] = this.src.slice(first, last);
}
} }
return queue.join(''); return queue.join('');

52
test/fixtures/commonmark/bad.txt

@ -1,31 +1,3 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 387
.
- foo
bar
.
<ul>
<li>
<p>foo</p>
<pre><code> bar
</code></pre>
</li>
</ul>
.
error:
<ul>
<li>
<p>foo</p>
<pre><code>bar
</code></pre>
</li>
</ul>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 410 src line: 410
@ -46,30 +18,6 @@ error:
</blockquote> </blockquote>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 419
.
- foo
.
<ul>
<li>
<pre><code> foo
</code></pre>
</li>
</ul>
.
error:
<ul>
<li>
<pre><code>foo
</code></pre>
</li>
</ul>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 458 src line: 458

31
test/fixtures/commonmark/good.txt

@ -46,6 +46,37 @@ src line: 374
</ul> </ul>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 387
.
- foo
bar
.
<ul>
<li>
<p>foo</p>
<pre><code> bar
</code></pre>
</li>
</ul>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 419
.
- foo
.
<ul>
<li>
<pre><code> foo
</code></pre>
</li>
</ul>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 431 src line: 431

Loading…
Cancel
Save