Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ function indentCodeCompensation(raw: string, text: string, rules: Rules) {

const [indentInNode] = matchIndentInNode;

if (indentInNode.length >= indentToCode.length) {
return node.slice(indentToCode.length);
}

return node;
// Up to the fence's own indentation is removed from each line, so a line
// indented less than the fence loses whatever indentation it has.
return node.slice(Math.min(indentInNode.length, indentToCode.length));
})
.join('\n');
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/marked.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ describe('marked unit', () => {
});
});

describe('fenced code block indentation', () => {
it('should remove up to the fence indentation from each line', () => {
const md = ' ```\n aaa\n aaa\n aaa\n ```\n';
assert.strictEqual(marked.parse(md), '<pre><code>aaa\n aaa\naaa\n</code></pre>\n');
});

it('should leave lines indented more than the fence with the remainder', () => {
const md = ' ```\n aaa\n ```\n';
assert.strictEqual(marked.parse(md), '<pre><code> aaa\n</code></pre>\n');
});
});

describe('changeDefaults', () => {
it('should change global defaults', async() => {
const { defaults, setOptions } = await import('../../lib/marked.esm.js');
Expand Down