1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-23 00:51:12 +01:00

Do not handle weird edge cases
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Daniil Gentili 2022-10-31 21:30:50 +01:00
parent 95f9275a61
commit 996d3df4d0
3 changed files with 17 additions and 5 deletions

View File

@ -158,7 +158,7 @@ abstract class StrTools extends Extension
if ($markdown === '') { if ($markdown === '') {
return $markdown; return $markdown;
} }
$html = (new Parsedown($markdown))->text($markdown); $html = Parsedown::instance()->text($markdown);
$document = new DOMDocument('', 'utf-8'); $document = new DOMDocument('', 'utf-8');
@$document->loadHTML(\mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); @$document->loadHTML(\mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
if (!$document->getElementsByTagName('body')[0]) { if (!$document->getElementsByTagName('body')[0]) {

View File

@ -24,7 +24,7 @@ final class DOMEntities
{ {
$dom = new \DOMDocument(); $dom = new \DOMDocument();
$html = \preg_replace("/\<br(\s*)?\/?\>/i", "\n", $html); $html = \preg_replace("/\<br(\s*)?\/?\>/i", "\n", $html);
$dom->loadxml("<body>" . \str_replace(['&amp;', '&#039;', '&quot;', '&gt;', '&lt;', '&'], ['&', '\'', "\"", '>', '<', '&amp;'], \trim($html)) . "</body>"); $dom->loadxml("<body>" . \trim($html) . "</body>");
$this->parseNode($dom->getElementsByTagName('body')->item(0), 0); $this->parseNode($dom->getElementsByTagName('body')->item(0), 0);
} }
/** /**

View File

@ -153,12 +153,12 @@ class EntitiesTest extends MadelineTestCase
], ],
[ [
'html', 'html',
'<b>&\'"</b>', '<b>\'"</b>',
'&\'"', '\'"',
[ [
[ [
'offset' => 0, 'offset' => 0,
'length' => 3, 'length' => 2,
'type' => 'bold' 'type' => 'bold'
] ]
] ]
@ -182,6 +182,18 @@ class EntitiesTest extends MadelineTestCase
] ]
] ]
], ],
[
'markdown',
'_a b c &lt;b&gt; &amp; &quot; &#039;_',
'a b c <b> & " \'',
[
[
'offset' => 0,
'length' => 15,
'type' => 'italic',
],
]
],
[ [
'markdown', 'markdown',
'test *italic* **bold** <u>underlined</u> ~~strikethrough~~ <pre language="test">pre</pre> <code>code</code> <spoiler>spoiler</spoiler>', 'test *italic* **bold** <u>underlined</u> ~~strikethrough~~ <pre language="test">pre</pre> <code>code</code> <spoiler>spoiler</spoiler>',