getValue(); // Remove leftover \n at the beginning of the line $markdown = \ltrim($markdown, "\n"); // Replace sequences of invisible characters with spaces, other than those which keep text on the same line $markdown = \preg_replace('~[^\S' . NoBreakSpaces::CHARACTERS . ']+~u', ' ', $markdown); \assert(\is_string($markdown)); // Escape the following characters: '*', '_', '[', ']', '|' and '\' $isEscaped = ($parent = $element->getParent()) && $parent->getTagName() !== 'div'; if ($isEscaped) { $markdown = \preg_replace('~([*_\\[\\]|\\\\])~u', '\\\\$1', $markdown); \assert(\is_string($markdown)); } $markdown = \preg_replace('~^#~u', '\\\\#', $markdown); \assert(\is_string($markdown)); if (\preg_match('~^\s++\z~u', $markdown) === 1) { $next = $element->getNext(); if (! $next || $next->isBlock() || \in_array($next->getTagName(), ['pre', 'table'], true)) { $markdown = ''; } } $markdown = \htmlspecialchars($markdown, ENT_NOQUOTES, 'UTF-8'); // A pipe could otherwise make a table out of its line, cutting through any code span on the line above if (! $isEscaped) { $markdown = \str_replace('|', '|', $markdown); } return Backticks::escapeText($markdown); } /** * @return string[] */ public function getSupportedTags(): array { return ['#text']; } }