Automatic pass to convert with php-cs-fixer
This commit is contained in:
162
src/Markdown.php
162
src/Markdown.php
@@ -1,35 +1,42 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework;
|
||||
|
||||
/** Convert the Markdown text to html format
|
||||
*/
|
||||
/**
|
||||
* Convert the Markdown text to html format
|
||||
*/
|
||||
class Markdown
|
||||
{
|
||||
/** To debug the markdown analyzer, activate the option */
|
||||
/**
|
||||
* To debug the markdown analyzer, activate the option
|
||||
*/
|
||||
public $debug = false;
|
||||
|
||||
/** The list of the HTML elements used by block */
|
||||
private $blockid = array("<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>",
|
||||
"<hr/>");
|
||||
/**
|
||||
* The list of the HTML elements used by block
|
||||
*/
|
||||
private $blockid = ["<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>",
|
||||
"<hr/>"];
|
||||
|
||||
/** Convert the markdown text to html
|
||||
* @param string $markdown The markdown to convert
|
||||
*/
|
||||
/**
|
||||
* Convert the markdown text to html
|
||||
* @param string $markdown The markdown to convert
|
||||
*/
|
||||
public function html($markdown)
|
||||
{
|
||||
$markdown = rtrim($markdown);
|
||||
$markdown = htmlentities($markdown);
|
||||
|
||||
// Here are the regexp on multilines
|
||||
$search = array();
|
||||
$replace = array();
|
||||
$search = [];
|
||||
$replace = [];
|
||||
// Titles with underline (SeText)
|
||||
// Titre1
|
||||
// ======
|
||||
@@ -56,9 +63,10 @@ class Markdown
|
||||
return $html;
|
||||
}
|
||||
|
||||
/** Search and replace in the paragraph on one line
|
||||
* @param string $line The line to analyze
|
||||
*/
|
||||
/**
|
||||
* Search and replace in the paragraph on one line
|
||||
* @param string $line The line to analyze
|
||||
*/
|
||||
private function searchReplace($line)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -68,7 +76,7 @@ class Markdown
|
||||
// Quotes : "
|
||||
$res = $line;
|
||||
// Manage the <hr/> separators
|
||||
$search = array("***", "---", "___", "* * *", "- - -", "_ _ _");
|
||||
$search = ["***", "---", "___", "* * *", "- - -", "_ _ _"];
|
||||
foreach ($search as $key => $pattern) {
|
||||
$start = 0;
|
||||
while (1) {
|
||||
@@ -92,8 +100,8 @@ class Markdown
|
||||
}
|
||||
|
||||
// Manage the emphasis and code correctely with the backslash
|
||||
$search = array();
|
||||
$replace = array();
|
||||
$search = [];
|
||||
$replace = [];
|
||||
$search[] = "__";
|
||||
$replace[] = "<strong>\\1</strong>";
|
||||
$search[] = "_";
|
||||
@@ -144,8 +152,8 @@ class Markdown
|
||||
}
|
||||
|
||||
// Manage the others cases
|
||||
$search = array();
|
||||
$replace = array();
|
||||
$search = [];
|
||||
$replace = [];
|
||||
// Titles short
|
||||
// == TITRE1
|
||||
$search[] = '~^([^\\\\]|^)(==+ (.+)( ==+)?)$~Um';
|
||||
@@ -214,16 +222,18 @@ class Markdown
|
||||
echo "$key => $s\n";
|
||||
$res = preg_replace ($s, $replace[$key], $res);
|
||||
echo "$res\n";
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
$res = preg_replace($search, $replace, $res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/** Return HTML code corresponding to the code block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
/**
|
||||
* Return HTML code corresponding to the code block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
private function typeCode($text, $depth, &$pos)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -250,11 +260,12 @@ class Markdown
|
||||
return "<pre><code>$content</code></pre>\n";
|
||||
}
|
||||
|
||||
/** Return HTML code corresponding to the OL block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
/**
|
||||
* Return HTML code corresponding to the OL block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
private function typeOL($text, $depth, &$pos)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -267,11 +278,12 @@ class Markdown
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Return HTML code corresponding to the UL block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
/**
|
||||
* Return HTML code corresponding to the UL block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
private function typeUL($text, $depth, &$pos)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -284,12 +296,13 @@ class Markdown
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Return the HTML code corresponding to the OL/UL block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
* @param string $type The block type : "ul" or "ol"
|
||||
*/
|
||||
/**
|
||||
* Return the HTML code corresponding to the OL/UL block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
* @param string $type The block type : "ul" or "ol"
|
||||
*/
|
||||
private function typeOLUL($text, $depth, &$pos, $type)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -359,13 +372,14 @@ class Markdown
|
||||
return "<$type>\n$content" . str_repeat(" ", $depth) . "</$type>\n";
|
||||
}
|
||||
|
||||
/** Return HTML code corresponding to the NONE block
|
||||
* The NONE type exists only on empty strings. Just skip the current and
|
||||
* empty line, and return an empty string
|
||||
* @param string $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of the current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
/**
|
||||
* Return HTML code corresponding to the NONE block
|
||||
* The NONE type exists only on empty strings. Just skip the current and
|
||||
* empty line, and return an empty string
|
||||
* @param string $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of the current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
private function typeNONE($text, $depth, &$pos)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -375,11 +389,12 @@ class Markdown
|
||||
return "";
|
||||
}
|
||||
|
||||
/** Return HTML code corresponding to the P block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
/**
|
||||
* Return HTML code corresponding to the P block
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
*/
|
||||
private function typeP($text, $depth, &$pos)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -412,12 +427,13 @@ class Markdown
|
||||
return "<p>$content</p>\n";
|
||||
}
|
||||
|
||||
/** Detect the type of the text and call the appropriate function *
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
* @return the HTML code
|
||||
*/
|
||||
/**
|
||||
* Detect the type of the text and call the appropriate function *
|
||||
* @param array $text The Markdown text to translate split by \n
|
||||
* @param integer $depth The depth of current bloc (in number of space)
|
||||
* @param integer &$pos The start line number of the bloc
|
||||
* @return the HTML code
|
||||
*/
|
||||
private function detectBlock($text, $depth, &$pos)
|
||||
{
|
||||
if ($this->debug) {
|
||||
@@ -463,10 +479,11 @@ class Markdown
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Return the Type of object in the provided line
|
||||
* p, ul, ol, code
|
||||
* @param string $line The line to get the type
|
||||
*/
|
||||
/**
|
||||
* Return the Type of object in the provided line
|
||||
* p, ul, ol, code
|
||||
* @param string $line The line to get the type
|
||||
*/
|
||||
private function lineType($line)
|
||||
{
|
||||
if (! isset($line[0])) {
|
||||
@@ -484,10 +501,11 @@ class Markdown
|
||||
return "p";
|
||||
}
|
||||
|
||||
/** Return the depth of the provided line
|
||||
* @param string $line Line to analyze
|
||||
* @return the depth of the line
|
||||
*/
|
||||
/**
|
||||
* Return the depth of the provided line
|
||||
* @param string $line Line to analyze
|
||||
* @return the depth of the line
|
||||
*/
|
||||
private function depth($line)
|
||||
{
|
||||
return strspn($line, " ");
|
||||
|
||||
Reference in New Issue
Block a user