From e692634f709245b6bbe0c8eeb0d41c168577316d Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 23 Dec 2022 09:39:10 -0600 Subject: [PATCH] fix: fix tabs at beginning of list items (#2679) * fix: fix tabs at beginning of list items * test: add test for ordered list --- src/Tokenizer.js | 4 ++-- test/specs/new/list_item_tabs.html | 17 +++++++++++++++++ test/specs/new/list_item_tabs.md | 13 +++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/specs/new/list_item_tabs.html create mode 100644 test/specs/new/list_item_tabs.md diff --git a/src/Tokenizer.js b/src/Tokenizer.js index 6889d7b145..9e2866f2b2 100644 --- a/src/Tokenizer.js +++ b/src/Tokenizer.js @@ -203,7 +203,7 @@ export class Tokenizer { raw = cap[0]; src = src.substring(raw.length); - line = cap[2].split('\n', 1)[0]; + line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length)); nextLine = src.split('\n', 1)[0]; if (this.options.pedantic) { @@ -225,7 +225,7 @@ export class Tokenizer { } if (!endEarly) { - const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`); + const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`); const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`); const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`); const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`); diff --git a/test/specs/new/list_item_tabs.html b/test/specs/new/list_item_tabs.html new file mode 100644 index 0000000000..e1b33013ea --- /dev/null +++ b/test/specs/new/list_item_tabs.html @@ -0,0 +1,17 @@ + + +
    +
  1. A
  2. +
  3. B
  4. +
  5. C
  6. +
  7. D
  8. +
  9. E
  10. +
  11. F
  12. +
diff --git a/test/specs/new/list_item_tabs.md b/test/specs/new/list_item_tabs.md new file mode 100644 index 0000000000..b42c88b8cc --- /dev/null +++ b/test/specs/new/list_item_tabs.md @@ -0,0 +1,13 @@ +- A +- B +- C +- D +- E +- F + +1. A +2. B +3. C +4. D +5. E +6. F