Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
fix: non leading-tabs in markdown content (markedjs#1559)
Browse files Browse the repository at this point in the history
Only replaces tabs at the beginning of a block construct. Tabs in the
middle of the item are unaffected.

All tests passing. Tabs in both GFM and CommonMark at 100%

fixes markedjs#1559
  • Loading branch information
rossipedia committed Apr 8, 2022
1 parent 3dc35bb commit e160e57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ export class Lexer {
*/
lex(src) {
src = src
.replace(/\r\n|\r/g, '\n')
.replace(/\t/g, ' ');
.replace(/\r\n|\r/g, '\n');

this.blockTokens(src, this.tokens);

Expand All @@ -135,6 +134,15 @@ export class Lexer {
if (this.options.pedantic) {
src = src.replace(/^ +$/gm, '');
}

if (this.options.gfm || this.options.pedantic) {
src = src.replace(/\t/g, ' ');
} else {
src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
return leading + ' '.repeat(tabs.length);
});
}

let token, lastToken, cutSrc, lastParagraphClipped;

while (src) {
Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class Tokenizer {
}

// Get next list item
const itemRegex = new RegExp(`^( {0,3}${bull})((?: [^\\n]*)?(?:\\n|$))`);
const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);

// Check if current bullet point can start a new List Item
while (src) {
Expand Down
4 changes: 2 additions & 2 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const block = {
newline: /^(?: *(?:\n|$))+/,
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
html: '^ {0,3}(?:' // optional indentation
+ '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
+ '|comment[^\\n]*(\\n+|$)' // (2)
Expand Down

0 comments on commit e160e57

Please sign in to comment.