Files
dualfroz 260083d10a fix: accept unordered_list_markers config in InlinesOnlyExtension
The unordered_list_markers option is declared in the shared 'commonmark'
config schema by CommonMarkCoreExtension, but InlinesOnlyExtension did not
declare it in its own schema for the same 'commonmark' namespace. Setting
the option while using InlinesOnlyExtension therefore failed schema
validation with 'Unexpected item commonmark unordered_list_markers'.

Declare the option in InlinesOnlyExtension using the same definition so it
is accepted. InlinesOnlyExtension does not render lists, so this only makes
the option valid without changing rendering behaviour.

Adds a regression test asserting the option is accepted and rendering still
works.

Closes #1015
2026-08-27 23:37:32 +02:00

85 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Tests\Functional\Extension\InlinesOnly;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
use League\CommonMark\MarkdownConverter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* Tests the extension against sample files
*/
final class InlinesOnlyFunctionalTest extends TestCase
{
private MarkdownConverter $converter;
protected function setUp(): void
{
$environment = new Environment();
$environment->addExtension(new InlinesOnlyExtension());
$this->converter = new MarkdownConverter($environment);
}
/**
* @dataProvider dataProvider
*
* @param string $markdown Markdown to parse
* @param string $html Expected result
*/
#[DataProvider('dataProvider')]
public function testExample(string $markdown, string $html): void
{
$actualResult = $this->converter->convert($markdown);
$failureMessage = 'Unexpected result';
$failureMessage .= "\n=== markdown ===============\n" . $markdown;
$failureMessage .= "\n=== expected ===============\n" . $html;
$failureMessage .= "\n=== got ====================\n" . $actualResult;
$this->assertEquals($html, $actualResult, $failureMessage);
}
/**
* @return array<array<string>>
*/
public static function dataProvider(): array
{
$markdown = \file_get_contents(__DIR__ . '/inlines.md');
$html = \file_get_contents(__DIR__ . '/inlines.html');
return [
[$markdown, $html],
];
}
/**
* The unordered_list_markers option is part of the shared 'commonmark' config
* schema. InlinesOnlyExtension reuses that config key, so setting the option
* must be accepted even though this extension does not render lists.
*
* @see https://github.com/thephpleague/commonmark/issues/1015
*/
public function testUnorderedListMarkersConfigIsAccepted(): void
{
$environment = new Environment(['commonmark' => ['unordered_list_markers' => ['*']]]);
$environment->addExtension(new InlinesOnlyExtension());
$converter = new MarkdownConverter($environment);
$this->assertSame(['*'], $environment->getConfiguration()->get('commonmark/unordered_list_markers'));
$this->assertSame('<em>foo</em>', \trim($converter->convert('*foo*')->getContent()));
}
}