MDL-70295 libraries: upgrade to version 4.3.1 of Html2Text.

This commit is contained in:
Paul Holden
2020-11-25 21:42:05 +00:00
parent ae8e7f90ad
commit 3eab26586b
3 changed files with 50 additions and 22 deletions
+44 -17
View File
@@ -28,14 +28,14 @@ class Html2Text
/**
* Contains the HTML content to convert.
*
* @type string
* @var string $html
*/
protected $html;
/**
* Contains the converted, formatted text.
*
* @type string
* @var string $text
*/
protected $text;
@@ -43,7 +43,7 @@ class Html2Text
* List of preg* regular expression patterns to search for,
* used in conjunction with $replace.
*
* @type array
* @var array $search
* @see $replace
*/
protected $search = array(
@@ -54,6 +54,7 @@ class Html2Text
'/<style\b[^>]*>.*?<\/style>/i', // <style>s -- which strip_tags supposedly has problems with
'/<i\b[^>]*>(.*?)<\/i>/i', // <i>
'/<em\b[^>]*>(.*?)<\/em>/i', // <em>
'/<ins\b[^>]*>(.*?)<\/ins>/i', // <ins>
'/(<ul\b[^>]*>|<\/ul>)/i', // <ul> and </ul>
'/(<ol\b[^>]*>|<\/ol>)/i', // <ol> and </ol>
'/(<dl\b[^>]*>|<\/dl>)/i', // <dl> and </dl>
@@ -73,7 +74,7 @@ class Html2Text
/**
* List of pattern replacements corresponding to patterns searched.
*
* @type array
* @var array $replace
* @see $search
*/
protected $replace = array(
@@ -84,6 +85,7 @@ class Html2Text
'', // <style>s -- which strip_tags supposedly has problems with
'_\\1_', // <i>
'_\\1_', // <em>
'_\\1_', // <ins>
"\n\n", // <ul> and </ul>
"\n\n", // <ol> and </ol>
"\n\n", // <dl> and </dl>
@@ -104,7 +106,7 @@ class Html2Text
* List of preg* regular expression patterns to search for,
* used in conjunction with $entReplace.
*
* @type array
* @var array $entSearch
* @see $entReplace
*/
protected $entSearch = array(
@@ -118,7 +120,7 @@ class Html2Text
/**
* List of pattern replacements corresponding to patterns searched.
*
* @type array
* @var array $entReplace
* @see $entSearch
*/
protected $entReplace = array(
@@ -133,7 +135,7 @@ class Html2Text
* List of preg* regular expression patterns to search for
* and replace using callback function.
*
* @type array
* @var array $callbackSearch
*/
protected $callbackSearch = array(
'/<(h)[123456]( [^>]*)?>(.*?)<\/h[123456]>/i', // h1 - h6
@@ -141,6 +143,7 @@ class Html2Text
'/<(br)[^>]*>[ ]*/i', // <br> with leading whitespace after the newline.
'/<(b)( [^>]*)?>(.*?)<\/b>/i', // <b>
'/<(strong)( [^>]*)?>(.*?)<\/strong>/i', // <strong>
'/<(del)( [^>]*)?>(.*?)<\/del>/i', // <del>
'/<(th)( [^>]*)?>(.*?)<\/th>/i', // <th> and </th>
'/<(a) [^>]*href=("|\')([^"\']+)\2([^>]*)>(.*?)<\/a>/i' // <a href="">
);
@@ -149,7 +152,7 @@ class Html2Text
* List of preg* regular expression patterns to search for in PRE body,
* used in conjunction with $preReplace.
*
* @type array
* @var array $preSearch
* @see $preReplace
*/
protected $preSearch = array(
@@ -163,7 +166,7 @@ class Html2Text
/**
* List of pattern replacements corresponding to patterns searched for PRE body.
*
* @type array
* @var array $preReplace
* @see $preSearch
*/
protected $preReplace = array(
@@ -177,21 +180,21 @@ class Html2Text
/**
* Temporary workspace used during PRE processing.
*
* @type string
* @var string $preContent
*/
protected $preContent = '';
/**
* Contains the base URL that relative links should resolve to.
*
* @type string
* @var string $baseurl
*/
protected $baseurl = '';
/**
* Indicates whether content in the $html variable has been converted yet.
*
* @type boolean
* @var boolean $converted
* @see $html, $text
*/
protected $converted = false;
@@ -199,7 +202,7 @@ class Html2Text
/**
* Contains URL addresses from links to be rendered in plain text.
*
* @type array
* @var array $linkList
* @see buildlinkList()
*/
protected $linkList = array();
@@ -207,7 +210,7 @@ class Html2Text
/**
* Various configuration options (able to be set in the constructor)
*
* @type array
* @var array $options
*/
protected $options = array(
'do_links' => 'inline', // 'none'
@@ -281,7 +284,7 @@ class Html2Text
/**
* Returns the text, converted from HTML.
*
* @return string
* @return string Plain text
*/
public function getText()
{
@@ -414,7 +417,7 @@ class Html2Text
}
// Ignored link types
if (preg_match('!^(javascript:|mailto:|#)!i', $link)) {
if (preg_match('!^(javascript:|mailto:|#)!i', html_entity_decode($link))) {
return $display;
}
@@ -450,6 +453,11 @@ class Html2Text
}
}
/**
* Helper function for PRE body conversion.
*
* @param string &$text HTML content
*/
protected function convertPre(&$text)
{
// get the content of PRE element
@@ -486,7 +494,7 @@ class Html2Text
/**
* Helper function for BLOCKQUOTE body conversion.
*
* @param string $text HTML content
* @param string &$text HTML content
*/
protected function convertBlockquotes(&$text)
{
@@ -563,6 +571,8 @@ class Html2Text
case 'b':
case 'strong':
return $this->toupper($matches[3]);
case 'del':
return $this->tostrike($matches[3]);
case 'th':
return $this->toupper("\t\t" . $matches[3] . "\n");
case 'h':
@@ -628,4 +638,21 @@ class Html2Text
return $str;
}
/**
* Helper function for DEL conversion.
*
* @param string $text HTML content
* @return string Converted text
*/
protected function tostrike($str)
{
$rtn = '';
for ($i = 0; $i < mb_strlen($str); $i++) {
$chr = mb_substr($str, $i, 1);
$combiningChr = chr(0xC0 | 0x336 >> 6). chr(0x80 | 0x336 & 0x3F);
$rtn .= $chr . $combiningChr;
}
return $rtn;
}
}