Remove no longer needed parts of core class

This commit is contained in:
Aidan Woods 2019-01-20 02:44:20 +00:00
parent dbdbda52a8
commit 36cfb21908
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -65,73 +65,6 @@ final class Parsedown
return $this->linesElements(Lines::fromTextLines($text, 0));
}
#
# Setters
#
public function setBreaksEnabled($breaksEnabled)
{
$this->breaksEnabled = $breaksEnabled;
return $this;
}
protected $breaksEnabled;
public function setMarkupEscaped($markupEscaped)
{
$this->markupEscaped = $markupEscaped;
return $this;
}
protected $markupEscaped;
public function setUrlsLinked($urlsLinked)
{
$this->urlsLinked = $urlsLinked;
return $this;
}
protected $urlsLinked = true;
public function setSafeMode($safeMode)
{
$this->safeMode = (bool) $safeMode;
return $this;
}
protected $safeMode;
public function setStrictMode($strictMode)
{
$this->strictMode = (bool) $strictMode;
return $this;
}
protected $strictMode;
protected $safeLinksWhitelist = [
'http://',
'https://',
'ftp://',
'ftps://',
'mailto:',
'tel:',
'data:image/png;base64,',
'data:image/gif;base64,',
'data:image/jpeg;base64,',
'irc:',
'ircs:',
'git:',
'ssh:',
'news:',
'steam:',
];
#
# Lines
#
@ -425,183 +358,8 @@ final class Parsedown
if (! isset($Element['autobreak'])) {
$Element['autobreak'] = false;
}
}
return $Elements;
}
# ~
protected function unmarkedText($text)
{
$Inline = $this->inlineText($text);
return $this->element($Inline['element']);
}
#
# Handlers
#
protected function handle(array $Element)
{
if (isset($Element['handler'])) {
if (!isset($Element['nonNestables'])) {
$Element['nonNestables'] = [];
}
if (\is_string($Element['handler'])) {
$function = $Element['handler'];
$argument = $Element['text'];
unset($Element['text']);
$destination = 'rawHtml';
} else {
$function = $Element['handler']['function'];
$argument = $Element['handler']['argument'];
$destination = $Element['handler']['destination'];
}
$Element[$destination] = $this->{$function}($argument, $Element['nonNestables']);
if ($destination === 'handler') {
$Element = $this->handle($Element);
}
unset($Element['handler']);
}
return $Element;
}
protected function handleElementRecursive(array $Element)
{
return $this->elementApplyRecursive([$this, 'handle'], $Element);
}
protected function handleElementsRecursive(array $Elements)
{
return $this->elementsApplyRecursive([$this, 'handle'], $Elements);
}
protected function elementApplyRecursive($closure, array $Element)
{
$Element = \call_user_func($closure, $Element);
if (isset($Element['elements'])) {
$Element['elements'] = $this->elementsApplyRecursive($closure, $Element['elements']);
} elseif (isset($Element['element'])) {
$Element['element'] = $this->elementApplyRecursive($closure, $Element['element']);
}
return $Element;
}
protected function elementApplyRecursiveDepthFirst($closure, array $Element)
{
if (isset($Element['elements'])) {
$Element['elements'] = $this->elementsApplyRecursiveDepthFirst($closure, $Element['elements']);
} elseif (isset($Element['element'])) {
$Element['element'] = $this->elementsApplyRecursiveDepthFirst($closure, $Element['element']);
}
$Element = \call_user_func($closure, $Element);
return $Element;
}
protected function elementsApplyRecursive($closure, array $Elements)
{
foreach ($Elements as &$Element) {
$Element = $this->elementApplyRecursive($closure, $Element);
}
return $Elements;
}
protected function elementsApplyRecursiveDepthFirst($closure, array $Elements)
{
foreach ($Elements as &$Element) {
$Element = $this->elementApplyRecursiveDepthFirst($closure, $Element);
}
return $Elements;
}
protected function element(array $Element)
{
if ($this->safeMode) {
$Element = $this->sanitiseElement($Element);
}
# identity map if element has no handler
$Element = $this->handle($Element);
$hasName = isset($Element['name']);
$markup = '';
if ($hasName) {
$markup .= '<' . $Element['name'];
if (isset($Element['attributes'])) {
foreach ($Element['attributes'] as $name => $value) {
if ($value === null) {
continue;
}
$markup .= " $name=\"".self::escape($value).'"';
}
}
}
$permitRawHtml = false;
if (isset($Element['text'])) {
$text = $Element['text'];
}
// very strongly consider an alternative if you're writing an
// extension
elseif (isset($Element['rawHtml'])) {
$text = $Element['rawHtml'];
$allowRawHtmlInSafeMode = isset($Element['allowRawHtmlInSafeMode']) && $Element['allowRawHtmlInSafeMode'];
$permitRawHtml = !$this->safeMode || $allowRawHtmlInSafeMode;
}
$hasContent = isset($text) || isset($Element['element']) || isset($Element['elements']);
if ($hasContent) {
$markup .= $hasName ? '>' : '';
if (isset($Element['elements'])) {
$markup .= $this->elements($Element['elements']);
} elseif (isset($Element['element'])) {
$markup .= $this->element($Element['element']);
} else {
if (!$permitRawHtml) {
$markup .= self::escape($text, true);
} else {
$markup .= $text;
}
}
$markup .= $hasName ? '</' . $Element['name'] . '>' : '';
} elseif ($hasName) {
$markup .= ' />';
}
return $markup;
}
protected function elements(array $Elements)
{
$markup = '';
$autoBreak = true;
foreach ($Elements as $Element) {
if (empty($Element)) {
continue;
}
# the marker does not belong to an inline
$autoBreakNext = (
isset($Element['autobreak'])
@ -635,10 +393,6 @@ final class Parsedown
return $Elements;
}
#
# AST Convenience
#
/**
* Replace occurrences $regexp with $Elements in $text. Return an array of
* elements representing the replacement.
@ -755,41 +509,4 @@ final class Parsedown
return $instance;
}
private static $instances = [];
#
# Read-Only
protected $specialCharacters = [
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', '~'
];
protected $StrongRegex = [
'*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*+[*])+?)[*]{2}(?![*])/s',
'_' => '/^__((?:\\\\_|[^_]|_[^_]*+_)+?)__(?!_)/us',
];
protected $EmRegex = [
'*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
'_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
];
protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+';
protected $voidElements = [
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
];
protected $textLevelElements = [
'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont',
'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing',
'i', 'rp', 'del', 'code', 'strike', 'marquee',
'q', 'rt', 'ins', 'font', 'strong',
's', 'tt', 'kbd', 'mark',
'u', 'xm', 'sub', 'nobr',
'sup', 'ruby',
'var', 'span',
'wbr', 'time',
];
}