Skip to content

Commit 9e6cedb

Browse files
committed
[Site] refactor commonmark config
1 parent 4b3fcae commit 9e6cedb

File tree

5 files changed

+53
-52
lines changed

5 files changed

+53
-52
lines changed

ux.symfony.com/config/services.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,3 @@ services:
2323

2424
# add more service definitions when explicit configuration is needed
2525
# please note that last definitions always *replace* previous ones
26-
27-
App\Service\CommonMark\CodeExtension:
28-
tags: ['twig.markdown.league_extension']
29-
30-
League\CommonMark\Extension\ExternalLink\ExternalLinkExtension:
31-
tags: ['twig.markdown.league_extension']

ux.symfony.com/src/Service/CommonMark/CodeExtension.php

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace App\Service\CommonMark;
13+
14+
use League\CommonMark\CommonMarkConverter;
15+
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
16+
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
17+
use League\CommonMark\Extension\Mention\MentionExtension;
18+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
19+
20+
/**
21+
* @author Kevin Bond <kevinbond@gmail.com>
22+
*/
23+
#[AsDecorator('twig.markdown.league_common_mark_converter_factory')]
24+
final class ConverterFactory
25+
{
26+
public function __invoke(): CommonMarkConverter
27+
{
28+
$converter = new CommonMarkConverter([
29+
'mentions' => [
30+
'github_handle' => [
31+
'prefix' => '@',
32+
'pattern' => '[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?!\w)',
33+
'generator' => 'https://github.com/%s',
34+
],
35+
'github_issue' => [
36+
'prefix' => '#',
37+
'pattern' => '\d+',
38+
'generator' => 'https://github.com/symfony/ux/issues/%d',
39+
],
40+
],
41+
]);
42+
43+
$converter->getEnvironment()
44+
->addRenderer(FencedCode::class, new CodeRenderer(), 10)
45+
->addExtension(new ExternalLinkExtension())
46+
->addExtension(new MentionExtension())
47+
;
48+
49+
return $converter;
50+
}
51+
}

ux.symfony.com/src/Twig/Components/ChangelogItem.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,12 @@ private function formatContent(string $content): string
3030
// Replace "## " with "### "
3131
$content = preg_replace('/^## /m', '### ', $content);
3232

33-
// Replace #1234 with a mardown link to the issue
34-
$content = preg_replace('/#(\d+)/', '[#$1](https://github.com/symfony/ux/issues/$1)', $content);
35-
3633
// Replace "in https://github.com/symfony/ux/pull/1234" with a mardown link to the PR
37-
$content = preg_replace('#in https://github.com/symfony/ux/pull/(\d+)/?#', 'in [#$1](https://github.com/symfony/ux/issues/$1)', $content);
34+
$content = preg_replace('#https://github.com/symfony/ux/pull/(\d+)/?#', '#$1', $content);
3835

39-
// Replace "https://github.com/symfony/ux/compare/v2.14.1...v2.14.2" with a mardown link to the full changelog
36+
// Replace "https://github.com/symfony/ux/compare/v2.14.1...v2.14.2" with a markdown link to the full changelog
4037
$content = preg_replace('#(https://github.com/symfony/ux/compare/(v(\d+\.\d+\.\d+))...(v(\d+\.\d+\.\d+)))#', '[$2 -> $4]($1)', $content);
4138

42-
// Insert markdown link to the user's Github profile
43-
// ...in: "by @weaverryan in "
44-
$content = preg_replace('/by @([a-zA-Z0-9_]+) in /', 'by [@$1](https://github.com/$1) in ', $content);
45-
// ...in: "@weaverryan made their first "
46-
$content = preg_replace('/@([a-zA-Z0-9_]+) made their first /', '[@$1](https://github.com/$1) made their first ', $content);
47-
4839
// Shorten "made their first contribution in" to "in"
4940
$content = preg_replace('/made their first contribution in/', 'in', $content);
5041

ux.symfony.com/tests/Twig/Components/ChangelogItemTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ public static function provideContentValues(): iterable
5252
'### Title 3',
5353
'### Title 3',
5454
];
55-
yield 'inject_#issue_link' => [
56-
'Fixes #1234',
57-
'Fixes [#1234](https://github.com/symfony/ux/issues/1234)',
58-
];
59-
yield 'inject_@user_link' => [
60-
'by @weaverryan in ',
61-
'by [@weaverryan](https://github.com/weaverryan) in ',
62-
];
6355
yield 'inject_changelog_link' => [
6456
'https://github.com/symfony/ux/compare/v2.14.1...v2.14.2',
6557
'[v2.14.1 -> v2.14.2](https://github.com/symfony/ux/compare/v2.14.1...v2.14.2)',

0 commit comments

Comments
 (0)