From f3145e85366d8f3322e09f856ea0a3370f7dde82 Mon Sep 17 00:00:00 2001
From: Tatsunori Uchino <tats.u@live.jp>
Date: Sun, 1 Sep 2024 14:46:59 +0900
Subject: [PATCH] Don't trim non-ASCII whitespace

---
 lib/inlines.js      |  6 +++++-
 test/regression.txt | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/lib/inlines.js b/lib/inlines.js
index 1ecf8eef..1f0cbb7c 100644
--- a/lib/inlines.js
+++ b/lib/inlines.js
@@ -980,7 +980,11 @@ var parseInline = function(block) {
 // Parse string content in block into inline children,
 // using refmap to resolve references.
 var parseInlines = function(block) {
-    this.subject = block._string_content.trim();
+    // trim() removes non-ASCII whitespaces, vertical tab, form feed and so on.
+    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim#return_value
+    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#white_space
+    // Removes only ASCII tab and space.
+    this.subject = block._string_content.replace(/^[\t \r\n]+|[\t \r\n]+$/g, "")
     this.pos = 0;
     this.delimiters = null;
     this.brackets = null;
diff --git a/test/regression.txt b/test/regression.txt
index 40630a7b..6de5a111 100644
--- a/test/regression.txt
+++ b/test/regression.txt
@@ -518,3 +518,31 @@ foo <!-- test --> more -->
 <p>foo <!-----></p>
 <p>foo <!-- test --> more --&gt;</p>
 ````````````````````````````````
+
+#261
+```````````````````````````````` example
+Vertical Tab
+
+Form Feed
+
+ NBSP (U+00A0) NBSP 
+
+ Em Space (U+2003) Em Space 
+
+
Line Separator (U+2028) Line Separator

+
+
Paragraph Separator (U+2029) Paragraph Separator

+
+ 全角スペース (U+3000) 全形空白 
+
+ZWNBSP (U+FEFF) ZWNBSP
+.
+<p>Vertical Tab</p>
+<p>Form Feed</p>
+<p> NBSP (U+00A0) NBSP </p>
+<p> Em Space (U+2003) Em Space </p>
+<p>
Line Separator (U+2028) Line Separator
</p>
+<p>
Paragraph Separator (U+2029) Paragraph Separator
</p>
+<p> 全角スペース (U+3000) 全形空白 </p>
+<p>ZWNBSP (U+FEFF) ZWNBSP</p>
+````````````````````````````````