Merge pull request #7483 from MrPetovan/task/7474-html-to-bbcode
Fix bug removing spaces between hashtag links in HTML::toPlaintext
This commit is contained in:
commit
dc85451b78
3 changed files with 18 additions and 4 deletions
|
@ -100,8 +100,9 @@ class HTML
|
||||||
|
|
||||||
if ($node->hasChildNodes()) {
|
if ($node->hasChildNodes()) {
|
||||||
/** @var \DOMNode $child */
|
/** @var \DOMNode $child */
|
||||||
foreach ($node->childNodes as $child) {
|
foreach ($node->childNodes as $key => $child) {
|
||||||
if (trim($child->nodeValue)) {
|
/* Remove empty text nodes at the start or at the end of the children list */
|
||||||
|
if ($key > 0 && $key < $node->childNodes->length - 1 || trim($child->nodeValue)) {
|
||||||
$newNode = $child->cloneNode(true);
|
$newNode = $child->cloneNode(true);
|
||||||
$node->parentNode->insertBefore($newNode, $node);
|
$node->parentNode->insertBefore($newNode, $node);
|
||||||
}
|
}
|
||||||
|
@ -170,7 +171,7 @@ class HTML
|
||||||
|
|
||||||
$message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8");
|
$message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8");
|
||||||
|
|
||||||
@$doc->loadHTML($message);
|
@$doc->loadHTML($message, LIBXML_HTML_NODEFDTD);
|
||||||
|
|
||||||
XML::deleteNode($doc, 'style');
|
XML::deleteNode($doc, 'style');
|
||||||
XML::deleteNode($doc, 'head');
|
XML::deleteNode($doc, 'head');
|
||||||
|
@ -190,7 +191,8 @@ class HTML
|
||||||
$message = $doc->saveHTML();
|
$message = $doc->saveHTML();
|
||||||
$message = str_replace(["\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"], ["<", ">", "<br />", " ", ""], $message);
|
$message = str_replace(["\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"], ["<", ">", "<br />", " ", ""], $message);
|
||||||
$message = preg_replace('= [\s]*=i', " ", $message);
|
$message = preg_replace('= [\s]*=i', " ", $message);
|
||||||
@$doc->loadHTML($message);
|
|
||||||
|
@$doc->loadHTML($message, LIBXML_HTML_NODEFDTD);
|
||||||
|
|
||||||
self::tagToBBCode($doc, 'html', [], "", "");
|
self::tagToBBCode($doc, 'html', [], "", "");
|
||||||
self::tagToBBCode($doc, 'body', [], "", "");
|
self::tagToBBCode($doc, 'body', [], "", "");
|
||||||
|
|
1
tests/datasets/content/text/html/bug-7474.html
Normal file
1
tests/datasets/content/text/html/bug-7474.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<p>I recently released a PHP package that makes executing commands over SSH super simple. You can also upload/download files via SCP.</p><p><a href="https://github.com/DivineOmega/php-ssh-connection" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/DivineOmega/php-ssh</span><span class="invisible">-connection</span></a></p><p><a href="https://mastodon.xyz/tags/php" class="mention hashtag" rel="tag">#<span>php</span></a> <a href="https://mastodon.xyz/tags/opensource" class="mention hashtag" rel="tag">#<span>opensource</span></a> <a href="https://mastodon.xyz/tags/webdev" class="mention hashtag" rel="tag">#<span>webdev</span></a> <a href="https://mastodon.xyz/tags/ssh" class="mention hashtag" rel="tag">#<span>ssh</span></a> <a href="https://mastodon.xyz/tags/devops" class="mention hashtag" rel="tag">#<span>DevOps</span></a></p>
|
11
tests/datasets/content/text/html/bug-7474.txt
Normal file
11
tests/datasets/content/text/html/bug-7474.txt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
I recently released a PHP package that makes executing commands over SSH super simple. You can also upload/download files via SCP.
|
||||||
|
|
||||||
|
https://github.com/DivineOmega/php-ssh-connection
|
||||||
|
|
||||||
|
#php #opensource #webdev #ssh #DevOps
|
||||||
|
|
||||||
|
https://mastodon.xyz/tags/php
|
||||||
|
https://mastodon.xyz/tags/opensource
|
||||||
|
https://mastodon.xyz/tags/webdev
|
||||||
|
https://mastodon.xyz/tags/ssh
|
||||||
|
https://mastodon.xyz/tags/devops
|
Loading…
Reference in a new issue