aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/michelf/php-markdown/Michelf/Markdown.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/michelf/php-markdown/Michelf/Markdown.php')
-rw-r--r--vendor/michelf/php-markdown/Michelf/Markdown.php94
1 files changed, 37 insertions, 57 deletions
diff --git a/vendor/michelf/php-markdown/Michelf/Markdown.php b/vendor/michelf/php-markdown/Michelf/Markdown.php
index f644080c7..746a2d048 100644
--- a/vendor/michelf/php-markdown/Michelf/Markdown.php
+++ b/vendor/michelf/php-markdown/Michelf/Markdown.php
@@ -4,7 +4,7 @@
*
* @package php-markdown
* @author Michel Fortin <michel.fortin@michelf.com>
- * @copyright 2004-2021 Michel Fortin <https://michelf.com/projects/php-markdown/>
+ * @copyright 2004-2022 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.9.1";
+ const MARKDOWNLIB_VERSION = "2.0.0";
/**
* Simple function interface - Initialize the parser and return the result
@@ -29,9 +29,9 @@ class Markdown implements MarkdownInterface {
* @param string $text
* @return string
*/
- public static function defaultTransform($text) {
+ public static function defaultTransform(string $text): string {
// Take parser class on which this function was called.
- $parser_class = \get_called_class();
+ $parser_class = static::class;
// Try to take parser from the static parser list
static $parser_list;
@@ -49,39 +49,34 @@ class Markdown implements MarkdownInterface {
/**
* Configuration variables
*/
-
/**
* Change to ">" for HTML output.
- * @var string
*/
- public $empty_element_suffix = " />";
+ public string $empty_element_suffix = " />";
/**
* The width of indentation of the output markup
- * @var int
*/
- public $tab_width = 4;
+ public int $tab_width = 4;
/**
* Change to `true` to disallow markup or entities.
- * @var boolean
*/
- public $no_markup = false;
- public $no_entities = false;
+ public bool $no_markup = false;
+ public bool $no_entities = false;
/**
* Change to `true` to enable line breaks on \n without two trailling spaces
* @var boolean
*/
- public $hard_wrap = false;
+ public bool $hard_wrap = false;
/**
* Predefined URLs and titles for reference links and images.
- * @var array
*/
- public $predef_urls = array();
- public $predef_titles = array();
+ public array $predef_urls = array();
+ public array $predef_titles = array();
/**
* Optional filter function for URLs
@@ -121,32 +116,27 @@ class Markdown implements MarkdownInterface {
* <li>List item two</li>
* <li>List item three</li>
* </ol>
- *
- * @var bool
*/
- public $enhanced_ordered_list = false;
+ public bool $enhanced_ordered_list = false;
/**
* Parser implementation
*/
-
/**
* Regex to match balanced [brackets].
* Needed to insert a maximum bracked depth while converting to PHP.
- * @var int
*/
- protected $nested_brackets_depth = 6;
- protected $nested_brackets_re;
+ protected int $nested_brackets_depth = 6;
+ protected string $nested_brackets_re;
- protected $nested_url_parenthesis_depth = 4;
- protected $nested_url_parenthesis_re;
+ protected int $nested_url_parenthesis_depth = 4;
+ protected string $nested_url_parenthesis_re;
/**
* Table of hash values for escaped characters:
- * @var string
*/
- protected $escape_chars = '\`*_{}[]()>#+-.!';
- protected $escape_chars_re;
+ protected string $escape_chars = '\`*_{}[]()>#+-.!';
+ protected string $escape_chars_re;
/**
* Constructor function. Initialize appropriate member variables.
@@ -175,23 +165,20 @@ class Markdown implements MarkdownInterface {
/**
* Internal hashes used during transformation.
- * @var array
*/
- protected $urls = array();
- protected $titles = array();
- protected $html_hashes = array();
+ protected array $urls = array();
+ protected array $titles = array();
+ protected array $html_hashes = array();
/**
* Status flag to avoid invalid nesting.
- * @var boolean
*/
- protected $in_anchor = false;
+ protected bool $in_anchor = false;
/**
* Status flag to avoid invalid nesting.
- * @var boolean
*/
- protected $in_emphasis_processing = false;
+ protected bool $in_emphasis_processing = false;
/**
* Called before the transformation process starts to setup parser states.
@@ -226,7 +213,7 @@ class Markdown implements MarkdownInterface {
* @param string $text
* @return string
*/
- public function transform($text) {
+ public function transform(string $text): string {
$this->setup();
# Remove UTF-8 BOM and marker character in input, if present.
@@ -263,9 +250,8 @@ class Markdown implements MarkdownInterface {
/**
* Define the document gamut
- * @var array
*/
- protected $document_gamut = array(
+ protected array $document_gamut = array(
// Strip link definitions, store in hashes.
"stripLinkDefinitions" => 20,
"runBasicBlockGamut" => 30,
@@ -525,9 +511,8 @@ class Markdown implements MarkdownInterface {
/**
* Define the block gamut - these are all the transformations that form
* block-level tags like paragraphs, headers, and list items.
- * @var array
*/
- protected $block_gamut = array(
+ protected array $block_gamut = array(
"doHeaders" => 10,
"doHorizontalRules" => 20,
"doLists" => 40,
@@ -597,9 +582,8 @@ class Markdown implements MarkdownInterface {
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
- * @var array
*/
- protected $span_gamut = array(
+ protected array $span_gamut = array(
// Process character escapes, code spans, and inline HTML
// in one shot.
"parseSpan" => -30,
@@ -724,7 +708,7 @@ class Markdown implements MarkdownInterface {
/**
* Callback method to parse referenced anchors
- * @param string $matches
+ * @param array $matches
* @return string
*/
protected function _doAnchors_reference_callback($matches) {
@@ -763,7 +747,7 @@ class Markdown implements MarkdownInterface {
/**
* Callback method to parse inline anchors
- * @param string $matches
+ * @param array $matches
* @return string
*/
protected function _doAnchors_inline_callback($matches) {
@@ -781,7 +765,7 @@ class Markdown implements MarkdownInterface {
$url = $this->encodeURLAttribute($url);
$result = "<a href=\"$url\"";
- if (isset($title)) {
+ if ($title) {
$title = $this->encodeAttribute($title);
$result .= " title=\"$title\"";
}
@@ -1105,9 +1089,8 @@ class Markdown implements MarkdownInterface {
/**
* Nesting tracker for list levels
- * @var integer
*/
- protected $list_level = 0;
+ protected int $list_level = 0;
/**
* Process the contents of a single ordered or unordered list, splitting it
@@ -1248,7 +1231,7 @@ class Markdown implements MarkdownInterface {
* Define the emphasis operators with their regex matches
* @var array
*/
- protected $em_relist = array(
+ protected array $em_relist = array(
'' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?![\.,:;]?\s)',
'*' => '(?<![\s*])\*(?!\*)',
'_' => '(?<![\s_])_(?!_)',
@@ -1258,7 +1241,7 @@ class Markdown implements MarkdownInterface {
* Define the strong operators with their regex matches
* @var array
*/
- protected $strong_relist = array(
+ protected array $strong_relist = array(
'' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?![\.,:;]?\s)',
'**' => '(?<![\s*])\*\*(?!\*)',
'__' => '(?<![\s_])__(?!_)',
@@ -1268,7 +1251,7 @@ class Markdown implements MarkdownInterface {
* Define the emphasis + strong operators with their regex matches
* @var array
*/
- protected $em_strong_relist = array(
+ protected array $em_strong_relist = array(
'' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?![\.,:;]?\s)',
'***' => '(?<![\s*])\*\*\*(?!\*)',
'___' => '(?<![\s_])___(?!_)',
@@ -1276,9 +1259,8 @@ class Markdown implements MarkdownInterface {
/**
* Container for prepared regular expressions
- * @var array
*/
- protected $em_strong_prepared_relist;
+ protected ?array $em_strong_prepared_relist = null;
/**
* Prepare regular expressions for searching emphasis tokens in any
@@ -1826,7 +1808,7 @@ class Markdown implements MarkdownInterface {
/**
* String length function for detab. `_initDetab` will create a function to
* handle UTF-8 if the default function does not exist.
- * @var string
+ * can be a string or function
*/
protected $utf8_strlen = 'mb_strlen';
@@ -1883,9 +1865,7 @@ class Markdown implements MarkdownInterface {
return;
}
- $this->utf8_strlen = function($text) {
- return preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/', $text, $m);
- };
+ $this->utf8_strlen = fn($text) => preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/', $text, $m);
}
/**