fix html2markdown() and re-enable previously failing tests

This commit is contained in:
Mario Vavti
2018-10-30 13:55:08 +01:00
parent 2192ea6fdf
commit 0b371c8103
2 changed files with 6 additions and 13 deletions

View File

@@ -248,20 +248,12 @@ function bb_to_markdown($Text, $options = []) {
// Convert it to HTML - don't try oembed
$Text = bbcode($Text, [ 'tryoembed' => false ]);
// Markdownify does not preserve previously escaped html entities such as <> and &.
//$Text = str_replace(array('&lt;','&gt;','&amp;'),array('&_lt_;','&_gt_;','&_amp_;'),$Text);
// Now convert HTML to Markdown
$Text = html2markdown($Text);
//html2markdown adds backslashes infront of hashes after a new line. remove them
$Text = str_replace("\n\#", "\n#", $Text);
// It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason.
//$Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('&lt;','&gt;','&amp;'),$Text);
// If the text going into bbcode() has a plain URL in it, i.e.
// with no [url] tags around it, it will come out of parseString()
// looking like: <http://url.com>, which gets removed by strip_tags().
@@ -298,7 +290,8 @@ function html2markdown($html,$options = []) {
$internal_errors = libxml_use_internal_errors(true);
$environment = Environment::createDefaultEnvironment($options);
$environment = new Environment($options);
$environment->createDefaultEnvironment();
$environment->addConverter(new TableConverter());
$converter = new HtmlConverter($environment);