mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: preserve internal tabs in list item content (#4086)
This commit is contained in:
+8
-4
@@ -331,7 +331,11 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
|
||||
raw = cap[0];
|
||||
src = src.substring(raw.length);
|
||||
|
||||
let line = expandTabs(cap[2].split('\n', 1)[0], cap[1].length);
|
||||
const firstLine = cap[2].split('\n', 1)[0];
|
||||
const bulletIndent = cap[1].length;
|
||||
let line = this.options.pedantic
|
||||
? expandTabs(firstLine, bulletIndent)
|
||||
: firstLine.replace(this.rules.other.leadingSpaceTab, whitespace => expandTabs(whitespace, bulletIndent));
|
||||
let nextLine = src.split('\n', 1)[0];
|
||||
let blankLine = !line.trim();
|
||||
|
||||
@@ -340,12 +344,12 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
|
||||
indent = 2;
|
||||
itemContents = line.trimStart();
|
||||
} else if (blankLine) {
|
||||
indent = cap[1].length + 1;
|
||||
indent = bulletIndent + 1;
|
||||
} else {
|
||||
indent = line.search(this.rules.other.nonSpaceChar); // Find first non-space char
|
||||
indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
|
||||
itemContents = line.slice(indent);
|
||||
indent += cap[1].length;
|
||||
indent += bulletIndent;
|
||||
}
|
||||
|
||||
if (blankLine && this.rules.other.blankLine.test(nextLine)) { // Items begin with at most one blank line
|
||||
@@ -373,7 +377,7 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
|
||||
nextLine = nextLine.replace(this.rules.other.listReplaceNesting, ' ');
|
||||
nextLineWithoutTabs = nextLine;
|
||||
} else {
|
||||
nextLineWithoutTabs = nextLine.replace(this.rules.other.tabCharGlobal, ' ');
|
||||
nextLineWithoutTabs = nextLine.replace(this.rules.other.leadingSpaceTab, whitespace => whitespace.replace(this.rules.other.tabCharGlobal, ' '));
|
||||
}
|
||||
|
||||
// End list item if found code fences
|
||||
|
||||
@@ -52,6 +52,7 @@ export const other = {
|
||||
nonSpaceChar: /[^ ]/,
|
||||
newLineCharGlobal: /\n/g,
|
||||
tabCharGlobal: /\t/g,
|
||||
leadingSpaceTab: /^[ \t]+/,
|
||||
multipleSpaceGlobal: /\s+/g,
|
||||
blankLine: /^[ \t]*$/,
|
||||
doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><p>item</p>
|
||||
<p><code>foo bar</code></p>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
- item
|
||||
|
||||
`foo bar`
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><p>item</p>
|
||||
<p><code>foo bar</code></p>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
- item
|
||||
|
||||
`foo bar`
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
- ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
- ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,3 @@
|
||||
<ul>
|
||||
<li><code>foo bar</code></li>
|
||||
</ul>
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
- `foo bar`
|
||||
@@ -0,0 +1,3 @@
|
||||
<ul>
|
||||
<li><code>foo bar</code></li>
|
||||
</ul>
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
- `foo bar`
|
||||
@@ -0,0 +1,8 @@
|
||||
<ul>
|
||||
<li>outer<ul>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
- outer
|
||||
- ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,8 @@
|
||||
<ul>
|
||||
<li>outer<ul>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
- outer
|
||||
- ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
<ol>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
1. ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
<ol>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
1. ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
- ~~~
|
||||
foo bar
|
||||
~~~
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><pre><code>foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
- ~~~
|
||||
foo bar
|
||||
~~~
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><pre><code> foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
- ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul>
|
||||
<li><pre><code> foo bar
|
||||
</code></pre>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
- ```
|
||||
foo bar
|
||||
```
|
||||
@@ -0,0 +1,3 @@
|
||||
<ul>
|
||||
<li><code>foo bar</code></li>
|
||||
</ul>
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
gfm: false
|
||||
renderExact: true
|
||||
---
|
||||
- `foo bar`
|
||||
@@ -0,0 +1,3 @@
|
||||
<ul>
|
||||
<li><code>foo bar</code></li>
|
||||
</ul>
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
gfm: true
|
||||
renderExact: true
|
||||
---
|
||||
- `foo bar`
|
||||
Reference in New Issue
Block a user