Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Feb 2, 2024
2 parents d1c0cee + 91c2429 commit 5de7972
Show file tree
Hide file tree
Showing 64 changed files with 233 additions and 230 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
/.idea/
/.phpcs-cache
/.phpunit.result.cache
/.phpunit.cache
/build/
/docs/_site/
composer.lock
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Expand Up @@ -13,6 +13,13 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
- `autolink/allowed_protocols` - an array of protocols to allow autolinking for
- `autolink/default_protocol` - the default protocol to use when none is specified

## [2.4.2] - 2024-02-02

### Fixed

- Fixed declaration parser being too strict
- `FencedCodeRenderer`: don't add `language-` to class if already prefixed

## [2.4.1] - 2023-08-30

### Fixed
Expand Down Expand Up @@ -567,7 +574,8 @@ No changes were introduced since the previous release.
- Alternative 1: Use `CommonMarkConverter` or `GithubFlavoredMarkdownConverter` if you don't need to customize the environment
- Alternative 2: Instantiate a new `Environment` and add the necessary extensions yourself

[unreleased]: https://github.com/thephpleague/commonmark/compare/2.4.1...main
[unreleased]: https://github.com/thephpleague/commonmark/compare/2.4.2...main
[2.4.2]: https://github.com/thephpleague/commonmark/compare/2.4.1...2.4.2
[2.4.1]: https://github.com/thephpleague/commonmark/compare/2.4.0...2.4.1
[2.4.0]: https://github.com/thephpleague/commonmark/compare/2.3.9...2.4.0
[2.3.9]: https://github.com/thephpleague/commonmark/compare/2.3.8...2.3.9
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -98,7 +98,7 @@ See [our extension documentation](https://commonmark.thephpleague.com/extensions

Custom parsers/renderers can be bundled into extensions which extend CommonMark. Here are some that you may find interesting:

- [Alt Three Emoji](https://github.com/AltThree/Emoji) An emoji parser for CommonMark.
- [Emoji extension](https://github.com/ElGigi/CommonMarkEmoji) - UTF-8 emoji extension with Github tag.
- [Sup Sub extensions](https://github.com/OWS/commonmark-sup-sub-extensions) - Adds support of superscript and subscript (`<sup>` and `<sub>` HTML tags)
- [YouTube iframe extension](https://github.com/zoonru/commonmark-ext-youtube-iframe) - Replaces youtube link with iframe.
- [Lazy Image extension](https://github.com/simonvomeyser/commonmark-ext-lazy-image) - Adds various options for lazy loading of images.
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Expand Up @@ -31,7 +31,7 @@
"require-dev": {
"ext-json": "*",
"cebe/markdown": "^1.0",
"commonmark/cmark": "0.30.0",
"commonmark/cmark": "0.30.3",
"commonmark/commonmark.js": "0.30.0",
"composer/package-versions-deprecated": "^1.8",
"embed/embed": "^4.4",
Expand All @@ -40,10 +40,10 @@
"michelf/php-markdown": "^1.4 || ^2.0",
"nyholm/psr7": "^1.5",
"phpstan/phpstan": "^1.8.2",
"phpunit/phpunit": "^9.5.21",
"phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0",
"scrutinizer/ocular": "^1.8.1",
"symfony/finder": "^5.3 | ^6.0",
"symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0",
"symfony/finder": "^5.3 | ^6.0 || ^7.0",
"symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0 || ^7.0",
"unleashedtech/php-coding-standard": "^3.1.1",
"vimeo/psalm": "^4.24.0 || ^5.0.0"
},
Expand All @@ -67,9 +67,9 @@
"type": "package",
"package": {
"name": "commonmark/cmark",
"version": "0.30.0",
"version": "0.30.3",
"dist": {
"url": "https://github.com/commonmark/cmark/archive/0.30.0.zip",
"url": "https://github.com/commonmark/cmark/archive/0.30.3.zip",
"type": "zip"
}
}
Expand All @@ -80,7 +80,7 @@
"name": "github/gfm",
"version": "0.29.0",
"dist": {
"url": "https://github.com/github/cmark-gfm/archive/0.29.0.gfm.9.zip",
"url": "https://github.com/github/cmark-gfm/archive/0.29.0.gfm.13.zip",
"type": "zip"
}
}
Expand Down
8 changes: 4 additions & 4 deletions docs/Gemfile.lock
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.4)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
colorator (1.1.0)
concurrent-ruby (1.2.2)
Expand Down Expand Up @@ -37,7 +37,7 @@ GEM
http_parser.rb (0.8.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
jekyll (4.3.2)
jekyll (4.3.3)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
Expand All @@ -53,7 +53,7 @@ GEM
safe_yaml (~> 1.0)
terminal-table (>= 1.8, < 4.0)
webrick (~> 1.7)
jekyll-github-metadata (2.16.0)
jekyll-github-metadata (2.16.1)
jekyll (>= 3.4, < 5.0)
octokit (>= 4, < 7, != 4.4.0)
jekyll-redirect-from (0.16.0)
Expand Down Expand Up @@ -81,7 +81,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.5)
rexml (3.2.6)
rouge (3.30.0)
ruby2_keywords (0.0.5)
safe_yaml (1.0.5)
Expand Down
9 changes: 3 additions & 6 deletions phpunit.xml.dist
Expand Up @@ -2,15 +2,12 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
backupStaticProperties="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
cacheDirectory=".phpunit.cache"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
Expand Down
Expand Up @@ -41,7 +41,12 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): \

$infoWords = $node->getInfoWords();
if (\count($infoWords) !== 0 && $infoWords[0] !== '') {
$attrs->append('class', 'language-' . $infoWords[0]);
$class = $infoWords[0];
if (! \str_starts_with($class, 'language-')) {
$class = 'language-' . $class;
}

$attrs->append('class', $class);
}

return new HtmlElement(
Expand Down
2 changes: 1 addition & 1 deletion src/Util/RegexHelper.php
Expand Up @@ -55,7 +55,7 @@ final class RegexHelper
public const PARTIAL_CLOSEBLOCKTAG = '<\/' . self::PARTIAL_BLOCKTAGNAME . '\s*[>]';
public const PARTIAL_HTMLCOMMENT = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->';
public const PARTIAL_PROCESSINGINSTRUCTION = '[<][?][\s\S]*?[?][>]';
public const PARTIAL_DECLARATION = '<![A-Z]+' . '\s+[^>]*>';
public const PARTIAL_DECLARATION = '<![A-Z]+' . '[^>]*>';
public const PARTIAL_CDATA = '<!\[CDATA\[[\s\S]*?]\]>';
public const PARTIAL_HTMLTAG = '(?:' . self::PARTIAL_OPENTAG . '|' . self::PARTIAL_CLOSETAG . '|' . self::PARTIAL_HTMLCOMMENT . '|' .
self::PARTIAL_PROCESSINGINSTRUCTION . '|' . self::PARTIAL_DECLARATION . '|' . self::PARTIAL_CDATA . ')';
Expand Down
Expand Up @@ -26,7 +26,7 @@
* This is particularly useful for testing minor variations allowed by the spec
* or small regressions not tested by the spec.
*/
abstract class AbstractLocalDataTest extends TestCase
abstract class AbstractLocalDataTestCase extends TestCase
{
/**
* @param array<string, mixed> $config
Expand All @@ -36,7 +36,7 @@ abstract protected function createConverter(array $config = []): ConverterInterf
/**
* @return iterable<array{string, string, array<string, mixed>, string}>
*/
abstract public function dataProvider(): iterable;
abstract public static function dataProvider(): iterable;

/**
* @dataProvider dataProvider
Expand All @@ -61,7 +61,7 @@ public function testWithLocalData(string $markdown, string $html, array $config,
/**
* @return iterable<array{string, string, array<string, mixed>, string}>
*/
protected function loadTests(string $dir, string $pattern = '*', string $inputFormat = '.md', string $outputFormat = '.html'): iterable
final protected static function loadTests(string $dir, string $pattern = '*', string $inputFormat = '.md', string $outputFormat = '.html'): iterable
{
$finder = new Finder();
$finder->files()
Expand Down
Expand Up @@ -18,10 +18,9 @@

use League\CommonMark\CommonMarkConverter;
use League\CommonMark\MarkdownConverter;
use League\CommonMark\Util\SpecReader;
use PHPUnit\Framework\TestCase;

abstract class AbstractSpecTest extends TestCase
abstract class AbstractSpecTestCase extends TestCase
{
protected MarkdownConverter $converter;

Expand All @@ -33,35 +32,25 @@ protected function setUp(): void
/**
* @dataProvider dataProvider
*
* @param string $markdown Markdown to parse
* @param string $html Expected result
* @param string $input Markdown to parse
* @param string $output Expected result
*/
public function testSpecExample(string $markdown, string $html): void
public function testSpecExample(string $input, string $output, string $type = '', string $section = '', int $number = -1): void
{
$actualResult = (string) $this->converter->convert($markdown);
$actualResult = (string) $this->converter->convert($input);

$failureMessage = 'Unexpected result:';
$failureMessage .= "\n=== markdown ===============\n" . $this->showSpaces($markdown);
$failureMessage .= "\n=== expected ===============\n" . $this->showSpaces($html);
$failureMessage .= "\n=== markdown ===============\n" . $this->showSpaces($input);
$failureMessage .= "\n=== expected ===============\n" . $this->showSpaces($output);
$failureMessage .= "\n=== got ====================\n" . $this->showSpaces($actualResult);

$this->assertEquals($html, $actualResult, $failureMessage);
$this->assertEquals($output, $actualResult, $failureMessage);
}

public function dataProvider(): \Generator
{
yield from $this->loadSpecExamples();
}

protected function loadSpecExamples(): \Generator
{
yield from SpecReader::readFile($this->getFileName());
}
abstract public static function dataProvider(): \Generator;

private function showSpaces(string $str): string
{
return \strtr($str, ["\t" => '→', ' ' => '␣']);
}

abstract protected function getFileName(): string;
}
28 changes: 11 additions & 17 deletions tests/functional/CMarkRegressionTest.php
Expand Up @@ -16,30 +16,24 @@

namespace League\CommonMark\Tests\Functional;

use League\CommonMark\Util\SpecReader;

/**
* Tests the parser against the CommonMark spec
*/
final class CMarkRegressionTest extends AbstractSpecTest
final class CMarkRegressionTest extends AbstractSpecTestCase
{
protected function getFileName(): string
public static function dataProvider(): \Generator
{
return __DIR__ . '/../../vendor/commonmark/cmark/test/regression.txt';
}

/**
* @deprecated
*
* We can't currently render spec example 13 exactly how the upstream library does. We'll likely need to overhaul
* our rendering approach in order to fix that, so we'll use this temporary workaround for now.
*/
public function dataProvider(): \Generator
{
foreach (parent::dataProvider() as $example) {
$tests = SpecReader::readFile(__DIR__ . '/../../vendor/commonmark/cmark/test/regression.txt');
foreach ($tests as $example) {
// We can't currently render spec example 13 exactly how the upstream library does. We'll likely need to overhaul
// our rendering approach in order to fix that, so we'll use this temporary workaround for now.
if ($example['number'] === 13) {
yield \str_replace('</script></li>', "</script>\n</li>", $example);
} else {
yield $example;
$example['output'] = \str_replace('</script></li>', "</script>\n</li>", $example['output']);
}

yield $example;
}
}
}
28 changes: 11 additions & 17 deletions tests/functional/CommonMarkJSRegressionTest.php
Expand Up @@ -16,30 +16,24 @@

namespace League\CommonMark\Tests\Functional;

use League\CommonMark\Util\SpecReader;

/**
* Tests the parser against the CommonMark spec
*/
final class CommonMarkJSRegressionTest extends AbstractSpecTest
final class CommonMarkJSRegressionTest extends AbstractSpecTestCase
{
protected function getFileName(): string
public static function dataProvider(): \Generator
{
return __DIR__ . '/../../vendor/commonmark/commonmark.js/test/regression.txt';
}

/**
* @deprecated
*
* We can't currently render spec example 18 exactly how the upstream library does. We'll likely need to overhaul
* our rendering approach in order to fix that, so we'll use this temporary workaround for now.
*/
public function dataProvider(): \Generator
{
foreach (parent::dataProvider() as $example) {
$tests = SpecReader::readFile(__DIR__ . '/../../vendor/commonmark/commonmark.js/test/regression.txt');
foreach ($tests as $example) {
// We can't currently render spec example 18 exactly how the upstream library does. We'll likely need to overhaul
// our rendering approach in order to fix that, so we'll use this temporary workaround for now.
if ($example['number'] === 18) {
yield \str_replace('</script></li>', "</script>\n</li>", $example);
} else {
yield $example;
$example['output'] = \str_replace('</script></li>', "</script>\n</li>", $example['output']);
}

yield $example;
}
}
}
2 changes: 1 addition & 1 deletion tests/functional/Delimiter/DelimiterProcessingTest.php
Expand Up @@ -55,7 +55,7 @@ public function testAsymmetricDelimiterProcessing(string $input, string $expecte
/**
* @return iterable<array<string>>
*/
public function asymmetricDelimiterDataProvider(): iterable
public static function asymmetricDelimiterDataProvider(): iterable
{
yield ['{foo} bar', "<p>FOO bar</p>\n"];
yield ['f{oo ba}r', "<p>fOO BAr</p>\n"];
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/Extension/Attributes/LocalDataTest.php
Expand Up @@ -20,12 +20,12 @@
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
use League\CommonMark\MarkdownConverter;
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;

/**
* @internal
*/
final class LocalDataTest extends AbstractLocalDataTest
final class LocalDataTest extends AbstractLocalDataTestCase
{
/**
* @param array<string, mixed> $config
Expand All @@ -43,8 +43,8 @@ protected function createConverter(array $config = []): ConverterInterface
/**
* {@inheritDoc}
*/
public function dataProvider(): iterable
public static function dataProvider(): iterable
{
yield from $this->loadTests(__DIR__ . '/data');
yield from self::loadTests(__DIR__ . '/data');
}
}
8 changes: 4 additions & 4 deletions tests/functional/Extension/Autolink/AutolinkXmlTest.php
Expand Up @@ -17,10 +17,10 @@
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\Autolink\AutolinkExtension;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Tests\Functional\AbstractLocalDataTest;
use League\CommonMark\Tests\Functional\AbstractLocalDataTestCase;
use League\CommonMark\Xml\MarkdownToXmlConverter;

final class AutolinkXmlTest extends AbstractLocalDataTest
final class AutolinkXmlTest extends AbstractLocalDataTestCase
{
/**
* @param array<string, mixed> $config
Expand All @@ -37,8 +37,8 @@ protected function createConverter(array $config = []): ConverterInterface
/**
* {@inheritDoc}
*/
public function dataProvider(): iterable
public static function dataProvider(): iterable
{
yield from $this->loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
yield from self::loadTests(__DIR__ . '/xml', '*', '.md', '.xml');
}
}
Expand Up @@ -38,7 +38,7 @@ public function testEmailAutolinks(string $input, string $expected): void
/**
* @return iterable<array<mixed>>
*/
public function dataProviderForEmailAutolinks(): iterable
public static function dataProviderForEmailAutolinks(): iterable
{
yield ['You can try emailing foo@example.com but that inbox doesn\'t actually exist.', '<p>You can try emailing <a href="mailto:foo@example.com">foo@example.com</a> but that inbox doesn\'t actually exist.</p>'];
yield ['> This processor can even handle email addresses like foo@example.com inside of blockquotes!', "<blockquote>\n<p>This processor can even handle email addresses like <a href=\"mailto:foo@example.com\">foo@example.com</a> inside of blockquotes!</p>\n</blockquote>"];
Expand Down

0 comments on commit 5de7972

Please sign in to comment.