From f3145e85366d8f3322e09f856ea0a3370f7dde82 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino 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 more -->

foo

foo more -->

```````````````````````````````` + +#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 +. +

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

+````````````````````````````````