Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
raw = cap[0];
src = src.substring(raw.length);

let line = cap[2].split('\n', 1)[0].replace(this.rules.other.listReplaceTabs, (t: string) => ' '.repeat(3 * t.length));
// Normalize the first line by replacing tabs with 4 spaces so we can
// compute indent and slice the correct number of characters. This keeps
// behavior consistent with how subsequent lines are normalized.
const rawLineFirst = cap[2].split('\n', 1)[0];
let line = rawLineFirst.replace(this.rules.other.tabCharGlobal, ' ');
let nextLine = src.split('\n', 1)[0];
let blankLine = !line.trim();

Expand All @@ -278,7 +282,9 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
} else if (blankLine) {
indent = cap[1].length + 1;
} else {
indent = cap[2].search(this.rules.other.nonSpaceChar); // Find first non-space char
// Treat tabs as 4 spaces when finding first non-space char so a leading tab
// isn't considered a non-space and we compute indent correctly.
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;
Expand Down
Binary file added test/specs/new/list_with_tabs.html
Binary file not shown.
13 changes: 13 additions & 0 deletions test/specs/new/list_with_tabs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1. Some Text
2. Some Text
3. Some Text

Paragraph before list

1. Some Text
2. Some Text
3. Some Text

- Some Text
- Some Text
- Some Text
12 changes: 12 additions & 0 deletions test/unit/marked.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import { timeout } from './utils.js';
import assert from 'node:assert';
import { describe, it, beforeEach, mock } from 'node:test';
import fs from 'fs';
import path from 'path';

Check failure on line 6 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

'path' is defined but never used

Check failure on line 6 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

'path' is defined but never used
import { fileURLToPath } from 'node:url';

Check failure on line 7 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

'fileURLToPath' is defined but never used

Check failure on line 7 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

'fileURLToPath' is defined but never used

describe('marked unit', () => {
let marked;
Expand Down Expand Up @@ -56,6 +59,15 @@
});
});

describe('lists with tabs', () => {
it('should correctly render markdown from the list_with_tabs fixture', () => {

Check failure on line 63 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

Expected indentation of 4 spaces but found 2
const markdown = fs.readFileSync(mdPath, 'utf8');

Check failure on line 64 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

'mdPath' is not defined

Check failure on line 64 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

Expected indentation of 6 spaces but found 4
const html = marked.parse(markdown);

Check failure on line 65 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

Expected indentation of 6 spaces but found 4
assert.ok(html.includes('<ol>') && html.includes('<ul>'), 'Expected list HTML not found');

Check failure on line 66 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

Expected indentation of 6 spaces but found 4
});

Check failure on line 67 in test/unit/marked.test.js

View workflow job for this annotation

GitHub Actions / OtherTests

Expected indentation of 4 spaces but found 2
});


describe('parseInline', () => {
it('should parse inline tokens', () => {
const md = '**strong** _em_';
Expand Down
Loading