Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

/* You can use any of the three usage methods below */

# usage 1
// usage 1
// $h = new HtmlUp($markdown);
// echo $h->parse();
// echo $h->parse();

# usage 2
// usage 2
// $h = new HtmlUp($markdown);
// echo $h;
// echo $h;

# usage 3
// usage 3
echo new HtmlUp($markdown);
18 changes: 9 additions & 9 deletions src/HtmlUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public function __construct($markdown)
{
// some normalisations
$this->Lines =
explode("\n", # the lines !
trim( # trim trailing \n
str_replace(array("\r\n", "\r"), "\n", # use standard newline
str_replace("\t", ' ', $markdown) # use 4 spaces for tab
explode("\n", // the lines !
trim( // trim trailing \n
str_replace(["\r\n", "\r"], "\n", // use standard newline
str_replace("\t", ' ', $markdown) // use 4 spaces for tab
), "\n"
)
);
Expand Down Expand Up @@ -54,7 +54,7 @@ public function parse()
$markup = '';
$nestLevel = $quoteLevel = 0;
$indent = $nextIndent = 0;
$stackList = $stackBlock = $stackTable = array();
$stackList = $stackBlock = $stackTable = [];
$lastPointer = count($this->Lines) - 1;

while (isset($this->Lines[++$this->Pointer])) {
Expand Down Expand Up @@ -86,7 +86,7 @@ public function parse()
) {
$markup .= "\n$line";
if (empty($inHtml) and
empty($this->Lines[$this->Pointer-1])
empty($this->Lines[$this->Pointer - 1])
) {
$inHtml = true;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public function parse()
(($line = htmlspecialchars($this->Lines[$this->Pointer + 1])) or true) and
(($codeBlock and substr(ltrim($line), 0, 3) !== '```') or substr($line, 0, 4) === ' ')
) {
$markup .= "\n"; # @todo: donot use \n for first line
$markup .= "\n"; // @todo: donot use \n for first line
$markup .= $codeBlock ? $line : substr($line, 4);
++$this->Pointer;
}
Expand All @@ -171,7 +171,7 @@ public function parse()
}

// list
if ($ul = in_array($mark12, array('- ', '* ', '+ ')) or
if ($ul = in_array($mark12, ['- ', '* ', '+ ']) or
preg_match('/^\d+\. /', $trimmedLine)
) {
$wrapper = $ul ? 'ul' : 'ol';
Expand All @@ -184,7 +184,7 @@ public function parse()

$markup .= '<li>'.ltrim($trimmedLine, '-*0123456789. ');

if ($ul = in_array($nextMark12, array('- ', '* ', '+ ')) or
if ($ul = in_array($nextMark12, ['- ', '* ', '+ ']) or
preg_match('/^\d+\. /', $trimmedNextLine)
) {
$wrapper = $ul ? 'ul' : 'ol';
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

error_reporting(E_ALL);

foreach (array(
foreach ([
dirname(__DIR__).'/vendor/autoload.php',
dirname(dirname(dirname(__DIR__))).'/autoload.php',
) as $loader) {
] as $loader) {
if (is_file($loader)) {
return require $loader;
}
Expand Down
47 changes: 23 additions & 24 deletions tests/src/HtmlUpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class HtmlUpTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider dataSrc
*
*/
public function testAll()
{
Expand All @@ -24,37 +23,37 @@ public function testAll()
* 'markdown text',
* 'expected markup text'
* )
* </code>
* </code>.
*/
public function dataSrc()
{
return array(
array(
return [
[
'Atx Header',
$this->assemble('# HelloH1', '## HelloH2'),
'<h1>HelloH1</h1><h2>HelloH2</h2>'
),
array(
'<h1>HelloH1</h1><h2>HelloH2</h2>',
],
[
'Unordered List',
$this->assemble('- Hello', '* HelloAgain'),
'<ul><li>Hello</li><li>HelloAgain</li></ul>'
),
array(
'<ul><li>Hello</li><li>HelloAgain</li></ul>',
],
[
'Ordered List',
$this->assemble('1. Hello', '2. HelloAgain'),
'<ol><li>Hello</li><li>HelloAgain</li></ol>'
),
array(
'<ol><li>Hello</li><li>HelloAgain</li></ol>',
],
[
'H8 is Paragraph',
'######## NoHeader',
'<p>######## NoHeader</p>'
),
array(
'<p>######## NoHeader</p>',
],
[
'Horizontal Rule',
$this->assemble('', '***', '', '___'),
'<hr /><hr />'
),
array(
'<hr /><hr />',
],
[
'Table',
$this->assemble('a | b', '---|---', '1 | 2', '4 | 5'),
'<table>
Expand All @@ -74,9 +73,9 @@ public function dataSrc()
<td>5</td>
</tr>
</tbody>
</table>'
),
);
</table>',
],
];
}

protected function assertion($testName, $expected, $actual)
Expand All @@ -91,8 +90,8 @@ protected function assertion($testName, $expected, $actual)
protected function normalizeMarkup($markup)
{
$markup = preg_replace(
array('/\>[^\S ]+/s', '/[^\S ]+\</s', ),
array('>', '<', ),
['/\>[^\S ]+/s', '/[^\S ]+\</s'],
['>', '<'],
$markup
);

Expand Down