2016-09-05 15:38:47 +03:00
|
|
|
<?php
|
2018-04-17 16:44:38 +03:00
|
|
|
|
|
|
|
namespace Erusev\Parsedown\Tests;
|
2016-09-05 15:38:47 +03:00
|
|
|
|
2019-01-20 05:55:12 +03:00
|
|
|
use Erusev\Parsedown\Html\Renderables\Element;
|
|
|
|
|
2016-09-05 15:38:47 +03:00
|
|
|
/**
|
|
|
|
* Test Parsedown against the CommonMark spec, but less aggressive
|
|
|
|
*
|
|
|
|
* The resulting HTML markup is cleaned up before comparison, so examples
|
|
|
|
* which would normally fail due to actually invisible differences (e.g.
|
|
|
|
* superfluous whitespaces), don't fail. However, cleanup relies on block
|
|
|
|
* element detection. The detection doesn't work correctly when a element's
|
|
|
|
* `display` CSS property is manipulated. According to that this test is only
|
|
|
|
* a interim solution on Parsedown's way to full CommonMark compatibility.
|
|
|
|
*
|
|
|
|
* @link http://commonmark.org/ CommonMark
|
|
|
|
*/
|
2016-10-12 03:01:40 +03:00
|
|
|
class CommonMarkTestWeak extends CommonMarkTestStrict
|
2016-09-05 15:38:47 +03:00
|
|
|
{
|
2016-09-05 16:31:07 +03:00
|
|
|
protected $textLevelElementRegex;
|
|
|
|
|
2016-09-05 15:38:47 +03:00
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2019-01-20 05:55:12 +03:00
|
|
|
$textLevelElements = \array_keys(Element::TEXT_LEVEL_ELEMENTS);
|
|
|
|
|
2018-12-04 19:24:25 +03:00
|
|
|
\array_walk($textLevelElements, function (&$element) {
|
|
|
|
$element = \preg_quote($element, '/');
|
2016-09-05 15:38:47 +03:00
|
|
|
});
|
2018-12-04 19:24:25 +03:00
|
|
|
$this->textLevelElementRegex = '\b(?:' . \implode('|', $textLevelElements) . ')\b';
|
2016-09-05 15:38:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider data
|
2016-10-12 03:01:40 +03:00
|
|
|
* @param $id
|
2016-09-05 15:38:47 +03:00
|
|
|
* @param $section
|
|
|
|
* @param $markdown
|
|
|
|
* @param $expectedHtml
|
|
|
|
*/
|
2016-10-12 03:01:40 +03:00
|
|
|
public function testExample($id, $section, $markdown, $expectedHtml)
|
2016-09-05 15:38:47 +03:00
|
|
|
{
|
|
|
|
$expectedHtml = $this->cleanupHtml($expectedHtml);
|
|
|
|
|
|
|
|
$actualHtml = $this->parsedown->text($markdown);
|
|
|
|
$actualHtml = $this->cleanupHtml($actualHtml);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedHtml, $actualHtml);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function cleanupHtml($markup)
|
|
|
|
{
|
|
|
|
// invisible whitespaces at the beginning and end of block elements
|
|
|
|
// however, whitespaces at the beginning of <pre> elements do matter
|
2018-12-04 19:24:25 +03:00
|
|
|
$markup = \preg_replace(
|
|
|
|
[
|
2016-09-05 16:17:52 +03:00
|
|
|
'/(<(?!(?:' . $this->textLevelElementRegex . '|\bpre\b))\w+\b[^>]*>(?:<' . $this->textLevelElementRegex . '[^>]*>)*)\s+/s',
|
|
|
|
'/\s+((?:<\/' . $this->textLevelElementRegex . '>)*<\/(?!' . $this->textLevelElementRegex . ')\w+\b>)/s'
|
2018-12-04 19:24:25 +03:00
|
|
|
],
|
2016-09-05 15:38:47 +03:00
|
|
|
'$1',
|
|
|
|
$markup
|
|
|
|
);
|
|
|
|
|
|
|
|
return $markup;
|
|
|
|
}
|
|
|
|
}
|