MDL-82828 core: Update Html2Text to version 4.3.2
This commit is contained in:
@@ -102,6 +102,7 @@ class component {
|
||||
];
|
||||
/** @var array<string|array<string>> associative array of PRS-4 namespaces and corresponding paths. */
|
||||
protected static $psr4namespaces = [
|
||||
\Html2Text::class => 'lib/html2text/src',
|
||||
\MaxMind::class => 'lib/maxmind/MaxMind',
|
||||
\GeoIp2::class => 'lib/maxmind/GeoIp2',
|
||||
\Sabberworm\CSS::class => 'lib/php-css-parser',
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# Html2Text
|
||||
|
||||
A PHP library for converting HTML to formatted plain text.
|
||||
|
||||
[](https://github.com/mtibben/html2text/actions/workflows/ci.yml)
|
||||
|
||||
## Installing
|
||||
|
||||
```
|
||||
composer require html2text/html2text
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
```php
|
||||
$html = new \Html2Text\Html2Text('Hello, "<b>world</b>"');
|
||||
|
||||
echo $html->getText(); // Hello, "WORLD"
|
||||
```
|
||||
|
||||
## History
|
||||
|
||||
This library started life on the blog of Jon Abernathy http://www.chuggnutt.com/html2text
|
||||
|
||||
A number of projects picked up the library and started using it - among those was RoundCube mail. They made a number of updates to it over time to suit their webmail client.
|
||||
|
||||
Now it has been extracted as a standalone library. Hopefully it can be of use to others.
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "html2text/html2text",
|
||||
"description": "Converts HTML to formatted plain text",
|
||||
"type": "library",
|
||||
"license": "GPL-2.0-or-later",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Html2Text\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Html2Text\\": "test/"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4|^9.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance",
|
||||
"symfony/polyfill-mbstring": "If you can't install ext-mbstring"
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/html2text/Html2Text.php');
|
||||
require_once(__DIR__ . '/override.php');
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Description of Html2Text v4.3.1 library import into Moodle
|
||||
Description of Html2Text library import into Moodle
|
||||
|
||||
Please note that we override some mb_* functions in Html2Text's namespace at
|
||||
run time. Until Html2Text adds some sort of fallback for the mb_* functions
|
||||
@@ -9,6 +9,8 @@ Instructions
|
||||
------------
|
||||
1. Download the latest release of Html2Text from https://github.com/mtibben/html2text/releases/
|
||||
2. Extract the contents of the release archive into a directory.
|
||||
3. Copy src/Html2Text.php to lib/html2text/
|
||||
3. Copy src to lib/html2text/src
|
||||
4. Update README
|
||||
5. Update composer.json
|
||||
|
||||
Imported from: https://github.com/mtibben/html2text/releases/
|
||||
|
||||
@@ -236,16 +236,19 @@ class Html2Text
|
||||
*/
|
||||
public function __construct($html = '', $options = array())
|
||||
{
|
||||
$this->htmlFuncFlags = (PHP_VERSION_ID < 50400)
|
||||
? ENT_QUOTES
|
||||
: ENT_QUOTES | ENT_HTML5;
|
||||
|
||||
// for backwards compatibility
|
||||
if (!is_array($options)) {
|
||||
return call_user_func_array(array($this, 'legacyConstruct'), func_get_args());
|
||||
// phpcs:ignore (PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
|
||||
call_user_func_array(array($this, 'legacyConstruct'), func_get_args());
|
||||
return;
|
||||
}
|
||||
|
||||
$this->html = $html;
|
||||
$this->options = array_merge($this->options, $options);
|
||||
$this->htmlFuncFlags = (PHP_VERSION_ID < 50400)
|
||||
? ENT_COMPAT
|
||||
: ENT_COMPAT | ENT_HTML5;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,7 +354,11 @@ class Html2Text
|
||||
{
|
||||
$this->linkList = array();
|
||||
|
||||
$text = trim($this->html);
|
||||
if ($this->html === null) {
|
||||
$text = '';
|
||||
} else {
|
||||
$text = trim($this->html);
|
||||
}
|
||||
|
||||
$this->converter($text);
|
||||
|
||||
@@ -389,6 +396,9 @@ class Html2Text
|
||||
$text = preg_replace("/[\n]{3,}/", "\n\n", $text);
|
||||
|
||||
// remove leading empty lines (can be produced by eg. P tag on the beginning)
|
||||
if ($text === null) {
|
||||
$text = '';
|
||||
}
|
||||
$text = ltrim($text, "\n");
|
||||
|
||||
if ($this->options['width'] > 0) {
|
||||
@@ -417,7 +427,7 @@ class Html2Text
|
||||
}
|
||||
|
||||
// Ignored link types
|
||||
if (preg_match('!^(javascript:|mailto:|#)!i', html_entity_decode($link))) {
|
||||
if (preg_match('!^(javascript:|mailto:|#)!i', html_entity_decode($link, $this->htmlFuncFlags, self::ENCODING))) {
|
||||
return $display;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@
|
||||
<location>html2text</location>
|
||||
<name>HTML2Text</name>
|
||||
<description>PHP script to convert HTML into an approximate text equivalent.</description>
|
||||
<version>4.3.1</version>
|
||||
<version>4.3.2</version>
|
||||
<license>GPL</license>
|
||||
<licenseversion>2.0+</licenseversion>
|
||||
<repository>https://github.com/mtibben/html2text</repository>
|
||||
|
||||
Reference in New Issue
Block a user