Composer: php-markdown updated to 1.8.0

- Classmaps updated
This commit is contained in:
Hypolite Petovan 2018-01-15 08:56:45 -05:00
parent 35d334dd26
commit 53c5af0676
14 changed files with 409 additions and 368 deletions

19
composer.lock generated
View file

@ -161,30 +161,25 @@
},
{
"name": "michelf/php-markdown",
"version": "1.7.0",
"version": "1.8.0",
"source": {
"type": "git",
"url": "https://github.com/michelf/php-markdown.git",
"reference": "1f51cc520948f66cd2af8cbc45a5ee175e774220"
"reference": "01ab082b355bf188d907b9929cd99b2923053495"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/michelf/php-markdown/zipball/1f51cc520948f66cd2af8cbc45a5ee175e774220",
"reference": "1f51cc520948f66cd2af8cbc45a5ee175e774220",
"url": "https://api.github.com/repos/michelf/php-markdown/zipball/01ab082b355bf188d907b9929cd99b2923053495",
"reference": "01ab082b355bf188d907b9929cd99b2923053495",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-lib": "1.4.x-dev"
}
},
"autoload": {
"psr-0": {
"Michelf": ""
"psr-4": {
"Michelf\\": "Michelf/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -208,7 +203,7 @@
"keywords": [
"markdown"
],
"time": "2016-10-29T18:58:20+00:00"
"time": "2018-01-15T00:49:33+00:00"
},
{
"name": "mobiledetect/mobiledetectlib",

View file

@ -17,6 +17,7 @@ return array(
'Friendica\\Content\\ForumManager' => $baseDir . '/src/Content/ForumManager.php',
'Friendica\\Content\\OEmbed' => $baseDir . '/src/Content/OEmbed.php',
'Friendica\\Content\\Smilies' => $baseDir . '/src/Content/Smilies.php',
'Friendica\\Content\\Text\\Markdown' => $baseDir . '/src/Content/Text/Markdown.php',
'Friendica\\Core\\Cache' => $baseDir . '/src/Core/Cache.php',
'Friendica\\Core\\Config' => $baseDir . '/src/Core/Config.php',
'Friendica\\Core\\NotificationsManager' => $baseDir . '/src/Core/NotificationsManager.php',

View file

@ -7,7 +7,6 @@ $baseDir = dirname($vendorDir);
return array(
'Text' => array($vendorDir . '/pear/text_languagedetect'),
'Michelf' => array($vendorDir . '/michelf/php-markdown'),
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
'Detection' => array($vendorDir . '/mobiledetect/mobiledetectlib/namespaced'),
);

View file

@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Michelf\\' => array($vendorDir . '/michelf/php-markdown/Michelf'),
'League\\HTMLToMarkdown\\' => array($vendorDir . '/league/html-to-markdown/src'),
'Friendica\\' => array($baseDir . '/src'),
);

View file

@ -14,6 +14,10 @@ class ComposerStaticInitFriendica
);
public static $prefixLengthsPsr4 = array (
'M' =>
array (
'Michelf\\' => 8,
),
'L' =>
array (
'League\\HTMLToMarkdown\\' => 22,
@ -25,6 +29,10 @@ class ComposerStaticInitFriendica
);
public static $prefixDirsPsr4 = array (
'Michelf\\' =>
array (
0 => __DIR__ . '/..' . '/michelf/php-markdown/Michelf',
),
'League\\HTMLToMarkdown\\' =>
array (
0 => __DIR__ . '/..' . '/league/html-to-markdown/src',
@ -43,13 +51,6 @@ class ComposerStaticInitFriendica
0 => __DIR__ . '/..' . '/pear/text_languagedetect',
),
),
'M' =>
array (
'Michelf' =>
array (
0 => __DIR__ . '/..' . '/michelf/php-markdown',
),
),
'H' =>
array (
'HTMLPurifier' =>
@ -78,6 +79,7 @@ class ComposerStaticInitFriendica
'Friendica\\Content\\ForumManager' => __DIR__ . '/../..' . '/src/Content/ForumManager.php',
'Friendica\\Content\\OEmbed' => __DIR__ . '/../..' . '/src/Content/OEmbed.php',
'Friendica\\Content\\Smilies' => __DIR__ . '/../..' . '/src/Content/Smilies.php',
'Friendica\\Content\\Text\\Markdown' => __DIR__ . '/../..' . '/src/Content/Text/Markdown.php',
'Friendica\\Core\\Cache' => __DIR__ . '/../..' . '/src/Core/Cache.php',
'Friendica\\Core\\Config' => __DIR__ . '/../..' . '/src/Core/Config.php',
'Friendica\\Core\\NotificationsManager' => __DIR__ . '/../..' . '/src/Core/NotificationsManager.php',

View file

@ -160,33 +160,28 @@
},
{
"name": "michelf/php-markdown",
"version": "1.7.0",
"version_normalized": "1.7.0.0",
"version": "1.8.0",
"version_normalized": "1.8.0.0",
"source": {
"type": "git",
"url": "https://github.com/michelf/php-markdown.git",
"reference": "1f51cc520948f66cd2af8cbc45a5ee175e774220"
"reference": "01ab082b355bf188d907b9929cd99b2923053495"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/michelf/php-markdown/zipball/1f51cc520948f66cd2af8cbc45a5ee175e774220",
"reference": "1f51cc520948f66cd2af8cbc45a5ee175e774220",
"url": "https://api.github.com/repos/michelf/php-markdown/zipball/01ab082b355bf188d907b9929cd99b2923053495",
"reference": "01ab082b355bf188d907b9929cd99b2923053495",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-10-29T18:58:20+00:00",
"time": "2018-01-15T00:49:33+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-lib": "1.4.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Michelf": ""
"psr-4": {
"Michelf\\": "Michelf/"
}
},
"notification-url": "https://packagist.org/downloads/",

View file

@ -0,0 +1,3 @@
*~
/composer.lock
/vendor/

View file

@ -1,11 +1,11 @@
PHP Markdown Lib
Copyright (c) 2004-2016 Michel Fortin
Copyright (c) 2004-2018 Michel Fortin
<https://michelf.ca/>
All rights reserved.
Based on Markdown
Copyright (c) 2003-2006 John Gruber
<https://daringfireball.net/>
Copyright (c) 2003-2006 John Gruber
<https://daringfireball.net/>
All rights reserved.
Redistribution and use in source and binary forms, with or without

View file

@ -4,7 +4,7 @@
*
* @package php-markdown
* @author Michel Fortin <michel.fortin@michelf.com>
* @copyright 2004-2016 Michel Fortin <https://michelf.com/projects/php-markdown/>
* @copyright 2004-2018 Michel Fortin <https://michelf.com/projects/php-markdown/>
* @copyright (Original Markdown) 2004-2006 John Gruber <https://daringfireball.net/projects/markdown/>
*/
@ -18,7 +18,7 @@ class Markdown implements MarkdownInterface {
* Define the package version
* @var string
*/
const MARKDOWNLIB_VERSION = "1.7.0";
const MARKDOWNLIB_VERSION = "1.8.0";
/**
* Simple function interface - Initialize the parser and return the result
@ -61,14 +61,14 @@ class Markdown implements MarkdownInterface {
* @var int
*/
public $tab_width = 4;
/**
* Change to `true` to disallow markup or entities.
* @var boolean
*/
public $no_markup = false;
public $no_entities = false;
/**
* Change to `true` to enable line breaks on \n without two trailling spaces
@ -94,7 +94,7 @@ class Markdown implements MarkdownInterface {
* @var callable
*/
public $header_id_func = null;
/**
* Optional function for converting code block content to HTML
* @var callable
@ -111,7 +111,7 @@ class Markdown implements MarkdownInterface {
* Class attribute to toggle "enhanced ordered list" behaviour
* setting this to true will allow ordered lists to start from the index
* number that is defined first.
*
*
* For example:
* 2. List item two
* 3. List item three
@ -155,17 +155,17 @@ class Markdown implements MarkdownInterface {
public function __construct() {
$this->_initDetab();
$this->prepareItalicsAndBold();
$this->nested_brackets_re =
$this->nested_brackets_re =
str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth).
str_repeat('\])*', $this->nested_brackets_depth);
$this->nested_url_parenthesis_re =
$this->nested_url_parenthesis_re =
str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth).
str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth);
$this->escape_chars_re = '['.preg_quote($this->escape_chars).']';
// Sort document, block, and span gamut in ascendent priority order.
asort($this->document_gamut);
asort($this->block_gamut);
@ -180,13 +180,19 @@ class Markdown implements MarkdownInterface {
protected $urls = array();
protected $titles = array();
protected $html_hashes = array();
/**
* Status flag to avoid invalid nesting.
* @var boolean
*/
protected $in_anchor = false;
/**
* Status flag to avoid invalid nesting.
* @var boolean
*/
protected $in_emphasis_processing = false;
/**
* Called before the transformation process starts to setup parser states.
* @return void
@ -197,8 +203,9 @@ class Markdown implements MarkdownInterface {
$this->titles = $this->predef_titles;
$this->html_hashes = array();
$this->in_anchor = false;
$this->in_emphasis_processing = false;
}
/**
* Called after the transformation process to clear any variable which may
* be taking up memory unnecessarly.
@ -221,7 +228,7 @@ class Markdown implements MarkdownInterface {
*/
public function transform($text) {
$this->setup();
# Remove UTF-8 BOM and marker character in input, if present.
$text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text);
@ -248,7 +255,7 @@ class Markdown implements MarkdownInterface {
foreach ($this->document_gamut as $method => $priority) {
$text = $this->$method($text);
}
$this->teardown();
return $text . "\n";
@ -271,7 +278,7 @@ class Markdown implements MarkdownInterface {
* @return string
*/
protected function stripLinkDefinitions($text) {
$less_than_tab = $this->tab_width - 1;
// Link defs are in the form: ^[id]: url "optional title"
@ -338,8 +345,8 @@ class Markdown implements MarkdownInterface {
* for is hard-coded:
*
* * List "a" is made of tags which can be both inline or block-level.
* These will be treated block-level when the start tag is alone on
* its line, otherwise they're not matched here and will be taken as
* These will be treated block-level when the start tag is alone on
* its line, otherwise they're not matched here and will be taken as
* inline later.
* * List "b" is made of tags which are always block-level;
*/
@ -363,7 +370,7 @@ class Markdown implements MarkdownInterface {
|
\'[^\']*\' # text inside single quotes (tolerate ">")
)*
)?
)?
';
$content =
str_repeat('
@ -380,7 +387,7 @@ class Markdown implements MarkdownInterface {
str_repeat('
</\2\s*> # closing nested tag
)
|
|
<(?!/\2\s*> # other tags with a different name
)
)*',
@ -409,9 +416,9 @@ class Markdown implements MarkdownInterface {
)
( # save in $1
# Match from `\n<tag>` to `</tag>\n`, handling nested tags
# Match from `\n<tag>` to `</tag>\n`, handling nested tags
# in between.
[ ]{0,'.$less_than_tab.'}
<('.$block_tags_b_re.')# start tag = $2
'.$attr.'> # attributes followed by > and \n
@ -429,28 +436,28 @@ class Markdown implements MarkdownInterface {
</\3> # the matching end tag
[ ]* # trailing spaces/tabs
(?=\n+|\Z) # followed by a newline or end of document
| # Special case just for <hr />. It was easier to make a special
| # Special case just for <hr />. It was easier to make a special
# case than to make the other regex more complicated.
[ ]{0,'.$less_than_tab.'}
<(hr) # start tag = $2
'.$attr.' # attributes
/?> # the matching end tag
[ ]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
| # Special case for standalone HTML comments:
[ ]{0,'.$less_than_tab.'}
(?s:
<!-- .*? -->
)
[ ]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
| # PHP and ASP-style processor instructions (<? and <%)
[ ]{0,'.$less_than_tab.'}
(?s:
<([?%]) # $2
@ -459,7 +466,7 @@ class Markdown implements MarkdownInterface {
)
[ ]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
)
)}Sxmi',
array($this, '_hashHTMLBlocks_callback'),
@ -479,9 +486,9 @@ class Markdown implements MarkdownInterface {
$key = $this->hashBlock($text);
return "\n\n$key\n\n";
}
/**
* Called whenever a tag must be hashed when a function insert an atomic
* Called whenever a tag must be hashed when a function insert an atomic
* element in the text stream. Passing $text to through this function gives
* a unique text-token which will be reverted back when calling unhash.
*
@ -498,7 +505,7 @@ class Markdown implements MarkdownInterface {
// Swap back any tag hash found in $text so we do not have to `unhash`
// multiple times at the end.
$text = $this->unhash($text);
// Then hash the block.
static $i = 0;
$key = "$boundary\x1A" . ++$i . $boundary;
@ -531,10 +538,10 @@ class Markdown implements MarkdownInterface {
/**
* Run block gamut tranformations.
*
* We need to escape raw HTML in Markdown source before doing anything
* else. This need to be done for each block, and not only at the
* We need to escape raw HTML in Markdown source before doing anything
* else. This need to be done for each block, and not only at the
* begining in the Markdown function since hashed blocks can be part of
* list items and could have been indented. Indented blocks would have
* list items and could have been indented. Indented blocks would have
* been seen as a code block in a previous pass of hashHTMLBlocks.
*
* @param string $text
@ -546,7 +553,7 @@ class Markdown implements MarkdownInterface {
}
/**
* Run block gamut tranformations, without hashing HTML blocks. This is
* Run block gamut tranformations, without hashing HTML blocks. This is
* useful when HTML blocks are known to be already hashed, like in the first
* whole-document pass.
*
@ -554,11 +561,11 @@ class Markdown implements MarkdownInterface {
* @return string
*/
protected function runBasicBlockGamut($text) {
foreach ($this->block_gamut as $method => $priority) {
$text = $this->$method($text);
}
// Finally form paragraph and restore hashed blocks.
$text = $this->formParagraphs($text);
@ -582,7 +589,7 @@ class Markdown implements MarkdownInterface {
[ ]* # Tailing spaces
$ # End of line.
}mx',
"\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n",
"\n".$this->hashBlock("<hr$this->empty_element_suffix")."\n",
$text
);
}
@ -629,10 +636,10 @@ class Markdown implements MarkdownInterface {
*/
protected function doHardBreaks($text) {
if ($this->hard_wrap) {
return preg_replace_callback('/ *\n/',
return preg_replace_callback('/ *\n/',
array($this, '_doHardBreaks_callback'), $text);
} else {
return preg_replace_callback('/ {2,}\n/',
return preg_replace_callback('/ {2,}\n/',
array($this, '_doHardBreaks_callback'), $text);
}
}
@ -656,7 +663,7 @@ class Markdown implements MarkdownInterface {
return $text;
}
$this->in_anchor = true;
// First, handle reference-style links: [link text] [id]
$text = preg_replace_callback('{
( # wrap whole match in $1
@ -729,7 +736,7 @@ class Markdown implements MarkdownInterface {
// for shortcut links like [this][] or [this].
$link_id = $link_text;
}
// lower-case and turn embedded newlines into spaces
$link_id = strtolower($link_id);
$link_id = preg_replace('{[ ]?\n}', ' ', $link_id);
@ -737,14 +744,14 @@ class Markdown implements MarkdownInterface {
if (isset($this->urls[$link_id])) {
$url = $this->urls[$link_id];
$url = $this->encodeURLAttribute($url);
$result = "<a href=\"$url\"";
if ( isset( $this->titles[$link_id] ) ) {
$title = $this->titles[$link_id];
$title = $this->encodeAttribute($title);
$result .= " title=\"$title\"";
}
$link_text = $this->runSpanGamut($link_text);
$result .= ">$link_text</a>";
$result = $this->hashPart($result);
@ -779,7 +786,7 @@ class Markdown implements MarkdownInterface {
$title = $this->encodeAttribute($title);
$result .= " title=\"$title\"";
}
$link_text = $this->runSpanGamut($link_text);
$result .= ">$link_text</a>";
@ -807,7 +814,7 @@ class Markdown implements MarkdownInterface {
\]
)
}xs',
}xs',
array($this, '_doImages_reference_callback'), $text);
// Next, handle inline images: ![alt text](url "optional title")
@ -906,7 +913,7 @@ class Markdown implements MarkdownInterface {
* Setext-style headers:
* Header 1
* ========
*
*
* Header 2
* --------
*/
@ -944,7 +951,7 @@ class Markdown implements MarkdownInterface {
if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) {
return $matches[0];
}
$level = $matches[2]{0} == '=' ? 1 : 2;
// ID attribute generation
@ -977,7 +984,7 @@ class Markdown implements MarkdownInterface {
* @param string $headerValue
* @return string
*/
protected function _generateIdFromHeaderValue($headerValue) {
protected function _generateIdFromHeaderValue($headerValue) {
if (!is_callable($this->header_id_func)) {
return "";
}
@ -1035,10 +1042,10 @@ class Markdown implements MarkdownInterface {
)
)
'; // mx
// We use a different prefix before nested lists than top-level lists.
//See extended comment in _ProcessListItems().
if ($this->list_level) {
$text = preg_replace_callback('{
^
@ -1132,7 +1139,7 @@ class Markdown implements MarkdownInterface {
* without resorting to mind-reading. Perhaps the solution is to
* change the syntax rules such that sub-lists must start with a
* starting cardinal number; e.g. "1." or "a.".
*/
*/
$this->list_level++;
// Trim trailing blank lines:
@ -1166,7 +1173,7 @@ class Markdown implements MarkdownInterface {
$marker_space = $matches[3];
$tailing_blank_line =& $matches[5];
if ($leading_line || $tailing_blank_line ||
if ($leading_line || $tailing_blank_line ||
preg_match('/\n{2,}/', $item))
{
// Replace marker with the appropriate whitespace indentation
@ -1273,7 +1280,7 @@ class Markdown implements MarkdownInterface {
* @var array
*/
protected $em_strong_prepared_relist;
/**
* Prepare regular expressions for searching emphasis tokens in any
* context.
@ -1289,7 +1296,7 @@ class Markdown implements MarkdownInterface {
}
$token_relist[] = $em_re;
$token_relist[] = $strong_re;
// Construct master expression from list.
$token_re = '{(' . implode('|', $token_relist) . ')}';
$this->em_strong_prepared_relist["$em$strong"] = $token_re;
@ -1303,24 +1310,29 @@ class Markdown implements MarkdownInterface {
* @return string
*/
protected function doItalicsAndBold($text) {
if ($this->in_emphasis_processing) {
return $text; // avoid reentrency
}
$this->in_emphasis_processing = true;
$token_stack = array('');
$text_stack = array('');
$em = '';
$strong = '';
$tree_char_em = false;
while (1) {
// Get prepared regular expression for seraching emphasis tokens
// in current context.
$token_re = $this->em_strong_prepared_relist["$em$strong"];
// Each loop iteration search for the next emphasis token.
// Each loop iteration search for the next emphasis token.
// Each token is then passed to handleSpanToken.
$parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE);
$text_stack[0] .= $parts[0];
$token =& $parts[1];
$text =& $parts[2];
if (empty($token)) {
// Reached end of text span: empty stack without emitting.
// any more emphasis.
@ -1330,7 +1342,7 @@ class Markdown implements MarkdownInterface {
}
break;
}
$token_len = strlen($token);
if ($tree_char_em) {
// Reached closing marker while inside a three-char emphasis.
@ -1369,7 +1381,7 @@ class Markdown implements MarkdownInterface {
$$tag = ''; // $$tag stands for $em or $strong
}
} else {
// Reached opening three-char emphasis marker. Push on token
// Reached opening three-char emphasis marker. Push on token
// stack; will be handled by the special condition above.
$em = $token{0};
$strong = "$em$em";
@ -1383,6 +1395,7 @@ class Markdown implements MarkdownInterface {
if (strlen($token_stack[0]) == 1) {
$text_stack[1] .= array_shift($token_stack);
$text_stack[0] .= array_shift($text_stack);
$em = '';
}
// Closing strong marker:
array_shift($token_stack);
@ -1417,6 +1430,7 @@ class Markdown implements MarkdownInterface {
}
}
}
$this->in_emphasis_processing = false;
return $text_stack[0];
}
@ -1453,9 +1467,9 @@ class Markdown implements MarkdownInterface {
$bq = $this->runBlockGamut($bq); // recurse
$bq = preg_replace('/^/m', " ", $bq);
// These leading spaces cause problem with <pre> content,
// These leading spaces cause problem with <pre> content,
// so we need to fix that:
$bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
$bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
array($this, '_doBlockQuotes_callback2'), $bq);
return "\n" . $this->hashBlock("<blockquote>\n$bq\n</blockquote>") . "\n\n";
@ -1525,7 +1539,7 @@ class Markdown implements MarkdownInterface {
// // We can't call Markdown(), because that resets the hash;
// // that initialization code should be pulled into its own sub, though.
// $div_content = $this->hashHTMLBlocks($div_content);
//
//
// // Run document gamut methods on the content.
// foreach ($this->document_gamut as $method => $priority) {
// $div_content = $this->$method($div_content);
@ -1582,9 +1596,9 @@ class Markdown implements MarkdownInterface {
return $url;
}
/**
* Smart processing for ampersands and angle brackets that need to
* Smart processing for ampersands and angle brackets that need to
* be encoded. Valid character entities are left alone unless the
* no-entities mode is set.
* @param string $text
@ -1596,7 +1610,7 @@ class Markdown implements MarkdownInterface {
} else {
// Ampersand-encoding based entirely on Nat Irons's Amputator
// MT plugin: <http://bumppo.net/projects/amputator/>
$text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/',
$text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/',
'&amp;', $text);
}
// Encode remaining <'s
@ -1724,7 +1738,7 @@ class Markdown implements MarkdownInterface {
*/
protected function parseSpan($str) {
$output = '';
$span_re = '{
(
\\\\'.$this->escape_chars_re.'
@ -1752,16 +1766,16 @@ class Markdown implements MarkdownInterface {
}xs';
while (1) {
// Each loop iteration seach for either the next tag, the next
// openning code span marker, or the next escaped character.
// Each loop iteration seach for either the next tag, the next
// openning code span marker, or the next escaped character.
// Each token is then passed to handleSpanToken.
$parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE);
// Create token from text preceding tag.
if ($parts[0] != "") {
$output .= $parts[0];
}
// Check if we reach the end.
if (isset($parts[1])) {
$output .= $this->handleSpanToken($parts[1], $parts[2]);
@ -1770,7 +1784,7 @@ class Markdown implements MarkdownInterface {
break;
}
}
return $output;
}
@ -1787,7 +1801,7 @@ class Markdown implements MarkdownInterface {
return $this->hashPart("&#". ord($token{1}). ";");
case "`":
// Search for end marker in remaining text.
if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm',
if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm',
$str, $matches))
{
$str = $matches[2];
@ -1823,11 +1837,11 @@ class Markdown implements MarkdownInterface {
* For each line we separate the line in blocks delemited by tab characters.
* Then we reconstruct every line by adding the appropriate number of space
* between each blocks.
*
*
* @param string $text
* @return string
*/
protected function detab($text) {
protected function detab($text) {
$text = preg_replace_callback('/^.*\t.*$/m',
array($this, '_detab_callback'), $text);
@ -1842,7 +1856,7 @@ class Markdown implements MarkdownInterface {
protected function _detab_callback($matches) {
$line = $matches[0];
$strlen = $this->utf8_strlen; // strlen function for UTF-8.
// Split in blocks.
$blocks = explode("\t", $line);
// Add each blocks to the line.
@ -1850,7 +1864,7 @@ class Markdown implements MarkdownInterface {
unset($blocks[0]); // Do not add first block twice.
foreach ($blocks as $block) {
// Calculate amount of space, insert spaces, insert block.
$amount = $this->tab_width -
$amount = $this->tab_width -
$strlen($line, 'UTF-8') % $this->tab_width;
$line .= str_repeat(" ", $amount) . $block;
}
@ -1859,20 +1873,20 @@ class Markdown implements MarkdownInterface {
/**
* Check for the availability of the function in the `utf8_strlen` property
* (initially `mb_strlen`). If the function is not available, create a
* (initially `mb_strlen`). If the function is not available, create a
* function that will loosely count the number of UTF-8 characters with a
* regular expression.
* @return void
*/
protected function _initDetab() {
if (function_exists($this->utf8_strlen)) {
return;
}
$this->utf8_strlen = create_function('$text', 'return preg_match_all(
"/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/",
$text, $m);');
$this->utf8_strlen = function($text) {
return preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/', $text, $m);
};
}
/**
@ -1881,7 +1895,7 @@ class Markdown implements MarkdownInterface {
* @return string
*/
protected function unhash($text) {
return preg_replace_callback('/(.)\x1A[0-9]+\1/',
return preg_replace_callback('/(.)\x1A[0-9]+\1/',
array($this, '_unhash_callback'), $text);
}

View file

@ -4,7 +4,7 @@
*
* @package php-markdown
* @author Michel Fortin <michel.fortin@michelf.com>
* @copyright 2004-2016 Michel Fortin <https://michelf.com/projects/php-markdown/>
* @copyright 2004-2018 Michel Fortin <https://michelf.com/projects/php-markdown/>
* @copyright (Original Markdown) 2004-2006 John Gruber <https://daringfireball.net/projects/markdown/>
*/
@ -23,14 +23,14 @@ class MarkdownExtra extends \Michelf\Markdown {
* @var string
*/
public $fn_id_prefix = "";
/**
* Optional title attribute for footnote links and backlinks.
* @var string
*/
public $fn_link_title = "";
public $fn_backlink_title = "";
/**
* Optional class attribute for footnote links and backlinks.
* @var string
@ -73,20 +73,26 @@ class MarkdownExtra extends \Michelf\Markdown {
*/
public $predef_abbr = array();
/**
* Only convert atx-style headers if there's a space between the header and #
* @var boolean
*/
public $hashtag_protection = false;
/**
* Parser implementation
*/
/**
* Constructor function. Initialize the parser object.
* @return void
*/
public function __construct() {
// Add extra escapable characters before parent constructor
// Add extra escapable characters before parent constructor
// initialize the table.
$this->escape_chars .= ':|';
// Insert extra document, block, and span transformations.
// Insert extra document, block, and span transformations.
// Parent constructor will do the sorting.
$this->document_gamut += array(
"doFencedCodeBlocks" => 5,
@ -103,12 +109,12 @@ class MarkdownExtra extends \Michelf\Markdown {
"doFootnotes" => 5,
"doAbbreviations" => 70,
);
$this->enhanced_ordered_list = true;
parent::__construct();
}
/**
* Extra variables used during extra transformations.
* @var array
@ -118,21 +124,21 @@ class MarkdownExtra extends \Michelf\Markdown {
protected $footnotes_ref_count = array();
protected $footnotes_numbers = array();
protected $abbr_desciptions = array();
/** @var @string */
/** @var string */
protected $abbr_word_re = '';
/**
* Give the current footnote number.
* @var integer
*/
protected $footnote_counter = 1;
/**
* Setting up Extra-specific variables.
*/
protected function setup() {
parent::setup();
$this->footnotes = array();
$this->footnotes_ordered = array();
$this->footnotes_ref_count = array();
@ -140,7 +146,7 @@ class MarkdownExtra extends \Michelf\Markdown {
$this->abbr_desciptions = array();
$this->abbr_word_re = '';
$this->footnote_counter = 1;
foreach ($this->predef_abbr as $abbr_word => $abbr_desc) {
if ($this->abbr_word_re)
$this->abbr_word_re .= '|';
@ -159,11 +165,11 @@ class MarkdownExtra extends \Michelf\Markdown {
$this->footnotes_numbers = array();
$this->abbr_desciptions = array();
$this->abbr_word_re = '';
parent::teardown();
}
/**
* Extra attribute parser
*/
@ -197,7 +203,7 @@ class MarkdownExtra extends \Michelf\Markdown {
*/
protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null, $classes = array()) {
if (empty($attr) && !$defaultIdValue && empty($classes)) return "";
// Split on components
preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches);
$elements = $matches[0];
@ -288,38 +294,38 @@ class MarkdownExtra extends \Michelf\Markdown {
/**
* HTML block parser
*/
/**
* Tags that are always treated as block tags
* @var string
*/
protected $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|figure';
/**
* Tags treated as block tags only if the opening tag is alone on its line
* @var string
*/
protected $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video';
/**
* Tags where markdown="1" default to span mode:
* @var string
*/
protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address';
/**
* Tags which must not have their contents modified, no matter where
* they appear
* @var string
*/
protected $clean_tags_re = 'script|style|math|svg';
/**
* Tags that do not need to be closed.
* @var string
*/
protected $auto_close_tags_re = 'hr|img|param|source|track';
/**
* Hashify HTML Blocks and "clean tags".
*
@ -330,7 +336,7 @@ class MarkdownExtra extends \Michelf\Markdown {
* hard-coded.
*
* This works by calling _HashHTMLBlocks_InMarkdown, which then calls
* _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1"
* _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1"
* attribute is found within a tag, _HashHTMLBlocks_InHTML calls back
* _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag.
* These two functions are calling each other. It's recursive!
@ -344,15 +350,15 @@ class MarkdownExtra extends \Michelf\Markdown {
// Call the HTML-in-Markdown hasher.
list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text);
return $text;
}
/**
* Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags.
*
* * $indent is the number of space to be ignored when checking for code
* blocks. This is important because if we don't take the indent into
* * $indent is the number of space to be ignored when checking for code
* blocks. This is important because if we don't take the indent into
* account, something like this (which looks right) won't work as expected:
*
* <div>
@ -364,11 +370,11 @@ class MarkdownExtra extends \Michelf\Markdown {
* If you don't like this, just don't indent the tag on which
* you apply the markdown="1" attribute.
*
* * If $enclosing_tag_re is not empty, stops at the first unmatched closing
* * If $enclosing_tag_re is not empty, stops at the first unmatched closing
* tag with that name. Nested tags supported.
*
* * If $span is true, text inside must treated as span. So any double
* newline will be replaced by a single newline so that it does not create
* * If $span is true, text inside must treated as span. So any double
* newline will be replaced by a single newline so that it does not create
* paragraphs.
*
* Returns an array of that form: ( processed text , remaining text )
@ -382,18 +388,18 @@ class MarkdownExtra extends \Michelf\Markdown {
protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
$enclosing_tag_re = '', $span = false)
{
if ($text === '') return array('', '');
// Regex to check for the presense of newlines around a block tag.
$newline_before_re = '/(?:^\n?|\n\n)*$/';
$newline_after_re =
$newline_after_re =
'{
^ # Start of text following the tag.
(?>[ ]*<!--.*?-->)? # Optional comment.
[ ]*\n # Must be followed by newline.
}xs';
// Regex to match any tag.
$block_tag_re =
'{
@ -448,7 +454,7 @@ class MarkdownExtra extends \Michelf\Markdown {
)
}xs';
$depth = 0; // Current depth inside the tag tree.
$parsed = ""; // Parsed text that will be returned.
@ -457,31 +463,31 @@ class MarkdownExtra extends \Michelf\Markdown {
do {
// Split the text using the first $tag_match pattern found.
// Text before pattern will be first in the array, text after
// pattern will be at the end, and between will be any catches made
// pattern will be at the end, and between will be any catches made
// by the pattern.
$parts = preg_split($block_tag_re, $text, 2,
$parts = preg_split($block_tag_re, $text, 2,
PREG_SPLIT_DELIM_CAPTURE);
// If in Markdown span mode, add a empty-string span-level hash
// If in Markdown span mode, add a empty-string span-level hash
// after each newline to prevent triggering any block element.
if ($span) {
$void = $this->hashPart("", ':');
$newline = "\n$void";
$parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void;
}
$parsed .= $parts[0]; // Text before current tag.
// If end of $text has been reached. Stop loop.
if (count($parts) < 3) {
$text = "";
break;
}
$tag = $parts[1]; // Tag to handle.
$text = $parts[2]; // Remaining text after current tag.
$tag_re = preg_quote($tag); // For use in a regular expression.
// Check for: Fenced code block marker.
// Note: need to recheck the whole tag to disambiguate backtick
// fences from code spans
@ -490,7 +496,7 @@ class MarkdownExtra extends \Michelf\Markdown {
$fence_indent = strlen($capture[1]); // use captured indent in re
$fence_re = $capture[2]; // use captured fence in re
if (preg_match('{^(?>.*\n)*?[ ]{' . ($fence_indent) . '}' . $fence_re . '[ ]*(?:\n|$)}', $text,
$matches))
$matches))
{
// End marker found: pass text unchanged until marker.
$parsed .= $tag . $matches[0];
@ -503,7 +509,7 @@ class MarkdownExtra extends \Michelf\Markdown {
}
// Check for: Indented code block.
else if ($tag{0} == "\n" || $tag{0} == " ") {
// Indented code block: pass it unchanged, will be handled
// Indented code block: pass it unchanged, will be handled
// later.
$parsed .= $tag;
}
@ -525,7 +531,7 @@ class MarkdownExtra extends \Michelf\Markdown {
}
}
// Check for: Opening Block level tag or
// Opening Context Block tag (like ins and del)
// Opening Context Block tag (like ins and del)
// used as a block tag (tag is alone on it's line).
else if (preg_match('{^<(?:' . $this->block_tags_re . ')\b}', $tag) ||
( preg_match('{^<(?:' . $this->context_block_tags_re . ')\b}', $tag) &&
@ -534,9 +540,9 @@ class MarkdownExtra extends \Michelf\Markdown {
)
{
// Need to parse tag and following text using the HTML parser.
list($block_text, $text) =
list($block_text, $text) =
$this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true);
// Make sure it stays outside of any paragraph by adding newlines.
$parsed .= "\n\n$block_text\n\n";
}
@ -547,9 +553,9 @@ class MarkdownExtra extends \Michelf\Markdown {
{
// Need to parse tag and following text using the HTML parser.
// (don't check for markdown attribute)
list($block_text, $text) =
list($block_text, $text) =
$this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false);
$parsed .= $block_text;
}
// Check for: Tag with same name as enclosing tag.
@ -567,14 +573,14 @@ class MarkdownExtra extends \Michelf\Markdown {
$text = $tag . $text;
break;
}
$parsed .= $tag;
}
else {
$parsed .= $tag;
}
} while ($depth >= 0);
return array($parsed, $text);
}
@ -594,7 +600,7 @@ class MarkdownExtra extends \Michelf\Markdown {
*/
protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) {
if ($text === '') return array('', '');
// Regex to match `markdown` attribute inside of a tag.
$markdown_attr_re = '
{
@ -602,15 +608,15 @@ class MarkdownExtra extends \Michelf\Markdown {
markdown
\s*=\s*
(?>
(["\']) # $1: quote delimiter
(["\']) # $1: quote delimiter
(.*?) # $2: attribute value
\1 # matching delimiter
\1 # matching delimiter
|
([^\s>]*) # $3: unquoted attribute value
)
() # $4: make $3 always defined (avoid warnings)
}xs';
// Regex to match any tag.
$tag_re = '{
( # $2: Capture whole tag.
@ -633,9 +639,9 @@ class MarkdownExtra extends \Michelf\Markdown {
<!\[CDATA\[.*?\]\]> # CData Block
)
}xs';
$original_text = $text; // Save original text in case of faliure.
$depth = 0; // Current depth inside the tag tree.
$block_text = ""; // Temporary text holder for current text.
$parsed = ""; // Parsed text that will be returned.
@ -649,22 +655,22 @@ class MarkdownExtra extends \Michelf\Markdown {
do {
// Split the text using the first $tag_match pattern found.
// Text before pattern will be first in the array, text after
// pattern will be at the end, and between will be any catches made
// pattern will be at the end, and between will be any catches made
// by the pattern.
$parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE);
if (count($parts) < 3) {
// End of $text reached with unbalenced tag(s).
// In that case, we return original text unchanged and pass the
// first character as filtered to prevent an infinite loop in the
// first character as filtered to prevent an infinite loop in the
// parent function.
return array($original_text{0}, substr($original_text, 1));
}
$block_text .= $parts[0]; // Text before current tag.
$tag = $parts[1]; // Tag to handle.
$text = $parts[2]; // Remaining text after current tag.
// Check for: Auto-close tag (like <hr/>)
// Comments and Processing Instructions.
if (preg_match('{^</?(?:' . $this->auto_close_tags_re . ')\b}', $tag) ||
@ -680,20 +686,20 @@ class MarkdownExtra extends \Michelf\Markdown {
if ($tag{1} == '/') $depth--;
else if ($tag{strlen($tag)-2} != '/') $depth++;
}
// Check for `markdown="1"` attribute and handle it.
if ($md_attr &&
if ($md_attr &&
preg_match($markdown_attr_re, $tag, $attr_m) &&
preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3]))
{
// Remove `markdown` attribute from opening tag.
$tag = preg_replace($markdown_attr_re, '', $tag);
// Check if text inside this tag must be parsed in span mode.
$this->mode = $attr_m[2] . $attr_m[3];
$span_mode = $this->mode == 'span' || $this->mode != 'block' &&
preg_match('{^<(?:' . $this->contain_span_tags_re . ')\b}', $tag);
// Calculate indent before tag.
if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) {