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

Typed Properties #359

Merged
merged 4 commits into from
Nov 7, 2021
Merged
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
70 changes: 25 additions & 45 deletions Michelf/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Markdown implements MarkdownInterface {
*/
public static function defaultTransform($text) {
// 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;
Expand All @@ -49,25 +49,21 @@ public static function defaultTransform($text) {
/**
* 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;


/**
Expand All @@ -78,10 +74,9 @@ public static function defaultTransform($text) {

/**
* 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
Expand Down Expand Up @@ -121,32 +116,27 @@ public static function defaultTransform($text) {
* <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 int $nested_brackets_depth = 6;
protected $nested_brackets_re;

protected $nested_url_parenthesis_depth = 4;
protected int $nested_url_parenthesis_depth = 4;
protected $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.
Expand Down Expand Up @@ -175,23 +165,20 @@ public function __construct() {

/**
* Internal hashes used during transformation.
* @var array
*/
protected $urls = array();
protected array $urls = array();
protected $titles = array();
protected $html_hashes = 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.
Expand Down Expand Up @@ -263,9 +250,8 @@ public function transform($text) {

/**
* 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,
Expand Down Expand Up @@ -525,9 +511,8 @@ protected function hashBlock($text) {
/**
* 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,
Expand Down Expand Up @@ -597,9 +582,8 @@ protected function doHorizontalRules($text) {
/**
* 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,
Expand Down Expand Up @@ -1105,9 +1089,8 @@ protected function _doLists_callback($matches) {

/**
* 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
Expand Down Expand Up @@ -1248,7 +1231,7 @@ protected function makeCodeSpan($code) {
* Define the emphasis operators with their regex matches
* @var array
*/
protected $em_relist = array(
protected array $em_relist = array(
'' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?![\.,:;]?\s)',
'*' => '(?<![\s*])\*(?!\*)',
'_' => '(?<![\s_])_(?!_)',
Expand All @@ -1258,7 +1241,7 @@ protected function makeCodeSpan($code) {
* Define the strong operators with their regex matches
* @var array
*/
protected $strong_relist = array(
protected array $strong_relist = array(
'' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?![\.,:;]?\s)',
'**' => '(?<![\s*])\*\*(?!\*)',
'__' => '(?<![\s_])__(?!_)',
Expand All @@ -1268,17 +1251,16 @@ protected function makeCodeSpan($code) {
* 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_])___(?!_)',
);

/**
* 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
Expand Down Expand Up @@ -1883,9 +1865,7 @@ protected function _initDetab() {
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);
}

/**
Expand Down
Loading