Skip to content

Commit 69332c1

Browse files
authored
Merge pull request #336 from php-fig/updates
Updates of all deps: * PHP to 8.4 * Twig 3 * Sculpin 3.3.0-alpha4 (to support Twig 3) * CommonMark 2 * spatie/commonmark-highlighter v3 (to support CommonMark v2) * aptoma/twig-markdown dropped and ported inside the project * Docker compose setup updated * Switched from node-sass to sass Changes: * all template files files renamed from `*.twig` to `*.twig.html` to trigger correct MIME detection * all template changes are to handle Twig 3 breaking changes * With CommonMark 2, we switched to its native GitHub Markdown flavor
2 parents e207cbf + 6a6d774 commit 69332c1

File tree

92 files changed

+1475
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1475
-867
lines changed

.github/dependabot.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ updates:
44
directory: "/"
55
schedule:
66
interval: weekly
7+
- package-ecosystem: "bundler"
8+
directory: "/"
9+
schedule:
10+
interval: weekly

.platform.app.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: php-fig-website
2-
type: php:8.1
2+
type: php:8.4
33

44
build:
55
flavor: composer
@@ -25,7 +25,7 @@ disk: 1024
2525

2626
dependencies:
2727
nodejs:
28-
node-sass: '^4.9.4'
28+
sass: '^1.85'
2929
php:
3030
composer/composer: '^2'
3131

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org"
22

3-
ruby '>= 2.5', '< 2.6'
3+
ruby '>= 3.1', '< 3.2'
44

55
gem "html-proofer", "~> 3.19"

Gemfile.lock

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
addressable (2.8.0)
5-
public_suffix (>= 2.0.2, < 5.0)
6-
ethon (0.14.0)
4+
addressable (2.8.7)
5+
public_suffix (>= 2.0.2, < 7.0)
6+
ethon (0.16.0)
77
ffi (>= 1.15.0)
8-
ffi (1.15.0)
9-
html-proofer (3.19.1)
8+
ffi (1.17.1)
9+
ffi (1.17.1-arm64-darwin)
10+
ffi (1.17.1-x86_64-darwin)
11+
html-proofer (3.19.4)
1012
addressable (~> 2.3)
1113
mercenary (~> 0.3)
12-
nokogumbo (~> 2.0)
13-
parallel (~> 1.3)
14+
nokogiri (~> 1.13)
15+
parallel (~> 1.10)
1416
rainbow (~> 3.0)
1517
typhoeus (~> 1.3)
1618
yell (~> 2.0)
1719
mercenary (0.4.0)
18-
nokogiri (1.12.5-x86_64-linux)
20+
mini_portile2 (2.8.8)
21+
nokogiri (1.18.3)
22+
mini_portile2 (~> 2.8.2)
1923
racc (~> 1.4)
20-
nokogumbo (2.0.5)
21-
nokogiri (~> 1.8, >= 1.8.4)
22-
parallel (1.20.1)
23-
public_suffix (4.0.6)
24-
racc (1.5.2)
25-
rainbow (3.0.0)
26-
typhoeus (1.4.0)
24+
nokogiri (1.18.3-arm64-darwin)
25+
racc (~> 1.4)
26+
nokogiri (1.18.3-x86_64-darwin)
27+
racc (~> 1.4)
28+
parallel (1.26.3)
29+
public_suffix (6.0.1)
30+
racc (1.8.1)
31+
rainbow (3.1.1)
32+
typhoeus (1.4.1)
2733
ethon (>= 0.9.0)
2834
yell (2.2.2)
2935

3036
PLATFORMS
31-
x86_64-linux
37+
aarch64-linux
38+
arm64-darwin
39+
ruby
40+
x86_64-darwin
3241

3342
DEPENDENCIES
3443
html-proofer (~> 3.19)
3544

3645
RUBY VERSION
37-
ruby 2.5.9p229
46+
ruby 3.1.2p20
3847

3948
BUNDLED WITH
40-
2.3.26
49+
2.6.5

app/config/sculpin_kernel.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ services:
4040
tags:
4141
- { name: twig.extension }
4242

43-
aptoma.twig.markdown_extension:
44-
class: Aptoma\Twig\Extension\MarkdownExtension
43+
markdown_extension:
44+
class: \Fig\Website\MarkdownExtension
4545
arguments:
46-
$markdownEngine: '@Aptoma\Twig\Extension\MarkdownEngineInterface'
46+
$markdownConverter: '@League\CommonMark\GithubFlavoredMarkdownConverter'
4747
tags:
4848
- { name: twig.extension }
4949

50-
Aptoma\Twig\Extension\MarkdownEngineInterface:
51-
factory: ['Fig\Website\CommonMarkEngineFactory', 'create']
50+
League\CommonMark\GithubFlavoredMarkdownConverter:
51+
factory: ['Fig\Website\MarkdownConverterFactory', 'create']

app/lib/CommonMarkEngineFactory.php

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Fig\Website;
4+
5+
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
6+
use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock;
7+
use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode;
8+
use League\CommonMark\Extension\CommonMark\Node\Inline\HtmlInline;
9+
use League\CommonMark\Extension\CommonMark\Renderer\Block\HtmlBlockRenderer;
10+
use League\CommonMark\Extension\CommonMark\Renderer\Inline\HtmlInlineRenderer;
11+
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
12+
use League\CommonMark\Extension\Table\TableExtension;
13+
use League\CommonMark\GithubFlavoredMarkdownConverter;
14+
use Spatie\CommonMarkHighlighter\FencedCodeRenderer;
15+
use Spatie\CommonMarkHighlighter\IndentedCodeRenderer;
16+
17+
class MarkdownConverterFactory
18+
{
19+
public static function create(): GithubFlavoredMarkdownConverter
20+
{
21+
$supportedLanguages = [
22+
'php',
23+
'http', # inside PSR-7
24+
];
25+
26+
$config = [
27+
'heading_permalink' => [
28+
'id_prefix' => '',
29+
'fragment_prefix' => '',
30+
'insert' => 'after',
31+
],
32+
'html_input' => 'allow',
33+
'disallowed_raw_html' => ['disallowed_tags' => []],
34+
];
35+
36+
$converter = new GithubFlavoredMarkdownConverter($config);
37+
$environment = $converter->getEnvironment();
38+
$environment
39+
->addExtension(new TableExtension())
40+
->addExtension(new HeadingPermalinkExtension())
41+
->addRenderer(FencedCode::class, new FencedCodeRenderer($supportedLanguages))
42+
->addRenderer(IndentedCode::class, new IndentedCodeRenderer($supportedLanguages))
43+
;
44+
45+
return $converter;
46+
}
47+
}

app/lib/MarkdownExtension.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Fig\Website;
4+
5+
use League\CommonMark\GithubFlavoredMarkdownConverter;
6+
7+
/**
8+
* MarkdownExtension provides support for Markdown.
9+
* Ported from \Aptoma\Twig\Extension\MarkdownExtension
10+
*/
11+
class MarkdownExtension extends \Twig\Extension\AbstractExtension
12+
{
13+
public function __construct(
14+
private readonly GithubFlavoredMarkdownConverter $markdownConverter,
15+
) {}
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function getFilters(): array
21+
{
22+
return [
23+
new \Twig\TwigFilter(
24+
'markdown',
25+
$this->parseMarkdown(...),
26+
['is_safe' => ['html']]
27+
)
28+
];
29+
}
30+
31+
/**
32+
* Transform Markdown content to HTML
33+
*
34+
* @param string|null $content The Markdown content to be transformed, coming from Twig
35+
* @return string The result of the Markdown engine transformation into HTML
36+
*/
37+
public function parseMarkdown(?string $content): string
38+
{
39+
if (null === $content) {
40+
return '';
41+
}
42+
43+
return $this->markdownConverter->convert($content);
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function getTokenParsers(): array
50+
{
51+
return [new MarkdownTokenParser()];
52+
}
53+
}

app/lib/MarkdownNode.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Fig\Website;
4+
5+
/**
6+
* Represents a markdown node.
7+
* Ported from \Aptoma\Twig\Node\MarkdownNode
8+
*/
9+
class MarkdownNode extends \Twig\Node\Node
10+
{
11+
public function __construct(\Twig\Node\Node $body, $lineno, $tag = 'markdown')
12+
{
13+
parent::__construct(array('body' => $body), array(), $lineno, $tag);
14+
}
15+
16+
/**
17+
* Compiles the node to PHP.
18+
*
19+
* @param \Twig\Compiler A Twig\Compiler instance
20+
*/
21+
public function compile(\Twig\Compiler $compiler)
22+
{
23+
$compiler
24+
->addDebugInfo($this)
25+
->write('ob_start();' . PHP_EOL)
26+
->subcompile($this->getNode('body'))
27+
->write('$content = ob_get_clean();' . PHP_EOL)
28+
->write('preg_match("/^\s*/", $content, $matches);' . PHP_EOL)
29+
->write('$lines = explode("\n", $content);' . PHP_EOL)
30+
->write('$content = preg_replace(\'/^\' . $matches[0]. \'/\', "", $lines);' . PHP_EOL)
31+
->write('$content = join("\n", $content);' . PHP_EOL)
32+
->write('echo $this->env->getExtension(\'Fig\Website\MarkdownExtension\')->parseMarkdown($content);' . PHP_EOL);
33+
}
34+
}

app/lib/MarkdownTokenParser.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Fig\Website;
4+
5+
/**
6+
* Ported from \Aptoma\Twig\TokenParser\MarkdownTokenParser
7+
*/
8+
class MarkdownTokenParser extends \Twig\TokenParser\AbstractTokenParser
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*/
13+
public function parse(\Twig\Token $token): MarkdownNode
14+
{
15+
$lineno = $token->getLine();
16+
17+
$this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
18+
$body = $this->parser->subparse(array($this, 'decideMarkdownEnd'), true);
19+
$this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
20+
21+
return new MarkdownNode($body, $lineno, $this->getTag());
22+
}
23+
24+
/**
25+
* Decide if current token marks end of Markdown block.
26+
*/
27+
public function decideMarkdownEnd(\Twig\Token $token): bool
28+
{
29+
return $token->test('endmarkdown');
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function getTag(): string
36+
{
37+
return 'markdown';
38+
}
39+
}

0 commit comments

Comments
 (0)