Update scrivo/highlight.php

This commit is contained in:
Floorb 2022-03-14 16:24:33 -04:00
parent ba0f8a85f4
commit 22ce01cc05
10 changed files with 108 additions and 43 deletions

View file

@ -16,7 +16,7 @@
"ext-openssl": "*",
"ext-gd": "*",
"ext-mbstring": "*",
"scrivo/highlight.php": "v9.18.1.7",
"scrivo/highlight.php": "v9.18.1.9",
"erusev/parsedown": "^1.7",
"illuminate/database": "^9.4",
"ext-redis": "*"

24
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "04f306e84ef4ecc60decf6fb96ac490c",
"content-hash": "bc050acf9c5c5997281c5c3a6f33c811",
"packages": [
{
"name": "doctrine/inflector",
@ -732,21 +732,20 @@
},
{
"name": "scrivo/highlight.php",
"version": "v9.18.1.7",
"version": "v9.18.1.9",
"source": {
"type": "git",
"url": "https://github.com/scrivo/highlight.php.git",
"reference": "05996fcc61e97978d76ca7d1ac14b65e7cd26f91"
"reference": "d45585504777e6194a91dffc7270ca39833787f8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/scrivo/highlight.php/zipball/05996fcc61e97978d76ca7d1ac14b65e7cd26f91",
"reference": "05996fcc61e97978d76ca7d1ac14b65e7cd26f91",
"url": "https://api.github.com/repos/scrivo/highlight.php/zipball/d45585504777e6194a91dffc7270ca39833787f8",
"reference": "d45585504777e6194a91dffc7270ca39833787f8",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=5.4"
},
"require-dev": {
@ -755,15 +754,18 @@
"symfony/finder": "^2.8|^3.4",
"symfony/var-dumper": "^2.8|^3.4"
},
"suggest": {
"ext-mbstring": "Allows highlighting code with unicode characters and supports language with unicode keywords"
},
"type": "library",
"autoload": {
"files": [
"HighlightUtilities/functions.php"
],
"psr-0": {
"Highlight\\": "",
"HighlightUtilities\\": ""
},
"files": [
"HighlightUtilities/functions.php"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@ -804,7 +806,7 @@
"type": "github"
}
],
"time": "2021-07-09T00:30:39+00:00"
"time": "2021-12-03T06:45:28+00:00"
},
{
"name": "symfony/console",

View file

@ -7,13 +7,13 @@ $baseDir = dirname($vendorDir);
return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'b6b991a57620e2fb6b2f66f03fe9ddc2' => $vendorDir . '/symfony/string/Resources/functions.php',
'a1105708a18b76903365ca1c4aa61b02' => $vendorDir . '/symfony/translation/Resources/functions.php',
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
'60799491728b879e74601d83e38b2cad' => $vendorDir . '/illuminate/collections/helpers.php',
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
'a1105708a18b76903365ca1c4aa61b02' => $vendorDir . '/symfony/translation/Resources/functions.php',
'72579e7bd17821bb1321b87411366eae' => $vendorDir . '/illuminate/support/helpers.php',
'b6ec61354e97f32c0ae683041c78392a' => $vendorDir . '/scrivo/highlight.php/HighlightUtilities/functions.php',
);

View file

@ -20,7 +20,7 @@ return array(
'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'PonePaste\\' => array($baseDir . '/includes'),
'Illuminate\\Support\\' => array($vendorDir . '/illuminate/conditionable', $vendorDir . '/illuminate/macroable', $vendorDir . '/illuminate/collections', $vendorDir . '/illuminate/support'),
'Illuminate\\Support\\' => array($vendorDir . '/illuminate/collections', $vendorDir . '/illuminate/conditionable', $vendorDir . '/illuminate/macroable', $vendorDir . '/illuminate/support'),
'Illuminate\\Database\\' => array($vendorDir . '/illuminate/database'),
'Illuminate\\Contracts\\' => array($vendorDir . '/illuminate/contracts'),
'Illuminate\\Container\\' => array($vendorDir . '/illuminate/container'),

View file

@ -8,13 +8,13 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => __DIR__ . '/..' . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => __DIR__ . '/..' . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'b6b991a57620e2fb6b2f66f03fe9ddc2' => __DIR__ . '/..' . '/symfony/string/Resources/functions.php',
'a1105708a18b76903365ca1c4aa61b02' => __DIR__ . '/..' . '/symfony/translation/Resources/functions.php',
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
'60799491728b879e74601d83e38b2cad' => __DIR__ . '/..' . '/illuminate/collections/helpers.php',
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
'a1105708a18b76903365ca1c4aa61b02' => __DIR__ . '/..' . '/symfony/translation/Resources/functions.php',
'72579e7bd17821bb1321b87411366eae' => __DIR__ . '/..' . '/illuminate/support/helpers.php',
'b6ec61354e97f32c0ae683041c78392a' => __DIR__ . '/..' . '/scrivo/highlight.php/HighlightUtilities/functions.php',
);
@ -119,9 +119,9 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
),
'Illuminate\\Support\\' =>
array (
0 => __DIR__ . '/..' . '/illuminate/conditionable',
1 => __DIR__ . '/..' . '/illuminate/macroable',
2 => __DIR__ . '/..' . '/illuminate/collections',
0 => __DIR__ . '/..' . '/illuminate/collections',
1 => __DIR__ . '/..' . '/illuminate/conditionable',
2 => __DIR__ . '/..' . '/illuminate/macroable',
3 => __DIR__ . '/..' . '/illuminate/support',
),
'Illuminate\\Database\\' =>

View file

@ -762,22 +762,21 @@
},
{
"name": "scrivo/highlight.php",
"version": "v9.18.1.7",
"version_normalized": "9.18.1.7",
"version": "v9.18.1.9",
"version_normalized": "9.18.1.9",
"source": {
"type": "git",
"url": "https://github.com/scrivo/highlight.php.git",
"reference": "05996fcc61e97978d76ca7d1ac14b65e7cd26f91"
"reference": "d45585504777e6194a91dffc7270ca39833787f8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/scrivo/highlight.php/zipball/05996fcc61e97978d76ca7d1ac14b65e7cd26f91",
"reference": "05996fcc61e97978d76ca7d1ac14b65e7cd26f91",
"url": "https://api.github.com/repos/scrivo/highlight.php/zipball/d45585504777e6194a91dffc7270ca39833787f8",
"reference": "d45585504777e6194a91dffc7270ca39833787f8",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=5.4"
},
"require-dev": {
@ -786,17 +785,20 @@
"symfony/finder": "^2.8|^3.4",
"symfony/var-dumper": "^2.8|^3.4"
},
"time": "2021-07-09T00:30:39+00:00",
"suggest": {
"ext-mbstring": "Allows highlighting code with unicode characters and supports language with unicode keywords"
},
"time": "2021-12-03T06:45:28+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"HighlightUtilities/functions.php"
],
"psr-0": {
"Highlight\\": "",
"HighlightUtilities\\": ""
},
"files": [
"HighlightUtilities/functions.php"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [

View file

@ -5,7 +5,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '3c0fc75d296bbf2703fa00ff1a7ece4cc9c2164e',
'reference' => '6f1363aafe558eeabeb9ac6985892803b5bd14f7',
'name' => 'aftercase/ponepaste',
'dev' => true,
),
@ -16,7 +16,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '3c0fc75d296bbf2703fa00ff1a7ece4cc9c2164e',
'reference' => '6f1363aafe558eeabeb9ac6985892803b5bd14f7',
'dev_requirement' => false,
),
'doctrine/inflector' => array(
@ -140,12 +140,12 @@
'dev_requirement' => false,
),
'scrivo/highlight.php' => array(
'pretty_version' => 'v9.18.1.7',
'version' => '9.18.1.7',
'pretty_version' => 'v9.18.1.9',
'version' => '9.18.1.9',
'type' => 'library',
'install_path' => __DIR__ . '/../scrivo/highlight.php',
'aliases' => array(),
'reference' => '05996fcc61e97978d76ca7d1ac14b65e7cd26f91',
'reference' => 'd45585504777e6194a91dffc7270ca39833787f8',
'dev_requirement' => false,
),
'symfony/console' => array(

View file

@ -45,6 +45,9 @@ class Highlighter
*/
const SPAN_END_TAG = "</span>";
/** @var bool Disable warnings thrown on PHP installations without multibyte functions available. */
public static $DISABLE_MULTIBYTE_WARNING = false;
/** @var bool */
private $safeMode = true;
@ -79,6 +82,15 @@ class Highlighter
/** @var string The current code we are highlighting */
private $codeToHighlight;
/** @var bool */
private $needsMultibyteSupport = false;
/** @var bool|null */
private static $hasMultiByteSupport = null;
/** @var bool */
private static $hasThrownMultiByteWarning = false;
/** @var string[] A list of all the bundled languages */
private static $bundledLanguages = array();
@ -328,7 +340,7 @@ class Highlighter
*/
private function keywordMatch($mode, $match)
{
$kwd = $this->language->case_insensitive ? mb_strtolower($match[0]) : $match[0];
$kwd = $this->language->case_insensitive ? $this->strToLower($match[0]) : $match[0];
return isset($mode->keywords[$kwd]) ? $mode->keywords[$kwd] : null;
}
@ -639,6 +651,45 @@ class Highlighter
return $code;
}
private function checkMultibyteNecessity()
{
$this->needsMultibyteSupport = preg_match('/[^\x00-\x7F]/', $this->codeToHighlight) === 1;
// If we aren't working with Unicode strings, then we default to `strtolower` since it's significantly faster
// https://github.com/scrivo/highlight.php/pull/92#pullrequestreview-782213861
if (!$this->needsMultibyteSupport) {
return;
}
if (self::$hasMultiByteSupport === null) {
self::$hasMultiByteSupport = function_exists('mb_strtolower');
}
if (!self::$hasMultiByteSupport && !self::$hasThrownMultiByteWarning) {
if (!self::$DISABLE_MULTIBYTE_WARNING) {
trigger_error('Your code snippet has unicode characters but your PHP version does not have multibyte string support. You should install the `mbstring` PHP package or `symfony/polyfill-mbstring` composer package if you use unicode characters.', E_USER_WARNING);
}
self::$hasThrownMultiByteWarning = true;
}
}
/**
* Allow for graceful failure if the mb_strtolower function doesn't exist.
*
* @param string $str
*
* @return string
*/
private function strToLower($str)
{
if ($this->needsMultibyteSupport && self::$hasMultiByteSupport) {
return mb_strtolower($str);
}
return strtolower($str);
}
/**
* Set the languages that will used for auto-detection. When using auto-
* detection the code to highlight will be probed for every language in this
@ -780,6 +831,8 @@ class Highlighter
throw new \DomainException("Unknown language: \"$languageName\"");
}
$this->checkMultibyteNecessity();
$this->language->compile($this->safeMode);
$this->top = $continuation ? $continuation : $this->language;
$this->continuations = array();

View file

@ -59,6 +59,7 @@ class RegExMatch implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new \ArrayIterator($this->data);
@ -67,6 +68,7 @@ class RegExMatch implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->data[$offset]);
@ -75,6 +77,7 @@ class RegExMatch implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->data[$offset];
@ -83,6 +86,7 @@ class RegExMatch implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
throw new \LogicException(__CLASS__ . ' instances are read-only.');
@ -91,6 +95,7 @@ class RegExMatch implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
throw new \LogicException(__CLASS__ . ' instances are read-only.');
@ -101,6 +106,7 @@ class RegExMatch implements \ArrayAccess, \Countable, \IteratorAggregate
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->data);

View file

@ -47,13 +47,15 @@
],
"require": {
"php": ">=5.4",
"ext-json": "*",
"ext-mbstring": "*"
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.7",
"sabberworm/php-css-parser": "^8.3",
"symfony/finder": "^2.8|^3.4",
"symfony/var-dumper": "^2.8|^3.4"
},
"suggest": {
"ext-mbstring": "Allows highlighting code with unicode characters and supports language with unicode keywords"
}
}