diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index b5385ce6..540741f4 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -331,7 +331,11 @@ export class _Tokenizer { raw = cap[0]; src = src.substring(raw.length); - let line = expandTabs(cap[2].split('\n', 1)[0], cap[1].length); + const firstLine = cap[2].split('\n', 1)[0]; + const bulletIndent = cap[1].length; + let line = this.options.pedantic + ? expandTabs(firstLine, bulletIndent) + : firstLine.replace(this.rules.other.leadingSpaceTab, whitespace => expandTabs(whitespace, bulletIndent)); let nextLine = src.split('\n', 1)[0]; let blankLine = !line.trim(); @@ -340,12 +344,12 @@ export class _Tokenizer { indent = 2; itemContents = line.trimStart(); } else if (blankLine) { - indent = cap[1].length + 1; + indent = bulletIndent + 1; } else { 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; + indent += bulletIndent; } if (blankLine && this.rules.other.blankLine.test(nextLine)) { // Items begin with at most one blank line @@ -373,7 +377,7 @@ export class _Tokenizer { nextLine = nextLine.replace(this.rules.other.listReplaceNesting, ' '); nextLineWithoutTabs = nextLine; } else { - nextLineWithoutTabs = nextLine.replace(this.rules.other.tabCharGlobal, ' '); + nextLineWithoutTabs = nextLine.replace(this.rules.other.leadingSpaceTab, whitespace => whitespace.replace(this.rules.other.tabCharGlobal, ' ')); } // End list item if found code fences diff --git a/src/rules.ts b/src/rules.ts index 8b850add..66bcec39 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -52,6 +52,7 @@ export const other = { nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, + leadingSpaceTab: /^[ \t]+/, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, diff --git a/test/specs/new/list_content_tabs_continuation_code_span_commonmark.html b/test/specs/new/list_content_tabs_continuation_code_span_commonmark.html new file mode 100644 index 00000000..b41a4f57 --- /dev/null +++ b/test/specs/new/list_content_tabs_continuation_code_span_commonmark.html @@ -0,0 +1,5 @@ +
    +
  • item

    +

    foo bar

    +
  • +
diff --git a/test/specs/new/list_content_tabs_continuation_code_span_commonmark.md b/test/specs/new/list_content_tabs_continuation_code_span_commonmark.md new file mode 100644 index 00000000..77b7a3b1 --- /dev/null +++ b/test/specs/new/list_content_tabs_continuation_code_span_commonmark.md @@ -0,0 +1,7 @@ +--- +gfm: false +renderExact: true +--- +- item + + `foo bar` diff --git a/test/specs/new/list_content_tabs_continuation_code_span_gfm.html b/test/specs/new/list_content_tabs_continuation_code_span_gfm.html new file mode 100644 index 00000000..b41a4f57 --- /dev/null +++ b/test/specs/new/list_content_tabs_continuation_code_span_gfm.html @@ -0,0 +1,5 @@ +
    +
  • item

    +

    foo bar

    +
  • +
diff --git a/test/specs/new/list_content_tabs_continuation_code_span_gfm.md b/test/specs/new/list_content_tabs_continuation_code_span_gfm.md new file mode 100644 index 00000000..5d5e6d7a --- /dev/null +++ b/test/specs/new/list_content_tabs_continuation_code_span_gfm.md @@ -0,0 +1,7 @@ +--- +gfm: true +renderExact: true +--- +- item + + `foo bar` diff --git a/test/specs/new/list_content_tabs_fence_commonmark.html b/test/specs/new/list_content_tabs_fence_commonmark.html new file mode 100644 index 00000000..50976d2f --- /dev/null +++ b/test/specs/new/list_content_tabs_fence_commonmark.html @@ -0,0 +1,5 @@ +
    +
  • foo	bar
    +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_fence_commonmark.md b/test/specs/new/list_content_tabs_fence_commonmark.md new file mode 100644 index 00000000..35f83bc0 --- /dev/null +++ b/test/specs/new/list_content_tabs_fence_commonmark.md @@ -0,0 +1,7 @@ +--- +gfm: false +renderExact: true +--- +- ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_fence_gfm.html b/test/specs/new/list_content_tabs_fence_gfm.html new file mode 100644 index 00000000..50976d2f --- /dev/null +++ b/test/specs/new/list_content_tabs_fence_gfm.html @@ -0,0 +1,5 @@ +
    +
  • foo	bar
    +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_fence_gfm.md b/test/specs/new/list_content_tabs_fence_gfm.md new file mode 100644 index 00000000..bd9550fc --- /dev/null +++ b/test/specs/new/list_content_tabs_fence_gfm.md @@ -0,0 +1,7 @@ +--- +gfm: true +renderExact: true +--- +- ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_first_line_code_span_commonmark.html b/test/specs/new/list_content_tabs_first_line_code_span_commonmark.html new file mode 100644 index 00000000..e3f83e94 --- /dev/null +++ b/test/specs/new/list_content_tabs_first_line_code_span_commonmark.html @@ -0,0 +1,3 @@ +
    +
  • foo bar
  • +
diff --git a/test/specs/new/list_content_tabs_first_line_code_span_commonmark.md b/test/specs/new/list_content_tabs_first_line_code_span_commonmark.md new file mode 100644 index 00000000..4835e46b --- /dev/null +++ b/test/specs/new/list_content_tabs_first_line_code_span_commonmark.md @@ -0,0 +1,5 @@ +--- +gfm: false +renderExact: true +--- +- `foo bar` diff --git a/test/specs/new/list_content_tabs_first_line_code_span_gfm.html b/test/specs/new/list_content_tabs_first_line_code_span_gfm.html new file mode 100644 index 00000000..e3f83e94 --- /dev/null +++ b/test/specs/new/list_content_tabs_first_line_code_span_gfm.html @@ -0,0 +1,3 @@ +
    +
  • foo bar
  • +
diff --git a/test/specs/new/list_content_tabs_first_line_code_span_gfm.md b/test/specs/new/list_content_tabs_first_line_code_span_gfm.md new file mode 100644 index 00000000..f0644f7c --- /dev/null +++ b/test/specs/new/list_content_tabs_first_line_code_span_gfm.md @@ -0,0 +1,5 @@ +--- +gfm: true +renderExact: true +--- +- `foo bar` diff --git a/test/specs/new/list_content_tabs_nested_fence_commonmark.html b/test/specs/new/list_content_tabs_nested_fence_commonmark.html new file mode 100644 index 00000000..4430fb46 --- /dev/null +++ b/test/specs/new/list_content_tabs_nested_fence_commonmark.html @@ -0,0 +1,8 @@ +
    +
  • outer
      +
    • foo	bar
      +
      +
    • +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_nested_fence_commonmark.md b/test/specs/new/list_content_tabs_nested_fence_commonmark.md new file mode 100644 index 00000000..5ed74938 --- /dev/null +++ b/test/specs/new/list_content_tabs_nested_fence_commonmark.md @@ -0,0 +1,8 @@ +--- +gfm: false +renderExact: true +--- +- outer + - ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_nested_fence_gfm.html b/test/specs/new/list_content_tabs_nested_fence_gfm.html new file mode 100644 index 00000000..4430fb46 --- /dev/null +++ b/test/specs/new/list_content_tabs_nested_fence_gfm.html @@ -0,0 +1,8 @@ +
    +
  • outer
      +
    • foo	bar
      +
      +
    • +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_nested_fence_gfm.md b/test/specs/new/list_content_tabs_nested_fence_gfm.md new file mode 100644 index 00000000..3e1e6207 --- /dev/null +++ b/test/specs/new/list_content_tabs_nested_fence_gfm.md @@ -0,0 +1,8 @@ +--- +gfm: true +renderExact: true +--- +- outer + - ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_ordered_fence_commonmark.html b/test/specs/new/list_content_tabs_ordered_fence_commonmark.html new file mode 100644 index 00000000..345694ac --- /dev/null +++ b/test/specs/new/list_content_tabs_ordered_fence_commonmark.html @@ -0,0 +1,5 @@ +
    +
  1. foo	bar
    +
    +
  2. +
diff --git a/test/specs/new/list_content_tabs_ordered_fence_commonmark.md b/test/specs/new/list_content_tabs_ordered_fence_commonmark.md new file mode 100644 index 00000000..d2e7526d --- /dev/null +++ b/test/specs/new/list_content_tabs_ordered_fence_commonmark.md @@ -0,0 +1,7 @@ +--- +gfm: false +renderExact: true +--- +1. ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_ordered_fence_gfm.html b/test/specs/new/list_content_tabs_ordered_fence_gfm.html new file mode 100644 index 00000000..345694ac --- /dev/null +++ b/test/specs/new/list_content_tabs_ordered_fence_gfm.html @@ -0,0 +1,5 @@ +
    +
  1. foo	bar
    +
    +
  2. +
diff --git a/test/specs/new/list_content_tabs_ordered_fence_gfm.md b/test/specs/new/list_content_tabs_ordered_fence_gfm.md new file mode 100644 index 00000000..7795e36c --- /dev/null +++ b/test/specs/new/list_content_tabs_ordered_fence_gfm.md @@ -0,0 +1,7 @@ +--- +gfm: true +renderExact: true +--- +1. ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_repeated_tabs_commonmark.html b/test/specs/new/list_content_tabs_repeated_tabs_commonmark.html new file mode 100644 index 00000000..ce0ded94 --- /dev/null +++ b/test/specs/new/list_content_tabs_repeated_tabs_commonmark.html @@ -0,0 +1,5 @@ +
    +
  • foo		bar
    +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_repeated_tabs_commonmark.md b/test/specs/new/list_content_tabs_repeated_tabs_commonmark.md new file mode 100644 index 00000000..4c8ed664 --- /dev/null +++ b/test/specs/new/list_content_tabs_repeated_tabs_commonmark.md @@ -0,0 +1,7 @@ +--- +gfm: false +renderExact: true +--- +- ~~~ + foo bar + ~~~ diff --git a/test/specs/new/list_content_tabs_repeated_tabs_gfm.html b/test/specs/new/list_content_tabs_repeated_tabs_gfm.html new file mode 100644 index 00000000..ce0ded94 --- /dev/null +++ b/test/specs/new/list_content_tabs_repeated_tabs_gfm.html @@ -0,0 +1,5 @@ +
    +
  • foo		bar
    +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_repeated_tabs_gfm.md b/test/specs/new/list_content_tabs_repeated_tabs_gfm.md new file mode 100644 index 00000000..b542a894 --- /dev/null +++ b/test/specs/new/list_content_tabs_repeated_tabs_gfm.md @@ -0,0 +1,7 @@ +--- +gfm: true +renderExact: true +--- +- ~~~ + foo bar + ~~~ diff --git a/test/specs/new/list_content_tabs_structural_indentation_tab_commonmark.html b/test/specs/new/list_content_tabs_structural_indentation_tab_commonmark.html new file mode 100644 index 00000000..b66cbf45 --- /dev/null +++ b/test/specs/new/list_content_tabs_structural_indentation_tab_commonmark.html @@ -0,0 +1,5 @@ +
    +
  •   foo	bar
    +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_structural_indentation_tab_commonmark.md b/test/specs/new/list_content_tabs_structural_indentation_tab_commonmark.md new file mode 100644 index 00000000..3484b997 --- /dev/null +++ b/test/specs/new/list_content_tabs_structural_indentation_tab_commonmark.md @@ -0,0 +1,7 @@ +--- +gfm: false +renderExact: true +--- +- ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_structural_indentation_tab_gfm.html b/test/specs/new/list_content_tabs_structural_indentation_tab_gfm.html new file mode 100644 index 00000000..b66cbf45 --- /dev/null +++ b/test/specs/new/list_content_tabs_structural_indentation_tab_gfm.html @@ -0,0 +1,5 @@ +
    +
  •   foo	bar
    +
    +
  • +
diff --git a/test/specs/new/list_content_tabs_structural_indentation_tab_gfm.md b/test/specs/new/list_content_tabs_structural_indentation_tab_gfm.md new file mode 100644 index 00000000..6c57d41a --- /dev/null +++ b/test/specs/new/list_content_tabs_structural_indentation_tab_gfm.md @@ -0,0 +1,7 @@ +--- +gfm: true +renderExact: true +--- +- ``` + foo bar + ``` diff --git a/test/specs/new/list_content_tabs_tab_separated_marker_commonmark.html b/test/specs/new/list_content_tabs_tab_separated_marker_commonmark.html new file mode 100644 index 00000000..e3f83e94 --- /dev/null +++ b/test/specs/new/list_content_tabs_tab_separated_marker_commonmark.html @@ -0,0 +1,3 @@ +
    +
  • foo bar
  • +
diff --git a/test/specs/new/list_content_tabs_tab_separated_marker_commonmark.md b/test/specs/new/list_content_tabs_tab_separated_marker_commonmark.md new file mode 100644 index 00000000..a3965769 --- /dev/null +++ b/test/specs/new/list_content_tabs_tab_separated_marker_commonmark.md @@ -0,0 +1,5 @@ +--- +gfm: false +renderExact: true +--- +- `foo bar` diff --git a/test/specs/new/list_content_tabs_tab_separated_marker_gfm.html b/test/specs/new/list_content_tabs_tab_separated_marker_gfm.html new file mode 100644 index 00000000..e3f83e94 --- /dev/null +++ b/test/specs/new/list_content_tabs_tab_separated_marker_gfm.html @@ -0,0 +1,3 @@ +
    +
  • foo bar
  • +
diff --git a/test/specs/new/list_content_tabs_tab_separated_marker_gfm.md b/test/specs/new/list_content_tabs_tab_separated_marker_gfm.md new file mode 100644 index 00000000..4ff48075 --- /dev/null +++ b/test/specs/new/list_content_tabs_tab_separated_marker_gfm.md @@ -0,0 +1,5 @@ +--- +gfm: true +renderExact: true +--- +- `foo bar`