Update Parsedown to use Composer

This commit is contained in:
Floorb 2021-08-20 16:21:55 -04:00
parent e3d2f64d39
commit 2b67a19013
18 changed files with 1962 additions and 3361 deletions

View file

@ -14,6 +14,7 @@
"require": {
"scrivo/highlight.php": "v9.18.1.7",
"ext-pdo": "*",
"ext-openssl": "*"
"ext-openssl": "*",
"erusev/parsedown": "^1.7"
}
}

57
composer.lock generated
View file

@ -4,8 +4,58 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6150c75f4650b6bf4b3f2cb2cbce0bda",
"content-hash": "b4c459c6c247b3748e5ccb0910498fcf",
"packages": [
{
"name": "erusev/parsedown",
"version": "1.7.4",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"type": "library",
"autoload": {
"psr-0": {
"Parsedown": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "Parser for Markdown.",
"homepage": "http://parsedown.org",
"keywords": [
"markdown",
"parser"
],
"support": {
"issues": "https://github.com/erusev/parsedown/issues",
"source": "https://github.com/erusev/parsedown/tree/1.7.x"
},
"time": "2019-12-30T22:54:17+00:00"
},
{
"name": "scrivo/highlight.php",
"version": "v9.18.1.7",
@ -89,7 +139,10 @@
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform": {
"ext-pdo": "*",
"ext-openssl": "*"
},
"platform-dev": [],
"plugin-api-version": "2.1.0"
}

View file

@ -1,445 +0,0 @@
<?php
#
#
# Beam Parsedown
# https://github.com/ardissoebrata/beam-parsedown
#
# (c) Emanuil Rusev
# http://erusev.com
#
# (c) Ardi Soebrata
# https://mybeam.me
#
# For the full license information, view the LICENSE file that was distributed
# with this source code.
#
#
namespace ArdiSSoebrata\BeamParsedown;
use ParsedownExtra;
class BeamParsedown extends ParsedownExtra {
const version = '0.0.1';
protected $isUrlRegex = "/(https?|ftp)\:\/\//i";
protected $regexAttribute = '(?:([#.][\w-]+\s*)|([\w-]+=[\w-]+\s*))+';
function __construct() {
parent::__construct();
// @codeCoverageIgnoreStart
if (version_compare(parent::version, '0.8.1') < 0) {
throw new Exception('BeamParsedown requires a later version of ParsedownExtra');
}
// @codeCoverageIgnoreEnd
$this->InlineTypes['['][] = 'Icon';
$this->InlineTypes['['][] = 'Audio';
// Identify our blocks before definition list.
array_unshift($this->BlockTypes[':'], 'Alert');
array_unshift($this->BlockTypes[':'], 'Mermaid');
array_unshift($this->BlockTypes[':'], 'Chart');
// Identify our blocks before Reference.
array_unshift($this->BlockTypes['['], 'Youtube');
array_unshift($this->BlockTypes['['], 'Drawio');
}
// Base path.
protected $basePath = '';
public function setBasePath($url) {
$this->basePath = preg_replace('{/$}', '', $url) . '/';
return $this;
}
protected function inlineImage($excerpt) {
$image = parent::inlineImage($excerpt);
if (!isset($image)) {
return null;
}
// Add basePath if src is relative.
$src = $image['element']['attributes']['src'];
if (!preg_match($this->isUrlRegex, $src, $urlmatch)) {
$image['element']['attributes']['src'] = $this->basePath . $src;
}
return $image;
}
// Heading id & attributes.
protected function blockHeader($Line) {
$Block = parent::blockHeader($Line);
if (!isset($Block)) {
return null;
}
if (!isset($Block['element']['attributes']['id'])) {
$text = $Block['element']['text'];
$text = preg_replace('/(\[.+:.*\]\s)/', '', $text); // remove [tag: value]. Ex. [icon: fa fa-home].
$Block['element']['attributes']['id'] = $this->slugify($text);
}
return $Block;
}
protected function blockSetextHeader($Line, array $Block = null) {
$Block = parent::blockSetextHeader($Line, $Block);
if (isset($Block['element']) && !isset($Block['element']['attributes']['id'])) {
$text = $Block['element']['text'];
$text = preg_replace('/(\[.+:.*\]\s)/', '', $text); // remove [tag: value]. Ex. [icon: fa fa-home].
$Block['element']['attributes']['id'] = $this->slugify($text);
}
return $Block;
}
protected function parseAttributeData($attributeString) {
$Data = array();
$attributes = preg_split('/[ ]+/', $attributeString, -1, PREG_SPLIT_NO_EMPTY);
foreach ($attributes as $attribute) {
if ($attribute[0] === '#') {
$Data['id'] = substr($attribute, 1);
} elseif ($attribute[0] === '.') {
$classes [] = substr($attribute, 1);
} elseif (preg_match('/([\w-]+)=([\w-]+)/', $attribute, $match)) {
$Data[$match[1]] = $match[2];
}
}
if (isset($classes)) {
$Data['class'] = implode(' ', $classes);
}
return $Data;
}
public static function slugify($text) {
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
// Icon
protected function InlineIcon($excerpt) {
if (preg_match('/\[icon:(.+?)\]/', $excerpt['text'], $matches)) {
return array(
// How many characters to advance the Parsedown's
// cursor after being done processing this tag.
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'i',
'attributes' => array(
'class' => trim($matches[1]),
),
'rawHtml' => '',
),
);
}
}
// Audio
protected function InlineAudio($excerpt) {
if (preg_match('/\[audio:(.+?)\]/', $excerpt['text'], $matches)) {
// Add basePath if src is relative.
$src = trim($matches[1]);
if (!preg_match($this->isUrlRegex, $src, $urlmatch)) {
$src = $this->basePath . $src;
}
return array(
// How many characters to advance the Parsedown's
// cursor after being done processing this tag.
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'audio',
'attributes' => array(
'controls' => '',
'preload' => 'none',
),
'handler' => 'element',
'text' => array(
'name' => 'source',
'attributes' => array(
'src' => $src,
)
),
),
);
}
}
// Youtube
protected function BlockYoutube($excerpt) {
if (preg_match('/\[youtube:\s*https\:\/\/youtu\.be\/(.+?)\]/', $excerpt['text'], $matches)) {
$video_id = trim($matches[1]);
return array(
// How many characters to advance the Parsedown's
// cursor after being done processing this tag.
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'div',
'attributes' => array(
'class' => 'overflow-hidden relative h-0',
'style' => 'padding-bottom: 56.25%',
),
'handler' => 'element',
'text' => array(
'name' => 'iframe',
'attributes' => array(
'src' => 'https://www.youtube.com/embed/' . $video_id,
'frameborder' => '0',
'allow' => 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture',
'allowfullscreen' => '',
'class' => 'left-0 top-0 h-full w-full absolute',
),
'rawHtml' => '',
),
),
);
}
}
// Alerts
protected $alert_types = array(
'info' => array(
'container-class' => 'bg-indigo-100 rounded shadow-sm flex overflow-hidden',
'icon-bg-class' => 'bg-indigo-500 w-20 flex justify-center items-center',
'icon-class' => 'fa fa-info-circle fa-2x text-white',
),
'warning' => array(
'container-class' => 'bg-yellow-50 rounded shadow-sm flex overflow-hidden',
'icon-bg-class' => 'bg-yellow-300 w-20 flex justify-center items-center',
'icon-class' => 'fa fa-exclamation-triangle fa-2x',
)
);
protected function BlockAlert($line, $block) {
$types = implode('|', array_keys($this->alert_types));
if (preg_match('/^:::(' . $types . ')/', $line['text'], $matches)) {
$type = trim($matches[1]);
return array(
'char' => $line['text'][0],
'element' => array(
'name' => 'div',
'attributes' => array(
'class' => $this->alert_types[$type]['container-class'],
'role' => 'alert',
),
'handler' => 'elements',
'text' => array(
array(
'name' => 'div',
'attributes' => array(
'class' => $this->alert_types[$type]['icon-bg-class']
),
'handler' => 'element',
'text' => array(
'name' => 'i',
'attributes' => array(
'class' => $this->alert_types[$type]['icon-class'],
),
'rawHtml' => ''
),
),
array(
'name' => 'div',
'attributes' => array(
'class' => 'flex-1 px-4',
),
'handler' => 'lines',
'text' => array(),
)
),
),
);
}
}
protected function BlockAlertContinue($line, $block) {
if (isset($block['complete'])) {
return;
}
// A blank newline has occurred.
if (isset($block['interrupted'])) {
unset($block['interrupted']);
}
// Check for end of the block.
if (preg_match('/^:::/', $line['text'])) {
$block['complete'] = true;
return $block;
}
$block['element']['text'][1]['text'][] = $line['body'];
return $block;
}
protected function BlockAlertComplete($block) {
return $block;
}
// draw.io
protected function BlockDrawio($excerpt) {
if (preg_match('/\[drawio:\s*(.+?)\]/', $excerpt['text'], $matches)) {
$file = trim($matches[1]);
if (!preg_match($this->isUrlRegex, $file, $urlmatch)) {
$file = $this->basePath . $file;
}
return array(
// How many characters to advance the Parsedown's
// cursor after being done processing this tag.
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'div',
'handler' => 'elements',
'text' => array(
array(
'name' => 'div',
'attributes' => array(
'class' => 'mxgraph w-full border',
'data-mxgraph' => json_encode(array(
'highlight' => '#0000ff',
'target' => 'blank',
'nav' => true,
'resize' => true,
'toolbar' => 'zoom layers lightbox',
'url' => $file,
))
),
'rawHtml' => '',
),
array(
'name' => 'script',
'attributes' => array(
'type' => 'text/javascript',
'src' => 'https://viewer.diagrams.net/js/viewer-static.min.js'
),
'rawHtml' => '',
),
),
),
);
}
}
// Mermaid
protected function BlockMermaid($line, $block) {
if (preg_match('/^:::\s*mermaid/', $line['text'], $matches)) {
return array(
'char' => $line['text'][0],
'element' => array(
'name' => 'div',
'attributes' => array(
'class' => 'mermaid',
),
'rawHtml' => "\n",
),
);
}
}
protected function BlockMermaidContinue($line, $block) {
if (isset($block['complete'])) {
return;
}
// A blank newline has occurred.
if (isset($block['interrupted'])) {
unset($block['interrupted']);
}
// Check for end of the block.
if (preg_match('/^:::/', $line['text'])) {
$block['complete'] = true;
return $block;
}
$block['element']['rawHtml'] .= $line['body'] . "\n";
return $block;
}
protected function BlockMermaidComplete($block) {
return $block;
}
// Chart JS
protected function BlockChart($line, $block) {
if (preg_match('/^:::\s*chart/', $line['text'], $matches)) {
return array(
'char' => $line['text'][0],
'element' => array(
'name' => 'canvas',
'attributes' => array(
'class' => 'chartjs',
),
'rawHtml' => "\n",
),
);
}
}
protected function BlockChartContinue($line, $block) {
if (isset($block['complete'])) {
return;
}
// A blank newline has occurred.
if (isset($block['interrupted'])) {
unset($block['interrupted']);
}
// Check for end of the block.
if (preg_match('/^:::/', $line['text'])) {
$block['complete'] = true;
return $block;
}
$block['element']['rawHtml'] .= $line['body'] . "\n";
return $block;
}
protected function BlockChartComplete($block) {
return $block;
}
}

View file

@ -1,87 +0,0 @@
<?php
namespace ArdiSSoebrata\BeamParsedown;
use Illuminate\Support\ServiceProvider;
class BeamParsedownServiceProvider extends ServiceProvider {
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot() : void {
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', ':lc:vendor');
// $this->loadViewsFrom(__DIR__.'/../resources/views', ':lc:vendor');
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
// $this->loadRoutesFrom(__DIR__.'/routes.php');
// Publishing is only necessary when using the CLI.
if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
}
/**
* Register any package services.
*
* @return void
*/
public function register() : void {
$this->mergeConfigFrom(__DIR__ . '/../config/beam-parsedown.php', 'beam-parsedown');
// Register the service the package provides.
$this->app->singleton('beam-parsedown', function ($app) {
$parse = new BeamParsedown();
// Set from config.
$parse->setBreaksEnabled(config('beam-parsedown.breaks_enabled', false));
$parse->setMarkupEscaped(config('beam-parsedown.markup_escaped', false));
$parse->setUrlsLinked(config('beam-parsedown.urls_linked', true));
$parse->setSafeMode(config('beam-parsedown.safe_mode', false));
return $parse;
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides() {
// @codeCoverageIgnoreStart
return ['beam-parsedown'];
// @codeCoverageIgnoreEnd
}
/**
* Console-specific booting.
*
* @return void
*/
protected function bootForConsole() : void {
// Publishing the configuration file.
$this->publishes([
__DIR__ . '/../config/beam-parsedown.php' => config_path('beam-parsedown.php'),
], 'beam-parsedown.config');
// Publishing the views.
/*$this->publishes([
__DIR__.'/../resources/views' => base_path('resources/views/vendor/:lc:vendor'),
], 'beam-parsedown.views');*/
// Publishing assets.
/*$this->publishes([
__DIR__.'/../resources/assets' => public_path('vendor/:lc:vendor'),
], 'beam-parsedown.views');*/
// Publishing the translation files.
/*$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/:lc:vendor'),
], 'beam-parsedown.views');*/
// Registering package commands.
// $this->commands([]);
}
}

View file

@ -1,16 +0,0 @@
<?php
namespace ArdiSSoebrata\BeamParsedown\Facades;
use Illuminate\Support\Facades\Facade;
class BeamParsedown extends Facade {
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() : string {
return 'beam-parsedown';
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,606 +0,0 @@
<?php
#
#
# Parsedown Extra
# https://github.com/erusev/parsedown-extra
#
# (c) Emanuil Rusev
# http://erusev.com
#
# For the full license information, view the LICENSE file that was distributed
# with this source code.
#
#
class ParsedownExtra extends Parsedown {
# ~
const version = '0.8.0';
# ~
function __construct() {
if (version_compare(parent::version, '1.7.1') < 0) {
throw new Exception('ParsedownExtra requires a later version of Parsedown');
}
$this->BlockTypes[':'] [] = 'DefinitionList';
$this->BlockTypes['*'] [] = 'Abbreviation';
# identify footnote definitions before reference definitions
array_unshift($this->BlockTypes['['], 'Footnote');
# identify footnote markers before before links
array_unshift($this->InlineTypes['['], 'FootnoteMarker');
}
#
# ~
function text($text) {
$Elements = $this->textElements($text);
# convert to markup
$markup = $this->elements($Elements);
# trim line breaks
$markup = trim($markup, "\n");
# merge consecutive dl elements
$markup = preg_replace('/<\/dl>\s+<dl>\s+/', '', $markup);
# add footnotes
if (isset($this->DefinitionData['Footnote'])) {
$Element = $this->buildFootnoteElement();
$markup .= "\n" . $this->element($Element);
}
return $markup;
}
#
# Blocks
#
#
# Abbreviation
protected function blockAbbreviation($Line) {
if (preg_match('/^\*\[(.+?)\]:[ ]*(.+?)[ ]*$/', $Line['text'], $matches)) {
$this->DefinitionData['Abbreviation'][$matches[1]] = $matches[2];
$Block = array(
'hidden' => true,
);
return $Block;
}
}
#
# Footnote
protected function blockFootnote($Line) {
if (preg_match('/^\[\^(.+?)\]:[ ]?(.*)$/', $Line['text'], $matches)) {
$Block = array(
'label' => $matches[1],
'text' => $matches[2],
'hidden' => true,
);
return $Block;
}
}
protected function blockFootnoteContinue($Line, $Block) {
if ($Line['text'][0] === '[' and preg_match('/^\[\^(.+?)\]:/', $Line['text'])) {
return;
}
if (isset($Block['interrupted'])) {
if ($Line['indent'] >= 4) {
$Block['text'] .= "\n\n" . $Line['text'];
return $Block;
}
} else {
$Block['text'] .= "\n" . $Line['text'];
return $Block;
}
}
protected function blockFootnoteComplete($Block) {
$this->DefinitionData['Footnote'][$Block['label']] = array(
'text' => $Block['text'],
'count' => null,
'number' => null,
);
return $Block;
}
#
# Definition List
protected function blockDefinitionList($Line, $Block) {
if (!isset($Block) or $Block['type'] !== 'Paragraph') {
return;
}
$Element = array(
'name' => 'dl',
'elements' => array(),
);
$terms = explode("\n", $Block['element']['handler']['argument']);
foreach ($terms as $term) {
$Element['elements'] [] = array(
'name' => 'dt',
'handler' => array(
'function' => 'lineElements',
'argument' => $term,
'destination' => 'elements'
),
);
}
$Block['element'] = $Element;
$Block = $this->addDdElement($Line, $Block);
return $Block;
}
protected function blockDefinitionListContinue($Line, array $Block) {
if ($Line['text'][0] === ':') {
$Block = $this->addDdElement($Line, $Block);
return $Block;
} else {
if (isset($Block['interrupted']) and $Line['indent'] === 0) {
return;
}
if (isset($Block['interrupted'])) {
$Block['dd']['handler']['function'] = 'textElements';
$Block['dd']['handler']['argument'] .= "\n\n";
$Block['dd']['handler']['destination'] = 'elements';
unset($Block['interrupted']);
}
$text = substr($Line['body'], min($Line['indent'], 4));
$Block['dd']['handler']['argument'] .= "\n" . $text;
return $Block;
}
}
#
# Header
protected function blockHeader($Line) {
$Block = parent::blockHeader($Line);
if ($Block !== null && preg_match('/[ #]*{(' . $this->regexAttribute . '+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE)) {
$attributeString = $matches[1][0];
$Block['element']['attributes'] = $this->parseAttributeData($attributeString);
$Block['element']['handler']['argument'] = substr($Block['element']['handler']['argument'], 0, $matches[0][1]);
}
return $Block;
}
#
# Markup
protected function blockMarkup($Line) {
if ($this->markupEscaped or $this->safeMode) {
return;
}
if (preg_match('/^<(\w[\w-]*)(?:[ ]*' . $this->regexHtmlAttribute . ')*[ ]*(\/)?>/', $Line['text'], $matches)) {
$element = strtolower($matches[1]);
if (in_array($element, $this->textLevelElements)) {
return;
}
$Block = array(
'name' => $matches[1],
'depth' => 0,
'element' => array(
'rawHtml' => $Line['text'],
'autobreak' => true,
),
);
$length = strlen($matches[0]);
$remainder = substr($Line['text'], $length);
if (trim($remainder) === '') {
if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) {
$Block['closed'] = true;
$Block['void'] = true;
}
} else {
if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) {
return;
}
if (preg_match('/<\/' . $matches[1] . '>[ ]*$/i', $remainder)) {
$Block['closed'] = true;
}
}
return $Block;
}
}
protected function blockMarkupContinue($Line, array $Block) {
if (isset($Block['closed'])) {
return;
}
if (preg_match('/^<' . $Block['name'] . '(?:[ ]*' . $this->regexHtmlAttribute . ')*[ ]*>/i', $Line['text'])) # open
{
$Block['depth']++;
}
if (preg_match('/(.*?)<\/' . $Block['name'] . '>[ ]*$/i', $Line['text'], $matches)) # close
{
if ($Block['depth'] > 0) {
$Block['depth']--;
} else {
$Block['closed'] = true;
}
}
if (isset($Block['interrupted'])) {
$Block['element']['rawHtml'] .= "\n";
unset($Block['interrupted']);
}
$Block['element']['rawHtml'] .= "\n" . $Line['body'];
return $Block;
}
protected function blockMarkupComplete($Block) {
if (!isset($Block['void'])) {
$Block['element']['rawHtml'] = $this->processTag($Block['element']['rawHtml']);
}
return $Block;
}
#
# Setext
protected function blockSetextHeader($Line, array $Block = null) {
$Block = parent::blockSetextHeader($Line, $Block);
if ($Block !== null && preg_match('/[ ]*{(' . $this->regexAttribute . '+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE)) {
$attributeString = $matches[1][0];
$Block['element']['attributes'] = $this->parseAttributeData($attributeString);
$Block['element']['handler']['argument'] = substr($Block['element']['handler']['argument'], 0, $matches[0][1]);
}
return $Block;
}
#
# Inline Elements
#
#
# Footnote Marker
protected function inlineFootnoteMarker($Excerpt) {
if (preg_match('/^\[\^(.+?)\]/', $Excerpt['text'], $matches)) {
$name = $matches[1];
if (!isset($this->DefinitionData['Footnote'][$name])) {
return;
}
$this->DefinitionData['Footnote'][$name]['count']++;
if (!isset($this->DefinitionData['Footnote'][$name]['number'])) {
$this->DefinitionData['Footnote'][$name]['number'] = ++$this->footnoteCount; # » &
}
$Element = array(
'name' => 'sup',
'attributes' => array('id' => 'fnref' . $this->DefinitionData['Footnote'][$name]['count'] . ':' . $name),
'element' => array(
'name' => 'a',
'attributes' => array('href' => '#fn:' . $name, 'class' => 'footnote-ref'),
'text' => $this->DefinitionData['Footnote'][$name]['number'],
),
);
return array(
'extent' => strlen($matches[0]),
'element' => $Element,
);
}
}
private $footnoteCount = 0;
#
# Link
protected function inlineLink($Excerpt) {
$Link = parent::inlineLink($Excerpt);
$remainder = $Link !== null ? substr($Excerpt['text'], $Link['extent']) : '';
if (preg_match('/^[ ]*{(' . $this->regexAttribute . '+)}/', $remainder, $matches)) {
$Link['element']['attributes'] += $this->parseAttributeData($matches[1]);
$Link['extent'] += strlen($matches[0]);
}
return $Link;
}
#
# ~
#
private $currentAbreviation;
private $currentMeaning;
protected function insertAbreviation(array $Element) {
if (isset($Element['text'])) {
$Element['elements'] = self::pregReplaceElements(
'/\b' . preg_quote($this->currentAbreviation, '/') . '\b/',
array(
array(
'name' => 'abbr',
'attributes' => array(
'title' => $this->currentMeaning,
),
'text' => $this->currentAbreviation,
)
),
$Element['text']
);
unset($Element['text']);
}
return $Element;
}
protected function inlineText($text) {
$Inline = parent::inlineText($text);
if (isset($this->DefinitionData['Abbreviation'])) {
foreach ($this->DefinitionData['Abbreviation'] as $abbreviation => $meaning) {
$this->currentAbreviation = $abbreviation;
$this->currentMeaning = $meaning;
$Inline['element'] = $this->elementApplyRecursiveDepthFirst(
array($this, 'insertAbreviation'),
$Inline['element']
);
}
}
return $Inline;
}
#
# Util Methods
#
protected function addDdElement(array $Line, array $Block) {
$text = substr($Line['text'], 1);
$text = trim($text);
unset($Block['dd']);
$Block['dd'] = array(
'name' => 'dd',
'handler' => array(
'function' => 'lineElements',
'argument' => $text,
'destination' => 'elements'
),
);
if (isset($Block['interrupted'])) {
$Block['dd']['handler']['function'] = 'textElements';
unset($Block['interrupted']);
}
$Block['element']['elements'] [] = &$Block['dd'];
return $Block;
}
protected function buildFootnoteElement() {
$Element = array(
'name' => 'div',
'attributes' => array('class' => 'footnotes'),
'elements' => array(
array('name' => 'hr'),
array(
'name' => 'ol',
'elements' => array(),
),
),
);
uasort($this->DefinitionData['Footnote'], 'self::sortFootnotes');
foreach ($this->DefinitionData['Footnote'] as $definitionId => $DefinitionData) {
if (!isset($DefinitionData['number'])) {
continue;
}
$text = $DefinitionData['text'];
$textElements = parent::textElements($text);
$numbers = range(1, $DefinitionData['count']);
$backLinkElements = array();
foreach ($numbers as $number) {
$backLinkElements[] = array('text' => ' ');
$backLinkElements[] = array(
'name' => 'a',
'attributes' => array(
'href' => "#fnref$number:$definitionId",
'rev' => 'footnote',
'class' => 'footnote-backref',
),
'rawHtml' => '&#8617;',
'allowRawHtmlInSafeMode' => true,
'autobreak' => false,
);
}
unset($backLinkElements[0]);
$n = count($textElements) - 1;
if ($textElements[$n]['name'] === 'p') {
$backLinkElements = array_merge(
array(
array(
'rawHtml' => '&#160;',
'allowRawHtmlInSafeMode' => true,
),
),
$backLinkElements
);
unset($textElements[$n]['name']);
$textElements[$n] = array(
'name' => 'p',
'elements' => array_merge(
array($textElements[$n]),
$backLinkElements
),
);
} else {
$textElements[] = array(
'name' => 'p',
'elements' => $backLinkElements
);
}
$Element['elements'][1]['elements'] [] = array(
'name' => 'li',
'attributes' => array('id' => 'fn:' . $definitionId),
'elements' => array_merge(
$textElements
),
);
}
return $Element;
}
# ~
protected function parseAttributeData($attributeString) {
$Data = array();
$attributes = preg_split('/[ ]+/', $attributeString, -1, PREG_SPLIT_NO_EMPTY);
foreach ($attributes as $attribute) {
if ($attribute[0] === '#') {
$Data['id'] = substr($attribute, 1);
} else # "."
{
$classes [] = substr($attribute, 1);
}
}
if (isset($classes)) {
$Data['class'] = implode(' ', $classes);
}
return $Data;
}
# ~
protected function processTag($elementMarkup) # recursive
{
# http://stackoverflow.com/q/1148928/200145
libxml_use_internal_errors(true);
$DOMDocument = new DOMDocument;
# http://stackoverflow.com/q/11309194/200145
$elementMarkup = mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8');
# http://stackoverflow.com/q/4879946/200145
$DOMDocument->loadHTML($elementMarkup);
$DOMDocument->removeChild($DOMDocument->doctype);
$DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);
$elementText = '';
if ($DOMDocument->documentElement->getAttribute('markdown') === '1') {
foreach ($DOMDocument->documentElement->childNodes as $Node) {
$elementText .= $DOMDocument->saveHTML($Node);
}
$DOMDocument->documentElement->removeAttribute('markdown');
$elementText = "\n" . $this->text($elementText) . "\n";
} else {
foreach ($DOMDocument->documentElement->childNodes as $Node) {
$nodeMarkup = $DOMDocument->saveHTML($Node);
if ($Node instanceof DOMElement and !in_array($Node->nodeName, $this->textLevelElements)) {
$elementText .= $this->processTag($nodeMarkup);
} else {
$elementText .= $nodeMarkup;
}
}
}
# because we don't want for markup to get encoded
$DOMDocument->documentElement->nodeValue = 'placeholder\x1A';
$markup = $DOMDocument->saveHTML($DOMDocument->documentElement);
$markup = str_replace('placeholder\x1A', $elementText, $markup);
return $markup;
}
# ~
protected function sortFootnotes($A, $B) # callback
{
return $A['number'] - $B['number'];
}
#
# Fields
#
protected $regexAttribute = '(?:[#.][-\w]+[ ]*)';
}

View file

@ -1,338 +0,0 @@
<?php
namespace Aidantwoods\SecureParsedown;
class SecureParsedown extends \Parsedown {
const version = '1.0.1';
function setSafeMode($safeMode) {
$this->safeMode = (bool)$safeMode;
return $this;
}
protected $safeMode;
protected $safeLinksWhitelist = array(
'http://',
'https://',
'ftp://',
'ftps://',
'mailto:',
'data:image/png;base64,',
'data:image/gif;base64,',
'data:image/jpeg;base64,',
'irc:',
'ircs:',
'git:',
'ssh:',
'news:',
'steam:',
);
protected function blockCodeComplete($Block) {
$text = $Block['element']['text']['text'];
$Block['element']['text']['text'] = $text;
return $Block;
}
protected function blockComment($Line) {
if ($this->markupEscaped or $this->safeMode) {
return;
}
if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!') {
$Block = array(
'markup' => $Line['body'],
);
if (preg_match('/-->$/', $Line['text'])) {
$Block['closed'] = true;
}
return $Block;
}
}
protected function blockFencedCodeComplete($Block) {
$text = $Block['element']['text']['text'];
$Block['element']['text']['text'] = $text;
return $Block;
}
protected function blockMarkup($Line) {
if ($this->markupEscaped or $this->safeMode) {
return;
}
if (preg_match('/^<(\w*)(?:[ ]*' . $this->regexHtmlAttribute . ')*[ ]*(\/)?>/', $Line['text'], $matches)) {
$element = strtolower($matches[1]);
if (in_array($element, $this->textLevelElements)) {
return;
}
$Block = array(
'name' => $matches[1],
'depth' => 0,
'markup' => $Line['text'],
);
$length = strlen($matches[0]);
$remainder = substr($Line['text'], $length);
if (trim($remainder) === '') {
if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) {
$Block['closed'] = true;
$Block['void'] = true;
}
} else {
if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) {
return;
}
if (preg_match('/<\/' . $matches[1] . '>[ ]*$/i', $remainder)) {
$Block['closed'] = true;
}
}
return $Block;
}
}
protected function inlineCode($Excerpt) {
$marker = $Excerpt['text'][0];
if (preg_match('/^(' . $marker . '+)[ ]*(.+?)[ ]*(?<!' . $marker . ')\1(?!' . $marker . ')/s', $Excerpt['text'], $matches)) {
$text = $matches[2];
$text = preg_replace("/[ ]*\n/", ' ', $text);
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'code',
'text' => $text,
),
);
}
}
protected function inlineLink($Excerpt) {
$Element = array(
'name' => 'a',
'handler' => 'line',
'text' => null,
'attributes' => array(
'href' => null,
'title' => null,
),
);
$extent = 0;
$remainder = $Excerpt['text'];
if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) {
$Element['text'] = $matches[1];
$extent += strlen($matches[0]);
$remainder = substr($remainder, $extent);
} else {
return;
}
if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) {
$Element['attributes']['href'] = $matches[1];
if (isset($matches[2])) {
$Element['attributes']['title'] = substr($matches[2], 1, -1);
}
$extent += strlen($matches[0]);
} else {
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) {
$definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
$definition = strtolower($definition);
$extent += strlen($matches[0]);
} else {
$definition = strtolower($Element['text']);
}
if (!isset($this->DefinitionData['Reference'][$definition])) {
return;
}
$Definition = $this->DefinitionData['Reference'][$definition];
$Element['attributes']['href'] = $Definition['url'];
$Element['attributes']['title'] = $Definition['title'];
}
return array(
'extent' => $extent,
'element' => $Element,
);
}
protected function inlineMarkup($Excerpt) {
if ($this->markupEscaped or $this->safeMode or strpos($Excerpt['text'], '>') === false) {
return;
}
if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches)) {
return array(
'markup' => $matches[0],
'extent' => strlen($matches[0]),
);
}
if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches)) {
return array(
'markup' => $matches[0],
'extent' => strlen($matches[0]),
);
}
if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*' . $this->regexHtmlAttribute . ')*[ ]*\/?>/s', $Excerpt['text'], $matches)) {
return array(
'markup' => $matches[0],
'extent' => strlen($matches[0]),
);
}
}
protected function inlineUrl($Excerpt) {
if ($this->urlsLinked !== true or !isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') {
return;
}
if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) {
$url = $matches[0][0];
$Inline = array(
'extent' => strlen($matches[0][0]),
'position' => $matches[0][1],
'element' => array(
'name' => 'a',
'text' => $url,
'attributes' => array(
'href' => $url,
),
),
);
return $Inline;
}
}
protected function inlineUrlTag($Excerpt) {
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) {
$url = $matches[1];
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'a',
'text' => $url,
'attributes' => array(
'href' => $url,
),
),
);
}
}
protected function element(array $Element) {
if ($this->safeMode) {
$Element = $this->sanitiseElement($Element);
}
$markup = '<' . $Element['name'];
if (isset($Element['attributes'])) {
foreach ($Element['attributes'] as $name => $value) {
if ($value === null) {
continue;
}
$markup .= ' ' . $name . '="' . self::escape($value) . '"';
}
}
if (isset($Element['text'])) {
$markup .= '>';
if (isset($Element['handler'])) {
$markup .= $this->{$Element['handler']}($Element['text']);
} else {
$markup .= self::escape($Element['text'], true);
}
$markup .= '</' . $Element['name'] . '>';
} else {
$markup .= ' />';
}
return $markup;
}
protected function sanitiseElement(array $Element) {
static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/';
static $safeUrlNameToAtt = array(
'a' => 'href',
'img' => 'src',
);
if (isset($safeUrlNameToAtt[$Element['name']])) {
$Element = $this->filterUnsafeUrlInAttribute($Element, $safeUrlNameToAtt[$Element['name']]);
}
if (!empty($Element['attributes'])) {
foreach ($Element['attributes'] as $att => $val) {
# filter out badly parsed attribute
if (!preg_match($goodAttribute, $att)) {
unset($Element['attributes'][$att]);
} # dump onevent attribute
elseif (self::striAtStart($att, 'on')) {
unset($Element['attributes'][$att]);
}
}
}
return $Element;
}
protected function filterUnsafeUrlInAttribute(array $Element, $attribute) {
foreach ($this->safeLinksWhitelist as $scheme) {
if (self::striAtStart($Element['attributes'][$attribute], $scheme)) {
return $Element;
}
}
$Element['attributes'][$attribute] = str_replace(':', '%3A', $Element['attributes'][$attribute]);
return $Element;
}
protected static function escape($text, $allowQuotes = false) {
return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8');
}
protected static function striAtStart($string, $needle) {
$len = strlen($needle);
if ($len > strlen($string)) {
return false;
} else {
return strtolower(substr($string, 0, $len)) === strtolower($needle);
}
}
}

View file

@ -1 +0,0 @@
Directory listing not allowed.

View file

@ -24,11 +24,6 @@ require_once('includes/functions.php');
require_once('includes/Tag.class.php');
require_once('includes/passwords.php');
require_once('includes/Parsedown/Parsedown.php');
require_once('includes/Parsedown/ParsedownExtra.php');
require_once('includes/Parsedown/SecureParsedown.php');
use Highlight\Highlighter;
function rawView($content, $p_code) {

View file

@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Parsedown' => array($vendorDir . '/erusev/parsedown'),
'Highlight\\' => array($vendorDir . '/scrivo/highlight.php'),
'HighlightUtilities\\' => array($vendorDir . '/scrivo/highlight.php'),
);

View file

@ -11,6 +11,13 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
);
public static $prefixesPsr0 = array (
'P' =>
array (
'Parsedown' =>
array (
0 => __DIR__ . '/..' . '/erusev/parsedown',
),
),
'H' =>
array (
'Highlight\\' =>

View file

@ -1,5 +1,58 @@
{
"packages": [
{
"name": "erusev/parsedown",
"version": "1.7.4",
"version_normalized": "1.7.4.0",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"time": "2019-12-30T22:54:17+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Parsedown": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"description": "Parser for Markdown.",
"homepage": "http://parsedown.org",
"keywords": [
"markdown",
"parser"
],
"support": {
"issues": "https://github.com/erusev/parsedown/issues",
"source": "https://github.com/erusev/parsedown/tree/1.7.x"
},
"install-path": "../erusev/parsedown"
},
{
"name": "scrivo/highlight.php",
"version": "v9.18.1.7",

View file

@ -5,7 +5,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '09e804a3b96f0f28a23da3d250e161f7c9dfb5a3',
'reference' => 'b39634998fff5e87ee8838d349a11ca2a315aec7',
'name' => 'aftercase/ponepaste',
'dev' => true,
),
@ -16,7 +16,16 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '09e804a3b96f0f28a23da3d250e161f7c9dfb5a3',
'reference' => 'b39634998fff5e87ee8838d349a11ca2a315aec7',
'dev_requirement' => false,
),
'erusev/parsedown' => array(
'pretty_version' => '1.7.4',
'version' => '1.7.4.0',
'type' => 'library',
'install_path' => __DIR__ . '/../erusev/parsedown',
'aliases' => array(),
'reference' => 'cb17b6477dfff935958ba01325f2e8a2bfa6dab3',
'dev_requirement' => false,
),
'scrivo/highlight.php' => array(

View file

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2013 Emanuil Rusev, erusev.com
Copyright (c) 2013-2018 Emanuil Rusev, erusev.com
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

1712
vendor/erusev/parsedown/Parsedown.php vendored Normal file

File diff suppressed because it is too large Load diff

86
vendor/erusev/parsedown/README.md vendored Normal file
View file

@ -0,0 +1,86 @@
> I also make [Caret](https://caret.io?ref=parsedown) - a Markdown editor for Mac and PC.
## Parsedown
[![Build Status](https://img.shields.io/travis/erusev/parsedown/master.svg?style=flat-square)](https://travis-ci.org/erusev/parsedown)
<!--[![Total Downloads](http://img.shields.io/packagist/dt/erusev/parsedown.svg?style=flat-square)](https://packagist.org/packages/erusev/parsedown)-->
Better Markdown Parser in PHP
[Demo](http://parsedown.org/demo) |
[Benchmarks](http://parsedown.org/speed) |
[Tests](http://parsedown.org/tests/) |
[Documentation](https://github.com/erusev/parsedown/wiki/)
### Features
* One File
* No Dependencies
* Super Fast
* Extensible
* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
* Tested in 5.3 to 7.1 and in HHVM
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra)
### Installation
Include `Parsedown.php` or install [the composer package](https://packagist.org/packages/erusev/parsedown).
### Example
``` php
$Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>
```
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
### Security
Parsedown is capable of escaping user-input within the HTML that it generates. Additionally Parsedown will apply sanitisation to additional scripting vectors (such as scripting link destinations) that are introduced by the markdown syntax itself.
To tell Parsedown that it is processing untrusted user-input, use the following:
```php
$parsedown = new Parsedown;
$parsedown->setSafeMode(true);
```
If instead, you wish to allow HTML within untrusted user-input, but still want output to be free from XSS it is recommended that you make use of a HTML sanitiser that allows HTML tags to be whitelisted, like [HTML Purifier](http://htmlpurifier.org/).
In both cases you should strongly consider employing defence-in-depth measures, like [deploying a Content-Security-Policy](https://scotthelme.co.uk/content-security-policy-an-introduction/) (a browser security feature) so that your page is likely to be safe even if an attacker finds a vulnerability in one of the first lines of defence above.
#### Security of Parsedown Extensions
Safe mode does not necessarily yield safe results when using extensions to Parsedown. Extensions should be evaluated on their own to determine their specific safety against XSS.
### Escaping HTML
> ⚠️  **WARNING:** This method isn't safe from XSS!
If you wish to escape HTML **in trusted input**, you can use the following:
```php
$parsedown = new Parsedown;
$parsedown->setMarkupEscaped(true);
```
Beware that this still allows users to insert unsafe scripting vectors, such as links like `[xss](javascript:alert%281%29)`.
### Questions
**How does Parsedown work?**
It tries to read Markdown like a human. First, it looks at the lines. Its interested in how the lines start. This helps it recognise blocks. It knows, for example, that if a line starts with a `-` then perhaps it belongs to a list. Once it recognises the blocks, it continues to the content. As it reads, it watches out for special characters. This helps it recognise inline elements (or inlines).
We call this approach "line based". We believe that Parsedown is the first Markdown parser to use it. Since the release of Parsedown, other developers have used the same approach to develop other Markdown parsers in PHP and in other languages.
**Is it compliant with CommonMark?**
It passes most of the CommonMark tests. Most of the tests that don't pass deal with cases that are quite uncommon. Still, as CommonMark matures, compliance should improve.
**Who uses it?**
[Laravel Framework](https://laravel.com/), [Bolt CMS](http://bolt.cm/), [Grav CMS](http://getgrav.org/), [Herbie CMS](http://www.getherbie.org/), [Kirby CMS](http://getkirby.com/), [October CMS](http://octobercms.com/), [Pico CMS](http://picocms.org), [Statamic CMS](http://www.statamic.com/), [phpDocumentor](http://www.phpdoc.org/), [RaspberryPi.org](http://www.raspberrypi.org/), [Symfony demo](https://github.com/symfony/symfony-demo) and [more](https://packagist.org/packages/erusev/parsedown/dependents).
**How can I help?**
Use it, star it, share it and if you feel generous, [donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=528P3NZQMP8N2).

33
vendor/erusev/parsedown/composer.json vendored Normal file
View file

@ -0,0 +1,33 @@
{
"name": "erusev/parsedown",
"description": "Parser for Markdown.",
"keywords": ["markdown", "parser"],
"homepage": "http://parsedown.org",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Emanuil Rusev",
"email": "hello@erusev.com",
"homepage": "http://erusev.com"
}
],
"require": {
"php": ">=5.3.0",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"autoload": {
"psr-0": {"Parsedown": ""}
},
"autoload-dev": {
"psr-0": {
"TestParsedown": "test/",
"ParsedownTest": "test/",
"CommonMarkTest": "test/",
"CommonMarkTestWeak": "test/"
}
}
}