mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Standardise formatting
This commit is contained in:
parent
267256cbb8
commit
8512e65a18
34
.php_cs.dist
Normal file
34
.php_cs.dist
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
use PhpCsFixer\Config;
|
||||||
|
use PhpCsFixer\Finder;
|
||||||
|
$finder = Finder::create()
|
||||||
|
->in(__DIR__ . '/src/')
|
||||||
|
->in(__DIR__ . '/tests/')
|
||||||
|
;
|
||||||
|
$rules = [
|
||||||
|
'@PSR2' => true,
|
||||||
|
'array_syntax' => [
|
||||||
|
'syntax' => 'short',
|
||||||
|
],
|
||||||
|
'braces' => [
|
||||||
|
'allow_single_line_closure' => true,
|
||||||
|
],
|
||||||
|
'native_constant_invocation' => [
|
||||||
|
'fix_built_in' => true,
|
||||||
|
],
|
||||||
|
'native_function_invocation' => [
|
||||||
|
'include' => ['@all'],
|
||||||
|
],
|
||||||
|
'no_unused_imports' => true,
|
||||||
|
'ordered_imports' => [
|
||||||
|
'sort_algorithm' => 'alpha',
|
||||||
|
],
|
||||||
|
'strict_comparison' => true,
|
||||||
|
'strict_param' => true,
|
||||||
|
];
|
||||||
|
return Config::create()
|
||||||
|
->setRules($rules)
|
||||||
|
->setFinder($finder)
|
||||||
|
->setUsingCache(false)
|
||||||
|
->setRiskyAllowed(true)
|
||||||
|
;
|
@ -17,7 +17,8 @@
|
|||||||
"ext-mbstring": "*"
|
"ext-mbstring": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^4.8.35"
|
"phpunit/phpunit": "^4.8.35",
|
||||||
|
"friendsofphp/php-cs-fixer": "^2.13"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {"Erusev\\Parsedown\\": "src/"}
|
"psr-4": {"Erusev\\Parsedown\\": "src/"}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
namespace Erusev\Parsedown\Html;
|
namespace Erusev\Parsedown\Html;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
namespace Erusev\Parsedown\Html\Renderables;
|
namespace Erusev\Parsedown\Html\Renderables;
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
namespace Erusev\Parsedown\Html\Renderables;
|
namespace Erusev\Parsedown\Html\Renderables;
|
||||||
|
|
||||||
use Erusev\Parsedown\Html\Renderable;
|
use Erusev\Parsedown\Html\Renderable;
|
||||||
use Erusev\Parsedown\Html\Sanitisation\CharacterFilter;
|
|
||||||
use Erusev\Parsedown\Html\Sanitisation\Escaper;
|
use Erusev\Parsedown\Html\Sanitisation\Escaper;
|
||||||
|
|
||||||
final class Text implements Renderable
|
final class Text implements Renderable
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
namespace Erusev\Parsedown\Html\Sanitisation;
|
namespace Erusev\Parsedown\Html\Sanitisation;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
namespace Erusev\Parsedown\Html\Sanitisation;
|
namespace Erusev\Parsedown\Html\Sanitisation;
|
||||||
|
|
||||||
|
1192
src/Parsedown.php
1192
src/Parsedown.php
File diff suppressed because it is too large
Load Diff
@ -37,18 +37,18 @@ class CommonMarkTestStrict extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function data()
|
public function data()
|
||||||
{
|
{
|
||||||
$spec = file_get_contents(self::SPEC_URL);
|
$spec = \file_get_contents(self::SPEC_URL);
|
||||||
if ($spec === false) {
|
if ($spec === false) {
|
||||||
$this->fail('Unable to load CommonMark spec from ' . self::SPEC_URL);
|
$this->fail('Unable to load CommonMark spec from ' . self::SPEC_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$spec = str_replace("\r\n", "\n", $spec);
|
$spec = \str_replace("\r\n", "\n", $spec);
|
||||||
$spec = strstr($spec, '<!-- END TESTS -->', true);
|
$spec = \strstr($spec, '<!-- END TESTS -->', true);
|
||||||
|
|
||||||
$matches = array();
|
$matches = [];
|
||||||
preg_match_all('/^`{32} example\n((?s).*?)\n\.\n(?:|((?s).*?)\n)`{32}$|^#{1,6} *(.*?)$/m', $spec, $matches, PREG_SET_ORDER);
|
\preg_match_all('/^`{32} example\n((?s).*?)\n\.\n(?:|((?s).*?)\n)`{32}$|^#{1,6} *(.*?)$/m', $spec, $matches, \PREG_SET_ORDER);
|
||||||
|
|
||||||
$data = array();
|
$data = [];
|
||||||
$currentId = 0;
|
$currentId = 0;
|
||||||
$currentSection = '';
|
$currentSection = '';
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
@ -56,15 +56,15 @@ class CommonMarkTestStrict extends PHPUnit_Framework_TestCase
|
|||||||
$currentSection = $match[3];
|
$currentSection = $match[3];
|
||||||
} else {
|
} else {
|
||||||
$currentId++;
|
$currentId++;
|
||||||
$markdown = str_replace('→', "\t", $match[1]);
|
$markdown = \str_replace('→', "\t", $match[1]);
|
||||||
$expectedHtml = isset($match[2]) ? str_replace('→', "\t", $match[2]) : '';
|
$expectedHtml = isset($match[2]) ? \str_replace('→', "\t", $match[2]) : '';
|
||||||
|
|
||||||
$data[$currentId] = array(
|
$data[$currentId] = [
|
||||||
'id' => $currentId,
|
'id' => $currentId,
|
||||||
'section' => $currentSection,
|
'section' => $currentSection,
|
||||||
'markdown' => $markdown,
|
'markdown' => $markdown,
|
||||||
'expectedHtml' => $expectedHtml
|
'expectedHtml' => $expectedHtml
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,10 +23,10 @@ class CommonMarkTestWeak extends CommonMarkTestStrict
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$textLevelElements = $this->parsedown->getTextLevelElements();
|
$textLevelElements = $this->parsedown->getTextLevelElements();
|
||||||
array_walk($textLevelElements, function (&$element) {
|
\array_walk($textLevelElements, function (&$element) {
|
||||||
$element = preg_quote($element, '/');
|
$element = \preg_quote($element, '/');
|
||||||
});
|
});
|
||||||
$this->textLevelElementRegex = '\b(?:' . implode('|', $textLevelElements) . ')\b';
|
$this->textLevelElementRegex = '\b(?:' . \implode('|', $textLevelElements) . ')\b';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,11 +50,11 @@ class CommonMarkTestWeak extends CommonMarkTestStrict
|
|||||||
{
|
{
|
||||||
// invisible whitespaces at the beginning and end of block elements
|
// invisible whitespaces at the beginning and end of block elements
|
||||||
// however, whitespaces at the beginning of <pre> elements do matter
|
// however, whitespaces at the beginning of <pre> elements do matter
|
||||||
$markup = preg_replace(
|
$markup = \preg_replace(
|
||||||
array(
|
[
|
||||||
'/(<(?!(?:' . $this->textLevelElementRegex . '|\bpre\b))\w+\b[^>]*>(?:<' . $this->textLevelElementRegex . '[^>]*>)*)\s+/s',
|
'/(<(?!(?:' . $this->textLevelElementRegex . '|\bpre\b))\w+\b[^>]*>(?:<' . $this->textLevelElementRegex . '[^>]*>)*)\s+/s',
|
||||||
'/\s+((?:<\/' . $this->textLevelElementRegex . '>)*<\/(?!' . $this->textLevelElementRegex . ')\w+\b>)/s'
|
'/\s+((?:<\/' . $this->textLevelElementRegex . '>)*<\/(?!' . $this->textLevelElementRegex . ')\w+\b>)/s'
|
||||||
),
|
],
|
||||||
'$1',
|
'$1',
|
||||||
$markup
|
$markup
|
||||||
);
|
);
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace Erusev\Parsedown\Tests;
|
namespace Erusev\Parsedown\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Erusev\Parsedown\Parsedown;
|
use Erusev\Parsedown\Parsedown;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ParsedownTest extends TestCase
|
class ParsedownTest extends TestCase
|
||||||
{
|
{
|
||||||
final function __construct($name = null, array $data = array(), $dataName = '')
|
final public function __construct($name = null, array $data = [], $dataName = '')
|
||||||
{
|
{
|
||||||
$this->dirs = $this->initDirs();
|
$this->dirs = $this->initDirs();
|
||||||
$this->Parsedown = $this->initParsedown();
|
$this->Parsedown = $this->initParsedown();
|
||||||
@ -23,7 +23,7 @@ class ParsedownTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
protected function initDirs()
|
protected function initDirs()
|
||||||
{
|
{
|
||||||
$dirs []= dirname(__FILE__).'/data/';
|
$dirs []= \dirname(__FILE__).'/data/';
|
||||||
|
|
||||||
return $dirs;
|
return $dirs;
|
||||||
}
|
}
|
||||||
@ -43,24 +43,24 @@ class ParsedownTest extends TestCase
|
|||||||
* @param $test
|
* @param $test
|
||||||
* @param $dir
|
* @param $dir
|
||||||
*/
|
*/
|
||||||
function test_($test, $dir)
|
public function test_($test, $dir)
|
||||||
{
|
{
|
||||||
$markdown = file_get_contents($dir . $test . '.md');
|
$markdown = \file_get_contents($dir . $test . '.md');
|
||||||
|
|
||||||
$expectedMarkup = file_get_contents($dir . $test . '.html');
|
$expectedMarkup = \file_get_contents($dir . $test . '.html');
|
||||||
|
|
||||||
$expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup);
|
$expectedMarkup = \str_replace("\r\n", "\n", $expectedMarkup);
|
||||||
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
|
$expectedMarkup = \str_replace("\r", "\n", $expectedMarkup);
|
||||||
|
|
||||||
$this->Parsedown->setSafeMode(substr($test, 0, 3) === 'xss');
|
$this->Parsedown->setSafeMode(\substr($test, 0, 3) === 'xss');
|
||||||
$this->Parsedown->setStrictMode(substr($test, 0, 6) === 'strict');
|
$this->Parsedown->setStrictMode(\substr($test, 0, 6) === 'strict');
|
||||||
|
|
||||||
$actualMarkup = $this->Parsedown->text($markdown);
|
$actualMarkup = $this->Parsedown->text($markdown);
|
||||||
|
|
||||||
$this->assertEquals($expectedMarkup, $actualMarkup);
|
$this->assertEquals($expectedMarkup, $actualMarkup);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testRawHtml()
|
public function testRawHtml()
|
||||||
{
|
{
|
||||||
$markdown = "```php\nfoobar\n```";
|
$markdown = "```php\nfoobar\n```";
|
||||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||||
@ -77,7 +77,7 @@ class ParsedownTest extends TestCase
|
|||||||
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
|
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTrustDelegatedRawHtml()
|
public function testTrustDelegatedRawHtml()
|
||||||
{
|
{
|
||||||
$markdown = "```php\nfoobar\n```";
|
$markdown = "```php\nfoobar\n```";
|
||||||
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
|
||||||
@ -94,37 +94,32 @@ class ParsedownTest extends TestCase
|
|||||||
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
|
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
|
||||||
}
|
}
|
||||||
|
|
||||||
function data()
|
public function data()
|
||||||
{
|
{
|
||||||
$data = array();
|
$data = [];
|
||||||
|
|
||||||
foreach ($this->dirs as $dir)
|
foreach ($this->dirs as $dir) {
|
||||||
{
|
|
||||||
$Folder = new \DirectoryIterator($dir);
|
$Folder = new \DirectoryIterator($dir);
|
||||||
|
|
||||||
foreach ($Folder as $File)
|
foreach ($Folder as $File) {
|
||||||
{
|
|
||||||
/** @var $File DirectoryIterator */
|
/** @var $File DirectoryIterator */
|
||||||
|
|
||||||
if ( ! $File->isFile())
|
if (! $File->isFile()) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = $File->getFilename();
|
$filename = $File->getFilename();
|
||||||
|
|
||||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
$extension = \pathinfo($filename, \PATHINFO_EXTENSION);
|
||||||
|
|
||||||
if ($extension !== 'md')
|
if ($extension !== 'md') {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$basename = $File->getBasename('.md');
|
$basename = $File->getBasename('.md');
|
||||||
|
|
||||||
if (file_exists($dir . $basename . '.html'))
|
if (\file_exists($dir . $basename . '.html')) {
|
||||||
{
|
$data []= [$basename, $dir];
|
||||||
$data []= array($basename, $dir);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user