diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 5f7d878599..16834b86bf 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -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'); } diff --git a/test/specs/new/fence_indent_stripping.html b/test/specs/new/fence_indent_stripping.html new file mode 100644 index 0000000000..b3feaa5773 --- /dev/null +++ b/test/specs/new/fence_indent_stripping.html @@ -0,0 +1,7 @@ +
aaa
+ aaa
+aaa
+
+sep
+ aaa
+
diff --git a/test/specs/new/fence_indent_stripping.md b/test/specs/new/fence_indent_stripping.md
new file mode 100644
index 0000000000..ea8bba01e6
--- /dev/null
+++ b/test/specs/new/fence_indent_stripping.md
@@ -0,0 +1,14 @@
+---
+renderExact: true
+---
+ ```
+ aaa
+ aaa
+ aaa
+ ```
+
+sep
+
+ ```
+ aaa
+ ```