mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-28 10:11:45 +00:00
Merge "Add stripTrailingSeparator to getBodyText as well as getBodyHTML"
This commit is contained in:
commit
768e400fe5
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace MediaWiki\Extension\DiscussionTools;
|
namespace MediaWiki\Extension\DiscussionTools;
|
||||||
|
|
||||||
|
use DOMDocumentFragment;
|
||||||
use DOMText;
|
use DOMText;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use MWException;
|
use MWException;
|
||||||
|
@ -46,12 +47,11 @@ class CommentItem extends ThreadItem {
|
||||||
/**
|
/**
|
||||||
* Get the HTML of this comment's body
|
* Get the HTML of this comment's body
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param bool $stripTrailingSeparator Strip a trailing separator between the body and
|
* @param bool $stripTrailingSeparator Strip a trailing separator between the body and
|
||||||
* the signature which consists of whitespace and hyphens e.g. ' --'
|
* the signature which consists of whitespace and hyphens e.g. ' --'
|
||||||
* @return string HTML
|
* @return DOMDocumentFragment Cloned fragment of the body content
|
||||||
*/
|
*/
|
||||||
public function getBodyHTML( bool $stripTrailingSeparator = false ) : string {
|
private function getBodyFragment( bool $stripTrailingSeparator = false ) : DOMDocumentFragment {
|
||||||
$fragment = $this->getBodyRange()->cloneContents();
|
$fragment = $this->getBodyRange()->cloneContents();
|
||||||
CommentModifier::unwrapFragment( $fragment );
|
CommentModifier::unwrapFragment( $fragment );
|
||||||
|
|
||||||
|
@ -72,6 +72,18 @@ class CommentItem extends ThreadItem {
|
||||||
substr( $lastChild->nodeValue, 0, -strlen( $matches[0] ) );
|
substr( $lastChild->nodeValue, 0, -strlen( $matches[0] ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the HTML of this comment's body
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param bool $stripTrailingSeparator See getBodyFragment
|
||||||
|
* @return string HTML
|
||||||
|
*/
|
||||||
|
public function getBodyHTML( bool $stripTrailingSeparator = false ) : string {
|
||||||
|
$fragment = $this->getBodyFragment( $stripTrailingSeparator );
|
||||||
$container = $fragment->ownerDocument->createElement( 'div' );
|
$container = $fragment->ownerDocument->createElement( 'div' );
|
||||||
$container->appendChild( $fragment );
|
$container->appendChild( $fragment );
|
||||||
return DOMCompat::getInnerHTML( $container );
|
return DOMCompat::getInnerHTML( $container );
|
||||||
|
@ -80,10 +92,11 @@ class CommentItem extends ThreadItem {
|
||||||
/**
|
/**
|
||||||
* Get the text of this comment's body
|
* Get the text of this comment's body
|
||||||
*
|
*
|
||||||
|
* @param bool $stripTrailingSeparator See getBodyFragment
|
||||||
* @return string Text
|
* @return string Text
|
||||||
*/
|
*/
|
||||||
public function getBodyText() : string {
|
public function getBodyText( bool $stripTrailingSeparator = false ) : string {
|
||||||
$fragment = $this->getBodyRange()->cloneContents();
|
$fragment = $this->getBodyFragment( $stripTrailingSeparator );
|
||||||
return $fragment->textContent;
|
return $fragment->textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue