diff options
author | Mario Vavti <mario@mariovavti.com> | 2018-10-30 13:55:08 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2018-10-30 13:55:08 +0100 |
commit | 0b371c8103b49a1bc9cde99fc13dabc330e9936c (patch) | |
tree | 42924dc24d0868474e0d9ec406a58ba46d582f59 | |
parent | 2192ea6fdf21a00ccf44d626a01b756d194d6cbe (diff) | |
download | volse-hubzilla-0b371c8103b49a1bc9cde99fc13dabc330e9936c.tar.gz volse-hubzilla-0b371c8103b49a1bc9cde99fc13dabc330e9936c.tar.bz2 volse-hubzilla-0b371c8103b49a1bc9cde99fc13dabc330e9936c.zip |
fix html2markdown() and re-enable previously failing tests
-rw-r--r-- | include/markdown.php | 11 | ||||
-rw-r--r-- | tests/unit/includes/MarkdownTest.php | 8 |
2 files changed, 6 insertions, 13 deletions
diff --git a/include/markdown.php b/include/markdown.php index d2148811c..0947afeff 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -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('<','>','&'),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('<','>','&'),$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); diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php index f0e253a58..c1408b303 100644 --- a/tests/unit/includes/MarkdownTest.php +++ b/tests/unit/includes/MarkdownTest.php @@ -52,12 +52,12 @@ class MarkdownTest extends UnitTestCase { ' ', '' ], -/* it is not clear why this test fails + 'strong, b, em, i, bib' => [ '<strong>strong</strong> <b>bold</b> <em>em</em> <i>italic</i> <b>bo<i>italic</i>ld</b>', '**strong** **bold** _em_ _italic_ **bo_italic_ld**' ], -*/ + 'empty tags' => [ 'text1 <b></b> text2 <i></i>', 'text1 text2' @@ -118,12 +118,12 @@ class MarkdownTest extends UnitTestCase { '<code><p>HTML text</p></code>', '`<p>HTML text</p>`' ], -/* it is not clear why this test fails + 'pre' => [ '<pre> line with spaces </pre>', '` line with spaces `' ], -*/ + 'div p' => [ '<div>div</div><div><p>p</p></div>', "<div>div</div><div>p\n\n</div>" |