mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-26 03:08:41 +00:00
fix(web): ParsedownMath
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bd5babfa29
commit
86d4b13cd6
@ -3,12 +3,11 @@
|
|||||||
"gregwar/captcha": "^1.1",
|
"gregwar/captcha": "^1.1",
|
||||||
"phpmailer/phpmailer": "^6.6",
|
"phpmailer/phpmailer": "^6.6",
|
||||||
"ezyang/htmlpurifier": "^4.16",
|
"ezyang/htmlpurifier": "^4.16",
|
||||||
"erusev/parsedown": "^1.7",
|
"erusev/parsedown": "^1.7"
|
||||||
"benjaminhoegh/parsedown-math": "dev-master"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"vendor/benjaminhoegh/parsedown-math/ParsedownMath.php"
|
"vendor/parsedown-math/ParsedownMath.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
|
1
web/app/vendor/benjaminhoegh/parsedown-math
vendored
1
web/app/vendor/benjaminhoegh/parsedown-math
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 668b11b80c7d1dc9812274405426cb62bbb4d78b
|
|
@ -6,6 +6,5 @@ $vendorDir = dirname(dirname(__FILE__));
|
|||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'DynamicParent' => $vendorDir . '/benjaminhoegh/parsedown-math/ParsedownMath.php',
|
'ParsedownMath' => $vendorDir . '/parsedown-math/ParsedownMath.php',
|
||||||
'ParsedownMath' => $vendorDir . '/benjaminhoegh/parsedown-math/ParsedownMath.php',
|
|
||||||
);
|
);
|
||||||
|
@ -6,7 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
|
|||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'parsedownMath' => array($vendorDir . '/benjaminhoegh/parsedown-math'),
|
|
||||||
'Parsedown' => array($vendorDir . '/erusev/parsedown'),
|
'Parsedown' => array($vendorDir . '/erusev/parsedown'),
|
||||||
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
|
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
|
||||||
);
|
);
|
||||||
|
10
web/app/vendor/composer/autoload_static.php
vendored
10
web/app/vendor/composer/autoload_static.php
vendored
@ -41,13 +41,6 @@ class ComposerStaticInit0d7c2cd5c2dbf2120e4372996869e900
|
|||||||
);
|
);
|
||||||
|
|
||||||
public static $prefixesPsr0 = array (
|
public static $prefixesPsr0 = array (
|
||||||
'p' =>
|
|
||||||
array (
|
|
||||||
'parsedownMath' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/benjaminhoegh/parsedown-math',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'P' =>
|
'P' =>
|
||||||
array (
|
array (
|
||||||
'Parsedown' =>
|
'Parsedown' =>
|
||||||
@ -65,8 +58,7 @@ class ComposerStaticInit0d7c2cd5c2dbf2120e4372996869e900
|
|||||||
);
|
);
|
||||||
|
|
||||||
public static $classMap = array (
|
public static $classMap = array (
|
||||||
'DynamicParent' => __DIR__ . '/..' . '/benjaminhoegh/parsedown-math/ParsedownMath.php',
|
'ParsedownMath' => __DIR__ . '/..' . '/parsedown-math/ParsedownMath.php',
|
||||||
'ParsedownMath' => __DIR__ . '/..' . '/benjaminhoegh/parsedown-math/ParsedownMath.php',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function getInitializer(ClassLoader $loader)
|
public static function getInitializer(ClassLoader $loader)
|
||||||
|
49
web/app/vendor/composer/installed.json
vendored
49
web/app/vendor/composer/installed.json
vendored
@ -1,53 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"name": "benjaminhoegh/parsedown-math",
|
|
||||||
"version": "dev-master",
|
|
||||||
"version_normalized": "9999999-dev",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/BenjaminHoegh/ParsedownMath.git",
|
|
||||||
"reference": "668b11b80c7d1dc9812274405426cb62bbb4d78b"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/BenjaminHoegh/ParsedownMath/zipball/668b11b80c7d1dc9812274405426cb62bbb4d78b",
|
|
||||||
"reference": "668b11b80c7d1dc9812274405426cb62bbb4d78b",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": "^5.6||^8.0"
|
|
||||||
},
|
|
||||||
"time": "2022-05-17T18:37:50+00:00",
|
|
||||||
"type": "library",
|
|
||||||
"installation-source": "source",
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"parsedownMath": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"description": "An extension of Parsedown that adds support for LaTeX.",
|
|
||||||
"homepage": "https://github.com/BenjaminHoegh/ParsedownMath",
|
|
||||||
"keywords": [
|
|
||||||
"latex",
|
|
||||||
"markdown",
|
|
||||||
"parsedown",
|
|
||||||
"parser"
|
|
||||||
],
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"url": "https://paypal.me/BenjaminHoegh",
|
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://www.buymeacoffee.com/BenjaminHoegh",
|
|
||||||
"type": "custom"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "erusev/parsedown",
|
"name": "erusev/parsedown",
|
||||||
"version": "1.7.4",
|
"version": "1.7.4",
|
||||||
|
248
web/app/vendor/parsedown-math/ParsedownMath.php
vendored
Normal file
248
web/app/vendor/parsedown-math/ParsedownMath.php
vendored
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ParsedownMath extends Parsedown
|
||||||
|
{
|
||||||
|
const VERSION = '1.2';
|
||||||
|
|
||||||
|
public function __construct($options = '')
|
||||||
|
{
|
||||||
|
if (version_compare(parent::version, '1.7.3') < 0) {
|
||||||
|
throw new Exception('ParsedownMath requires a later version of Parsedown');
|
||||||
|
}
|
||||||
|
// Blocks
|
||||||
|
$this->BlockTypes['\\'][] = 'Math';
|
||||||
|
$this->BlockTypes['$'][] = 'Math';
|
||||||
|
|
||||||
|
// Inline
|
||||||
|
$this->InlineTypes['\\'][] = 'Math';
|
||||||
|
$this->inlineMarkerList .= '\\';
|
||||||
|
|
||||||
|
$this->InlineTypes['$'][] = 'Math';
|
||||||
|
$this->inlineMarkerList .= '$';
|
||||||
|
|
||||||
|
$this->options['math']['enabled'] = (isset($options['math']['enabled']) ? $options['math']['enabled'] : false);
|
||||||
|
$this->options['math']['inline']['enabled'] = (isset($options['math']['inline']['enabled']) ? $options['math']['inline']['enabled'] : true);
|
||||||
|
$this->options['math']['block']['enabled'] = (isset($options['math']['block']['enabled']) ? $options['math']['block']['enabled'] : true);
|
||||||
|
$this->options['math']['matchSingleDollar'] = (isset($options['math']['matchSingleDollar']) ? $options['math']['matchSingleDollar'] : false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function element(array $Element)
|
||||||
|
{
|
||||||
|
if ($this->safeMode) {
|
||||||
|
$Element = $this->sanitiseElement($Element);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($Element['name'])) {
|
||||||
|
$markup = '<'.$Element['name'];
|
||||||
|
} else {
|
||||||
|
$markup = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($Element['attributes'])) {
|
||||||
|
foreach ($Element['attributes'] as $name => $value) {
|
||||||
|
if ($value === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$markup .= ' '.$name.'="'.self::escape($value).'"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($Element['text'])) {
|
||||||
|
if (isset($Element['name'])) {
|
||||||
|
$markup .= '>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($Element['nonNestables'])) {
|
||||||
|
$Element['nonNestables'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($Element['handler'])) {
|
||||||
|
$markup .= $this->{$Element['handler']}($Element['text'], $Element['nonNestables']);
|
||||||
|
} else {
|
||||||
|
$markup .= self::escape($Element['text'], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($Element['name'])) {
|
||||||
|
$markup .= '</'.$Element['name'].'>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset($Element['name'])) {
|
||||||
|
$markup .= ' />';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $markup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// ----------------------- Inline --------------------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Inline Math
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected function inlineMath($Excerpt)
|
||||||
|
{
|
||||||
|
if (!$this->options['math']['enabled'] === true && !$this->options['math']['inline']['enabled'] !== false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$matchSignleDollar = $this->options['math']['matchSingleDollar'] ?? false;
|
||||||
|
|
||||||
|
|
||||||
|
// Using inline detection to detect Block single-line math.
|
||||||
|
|
||||||
|
if (preg_match('/^(?<!\\\\)(?<!\$)\${2}(?!\$)[^$]*?(?<!\$)\${2}(?!\$)$/', $Excerpt['text'], $matches)) {
|
||||||
|
$Block = array(
|
||||||
|
'element' => array(
|
||||||
|
'text' => '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$Block['end'] = '$$';
|
||||||
|
$Block['complete'] = true;
|
||||||
|
$Block['latex'] = true;
|
||||||
|
$Block['element']['text'] = $matches[0];
|
||||||
|
$Block['extent'] = strlen($Block['element']['text']);
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Inline Matches
|
||||||
|
if ($matchSignleDollar === true) {
|
||||||
|
// Experimental
|
||||||
|
if (preg_match('/^(?<!\\\\)((?<!\$)\$(?!\$)(.*?)(?<!\$)\$(?!\$)|(?<!\\\\\()\\\\\((.*?)(?<!\\\\\()\\\\\)(?!\\\\\)))/s', $Excerpt['text'], $matches)) {
|
||||||
|
$this->mathMatch = $matches[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (preg_match('/^(?<!\\\\)(?<!\\\\\()\\\\\((.*?)(?<!\\\\\()\\\\\)(?!\\\\\))/s', $Excerpt['text'], $matches)) {
|
||||||
|
$this->mathMatch = $matches[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->mathMatch)) {
|
||||||
|
return array(
|
||||||
|
'extent' => strlen($this->mathMatch),
|
||||||
|
'element' => array(
|
||||||
|
'text' => $this->mathMatch,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $specialCharacters = array(
|
||||||
|
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '<', '>', '#', '+', '-', '.', '!', '|', '~', '^', '='
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Inline Escape
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected function inlineEscapeSequence($Excerpt)
|
||||||
|
{
|
||||||
|
$Element = array(
|
||||||
|
'element' => array(
|
||||||
|
'rawHtml' => $Excerpt['text'][1],
|
||||||
|
),
|
||||||
|
'extent' => 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->options['math']['enabled'] === true) {
|
||||||
|
if (isset($Excerpt['text'][1]) && in_array($Excerpt['text'][1], $this->specialCharacters) && !preg_match('/^(?<!\\\\)((?<!\\\\\()\\\\\((?!\\\\\())(.*?)(?<!\\\\)(?<!\\\\\()((?<!\\\\\))\\\\\)(?!\\\\\)))(?!\\\\\()/s', $Excerpt['text'])) {
|
||||||
|
return $Element;
|
||||||
|
} elseif (isset($Excerpt['text'][1]) && in_array($Excerpt['text'][1], $this->specialCharacters) && !preg_match('/^(?<!\\\\)(?<!\\\\\()\\\\\((.{1,}?)(?<!\\\\\()\\\\\)(?!\\\\\))/s', $Excerpt['text'])) {
|
||||||
|
return $Element;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset($Excerpt['text'][1]) && in_array($Excerpt['text'][1], $this->specialCharacters)) {
|
||||||
|
return $Element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// ----------------------- Blocks --------------------------
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Block Math
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected function blockMath($Line)
|
||||||
|
{
|
||||||
|
if (!$this->options['math']['enabled'] === true && !$this->options['math']['block']['enabled'] !== false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$Block = array(
|
||||||
|
'element' => array(
|
||||||
|
'text' => '',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (preg_match('/^(?<!\\\\)(\\\\\[)(?!.)$/', $Line['text'])) {
|
||||||
|
$Block['end'] = '\]';
|
||||||
|
return $Block;
|
||||||
|
} elseif (preg_match('/^(?<!\\\\)(\$\$)(?!.)$/', $Line['text'])) {
|
||||||
|
$Block['end'] = '$$';
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ~
|
||||||
|
|
||||||
|
protected function blockMathContinue($Line, $Block)
|
||||||
|
{
|
||||||
|
if (isset($Block['complete'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($Block['interrupted'])) {
|
||||||
|
$Block['element']['text'] .= str_repeat("\n", $Block['interrupted']);
|
||||||
|
|
||||||
|
unset($Block['interrupted']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^(?<!\\\\)(\\\\\])$/', $Line['text']) && $Block['end'] === '\]') {
|
||||||
|
$Block['complete'] = true;
|
||||||
|
$Block['latex'] = true;
|
||||||
|
$Block['element']['text'] = "\\[".$Block['element']['text']."\\]";
|
||||||
|
return $Block;
|
||||||
|
} elseif (preg_match('/^(?<!\\\\)(\$\$)$/', $Line['text']) && $Block['end'] === '$$') {
|
||||||
|
$Block['complete'] = true;
|
||||||
|
$Block['latex'] = true;
|
||||||
|
$Block['element']['text'] = "$$".$Block['element']['text']."$$";
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$Block['element']['text'] .= "\n" . $Line['body'];
|
||||||
|
|
||||||
|
// ~
|
||||||
|
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ~
|
||||||
|
|
||||||
|
protected function blockMathComplete($Block)
|
||||||
|
{
|
||||||
|
return $Block;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user