Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
18 changes: 18 additions & 0 deletions test/unit/marked.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { Marked, Renderer, lexer, parseInline, getDefaults, walkTokens, defaults
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';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const mdPath = path.join(__dirname, '../specs/new/list_with_tabs.md');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed. the files in the new folder are already ran in other tests



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

describe('lists with tabs', () => {
it('should correctly render markdown from the list_with_tabs fixture', () => {
const markdown = fs.readFileSync(mdPath, 'utf8');
const html = marked.parse(markdown);
assert.ok(html.includes('<ol>') && html.includes('<ul>'), 'Expected list HTML not found');
});
});


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