diff --git a/_test/json/unformatted.json b/_test/json/unformatted.json new file mode 100644 index 00000000..784461d7 --- /dev/null +++ b/_test/json/unformatted.json @@ -0,0 +1,14 @@ +{ + "type": "doc", + "content": [ + { + "type": "paragraph", + "content": [ + { + "type": "text", + "text": "__foo//bar%%" + } + ] + } + ] +} diff --git a/_test/json/unformatted.txt b/_test/json/unformatted.txt new file mode 100644 index 00000000..7bbe4d7b --- /dev/null +++ b/_test/json/unformatted.txt @@ -0,0 +1 @@ +%%__%%foo%%//%%bar%% diff --git a/parser/TextNode.php b/parser/TextNode.php index b8d61715..d36452c3 100644 --- a/parser/TextNode.php +++ b/parser/TextNode.php @@ -105,7 +105,25 @@ public function getPostfixSyntax() public function getInnerSyntax() { - return $this->text; + if ($this->marks['unformatted']) { + return $this->text; + } + return preg_replace_callback( + "/\bhttps?:\/\/|__+|\/\/+|%%+|''+|\*\*+/", + function ($matches) + { + switch ($matches[0][0]) { + case 'h': + // We matched http(s):// + return $matches[0]; + case '%': + return '' . $matches[0] . ''; + default: + return '%%' . $matches[0] . '%%'; + } + }, + $this->text + ); }