mirror of
https://github.com/php-fig/www.php-fig.org.git
synced 2026-03-24 06:52:15 +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
35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?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);
|
|
}
|
|
}
|