MediaWiki  1.34.0
TextExtracts\TextTruncator Class Reference

This class needs to understand HTML as well as plain text. More...

Collaboration diagram for TextExtracts\TextTruncator:

Public Member Functions

 __construct (TidyDriverBase $tidy=null)
 
 getFirstChars ( $text, $requestedLength)
 Returns no more than a requested number of characters, preserving words. More...
 
 getFirstSentences ( $text, $requestedSentenceCount)
 Returns no more than the given number of sentences. More...
 

Private Member Functions

 tidy ( $text)
 

Private Attributes

TidyDriverBase null $tidyDriver
 

Detailed Description

This class needs to understand HTML as well as plain text.

It tries to not break HTML tags, but might break pairs of tags, leaving unclosed tags behind. A Tidy instance must be provided to fix this.

Note
GPL-2.0-or-later

Definition at line 14 of file TextTruncator.php.

Constructor & Destructor Documentation

◆ __construct()

TextExtracts\TextTruncator::__construct ( TidyDriverBase  $tidy = null)
Parameters
TidyDriverBase | null$tidy

Definition at line 24 of file TextTruncator.php.

Member Function Documentation

◆ getFirstChars()

TextExtracts\TextTruncator::getFirstChars (   $text,
  $requestedLength 
)

Returns no more than a requested number of characters, preserving words.

Parameters
string$textSource text to extract from
int$requestedLengthMaximum number of characters to return
Returns
string

Definition at line 79 of file TextTruncator.php.

◆ getFirstSentences()

TextExtracts\TextTruncator::getFirstSentences (   $text,
  $requestedSentenceCount 
)

Returns no more than the given number of sentences.

Parameters
string$textSource text to extract from
int$requestedSentenceCountMaximum number of sentences to extract
Returns
string

Definition at line 35 of file TextTruncator.php.

References $lines, $matches, and $res.

◆ tidy()

TextExtracts\TextTruncator::tidy (   $text)
private
Parameters
string$text
Returns
string

Definition at line 101 of file TextTruncator.php.

Member Data Documentation

◆ $tidyDriver

TidyDriverBase null TextExtracts\TextTruncator::$tidyDriver
private

Definition at line 19 of file TextTruncator.php.


The documentation for this class was generated from the following file: