Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #336

Merged
merged 11 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ updates:
directory: "/"
schedule:
interval: weekly
- package-ecosystem: "bundler"
directory: "/"
schedule:
interval: weekly
4 changes: 2 additions & 2 deletions .platform.app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: php-fig-website
type: php:8.1
type: php:8.4

build:
flavor: composer
Expand All @@ -25,7 +25,7 @@ disk: 1024

dependencies:
nodejs:
node-sass: '^4.9.4'
sass: '^1.85'
php:
composer/composer: '^2'

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source "https://rubygems.org"

ruby '>= 2.5', '< 2.6'
ruby '>= 3.1', '< 3.2'

gem "html-proofer", "~> 3.19"
45 changes: 27 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ethon (0.14.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.15.0)
html-proofer (3.19.1)
ffi (1.17.1)
ffi (1.17.1-arm64-darwin)
ffi (1.17.1-x86_64-darwin)
html-proofer (3.19.4)
addressable (~> 2.3)
mercenary (~> 0.3)
nokogumbo (~> 2.0)
parallel (~> 1.3)
nokogiri (~> 1.13)
parallel (~> 1.10)
rainbow (~> 3.0)
typhoeus (~> 1.3)
yell (~> 2.0)
mercenary (0.4.0)
nokogiri (1.12.5-x86_64-linux)
mini_portile2 (2.8.8)
nokogiri (1.18.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogumbo (2.0.5)
nokogiri (~> 1.8, >= 1.8.4)
parallel (1.20.1)
public_suffix (4.0.6)
racc (1.5.2)
rainbow (3.0.0)
typhoeus (1.4.0)
nokogiri (1.18.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.3-x86_64-darwin)
racc (~> 1.4)
parallel (1.26.3)
public_suffix (6.0.1)
racc (1.8.1)
rainbow (3.1.1)
typhoeus (1.4.1)
ethon (>= 0.9.0)
yell (2.2.2)

PLATFORMS
x86_64-linux
aarch64-linux
arm64-darwin
ruby
x86_64-darwin

DEPENDENCIES
html-proofer (~> 3.19)

RUBY VERSION
ruby 2.5.9p229
ruby 3.1.2p20

BUNDLED WITH
2.3.26
2.6.5
10 changes: 5 additions & 5 deletions app/config/sculpin_kernel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ services:
tags:
- { name: twig.extension }

aptoma.twig.markdown_extension:
class: Aptoma\Twig\Extension\MarkdownExtension
markdown_extension:
class: \Fig\Website\MarkdownExtension
arguments:
$markdownEngine: '@Aptoma\Twig\Extension\MarkdownEngineInterface'
$markdownConverter: '@League\CommonMark\GithubFlavoredMarkdownConverter'
tags:
- { name: twig.extension }

Aptoma\Twig\Extension\MarkdownEngineInterface:
factory: ['Fig\Website\CommonMarkEngineFactory', 'create']
League\CommonMark\GithubFlavoredMarkdownConverter:
factory: ['Fig\Website\MarkdownConverterFactory', 'create']
48 changes: 0 additions & 48 deletions app/lib/CommonMarkEngineFactory.php

This file was deleted.

47 changes: 47 additions & 0 deletions app/lib/MarkdownConverterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Fig\Website;

use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock;
use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode;
use League\CommonMark\Extension\CommonMark\Node\Inline\HtmlInline;
use League\CommonMark\Extension\CommonMark\Renderer\Block\HtmlBlockRenderer;
use League\CommonMark\Extension\CommonMark\Renderer\Inline\HtmlInlineRenderer;
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
use League\CommonMark\Extension\Table\TableExtension;
use League\CommonMark\GithubFlavoredMarkdownConverter;
use Spatie\CommonMarkHighlighter\FencedCodeRenderer;
use Spatie\CommonMarkHighlighter\IndentedCodeRenderer;

class MarkdownConverterFactory
{
public static function create(): GithubFlavoredMarkdownConverter
{
$supportedLanguages = [
'php',
'http', # inside PSR-7
];

$config = [
'heading_permalink' => [
'id_prefix' => '',
'fragment_prefix' => '',
'insert' => 'after',
],
'html_input' => 'allow',
'disallowed_raw_html' => ['disallowed_tags' => []],
];

$converter = new GithubFlavoredMarkdownConverter($config);
$environment = $converter->getEnvironment();
$environment
->addExtension(new TableExtension())
->addExtension(new HeadingPermalinkExtension())
->addRenderer(FencedCode::class, new FencedCodeRenderer($supportedLanguages))
->addRenderer(IndentedCode::class, new IndentedCodeRenderer($supportedLanguages))
;

return $converter;
}
}
53 changes: 53 additions & 0 deletions app/lib/MarkdownExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Fig\Website;

use League\CommonMark\GithubFlavoredMarkdownConverter;

/**
* MarkdownExtension provides support for Markdown.
* Ported from \Aptoma\Twig\Extension\MarkdownExtension
*/
class MarkdownExtension extends \Twig\Extension\AbstractExtension
{
public function __construct(
private readonly GithubFlavoredMarkdownConverter $markdownConverter,
) {}

/**
* {@inheritdoc}
*/
public function getFilters(): array
{
return [
new \Twig\TwigFilter(
'markdown',
$this->parseMarkdown(...),
['is_safe' => ['html']]
)
];
}

/**
* Transform Markdown content to HTML
*
* @param string|null $content The Markdown content to be transformed, coming from Twig
* @return string The result of the Markdown engine transformation into HTML
*/
public function parseMarkdown(?string $content): string
{
if (null === $content) {
return '';
}

return $this->markdownConverter->convert($content);
}

/**
* {@inheritdoc}
*/
public function getTokenParsers(): array
{
return [new MarkdownTokenParser()];
}
}
34 changes: 34 additions & 0 deletions app/lib/MarkdownNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Fig\Website;

/**
* Represents a markdown node.
* Ported from \Aptoma\Twig\Node\MarkdownNode
*/
class MarkdownNode extends \Twig\Node\Node
{
public function __construct(\Twig\Node\Node $body, $lineno, $tag = 'markdown')
{
parent::__construct(array('body' => $body), array(), $lineno, $tag);
}

/**
* Compiles the node to PHP.
*
* @param \Twig\Compiler A Twig\Compiler instance
*/
public function compile(\Twig\Compiler $compiler)
{
$compiler
->addDebugInfo($this)
->write('ob_start();' . PHP_EOL)
->subcompile($this->getNode('body'))
->write('$content = ob_get_clean();' . PHP_EOL)
->write('preg_match("/^\s*/", $content, $matches);' . PHP_EOL)
->write('$lines = explode("\n", $content);' . PHP_EOL)
->write('$content = preg_replace(\'/^\' . $matches[0]. \'/\', "", $lines);' . PHP_EOL)
->write('$content = join("\n", $content);' . PHP_EOL)
->write('echo $this->env->getExtension(\'Fig\Website\MarkdownExtension\')->parseMarkdown($content);' . PHP_EOL);
}
}
39 changes: 39 additions & 0 deletions app/lib/MarkdownTokenParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Fig\Website;

/**
* Ported from \Aptoma\Twig\TokenParser\MarkdownTokenParser
*/
class MarkdownTokenParser extends \Twig\TokenParser\AbstractTokenParser
{
/**
* {@inheritdoc}
*/
public function parse(\Twig\Token $token): MarkdownNode
{
$lineno = $token->getLine();

$this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideMarkdownEnd'), true);
$this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE);

return new MarkdownNode($body, $lineno, $this->getTag());
}

/**
* Decide if current token marks end of Markdown block.
*/
public function decideMarkdownEnd(\Twig\Token $token): bool
{
return $token->test('endmarkdown');
}

/**
* {@inheritdoc}
*/
public function getTag(): string
{
return 'markdown';
}
}
26 changes: 0 additions & 26 deletions app/lib/NullSafeCommonMarkEngine.php

This file was deleted.

4 changes: 2 additions & 2 deletions bin/build-sass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

node-sass \
--output-style=compressed \
npx --yes sass \
--style=compressed \
source/_sass/all.scss \
output_dev/css/all.css
6 changes: 3 additions & 3 deletions bin/html-proofer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

set -e

gem install bundler:2.3.26
bundle update --bundler
bundle install --path .bundle
gem install bundler:2.6.5
bundle config set path '.bundle'
bundle install

bundle exec htmlproofer output_dev \
--check-html \
Expand Down
Loading