mirror of
https://github.com/php-fig/www.php-fig.org.git
synced 2026-03-23 22:42:13 +01:00
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
40 lines
928 B
PHP
40 lines
928 B
PHP
<?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';
|
|
}
|
|
}
|