Primo Committ

This commit is contained in:
paoloar77
2024-05-07 12:17:25 +02:00
commit e73d0e5113
7204 changed files with 884387 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\BlockQuote;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
final class BlockQuoteRenderer implements BlockRendererInterface
{
/**
* @param BlockQuote $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof BlockQuote)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$attrs = $block->getData('attributes', []);
$filling = $htmlRenderer->renderBlocks($block->children());
if ($filling === '') {
return new HtmlElement('blockquote', $attrs, $htmlRenderer->getOption('inner_separator', "\n"));
}
return new HtmlElement(
'blockquote',
$attrs,
$htmlRenderer->getOption('inner_separator', "\n") . $filling . $htmlRenderer->getOption('inner_separator', "\n")
);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
interface BlockRendererInterface
{
/**
* @param AbstractBlock $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement|string|null
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false);
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\Document;
use League\CommonMark\ElementRendererInterface;
final class DocumentRenderer implements BlockRendererInterface
{
/**
* @param Document $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return string
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof Document)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$wholeDoc = $htmlRenderer->renderBlocks($block->children());
return $wholeDoc === '' ? '' : $wholeDoc . "\n";
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\FencedCode;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
use League\CommonMark\Util\Xml;
final class FencedCodeRenderer implements BlockRendererInterface
{
/**
* @param FencedCode $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof FencedCode)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$attrs = $block->getData('attributes', []);
$infoWords = $block->getInfoWords();
if (\count($infoWords) !== 0 && \strlen($infoWords[0]) !== 0) {
$attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' : '';
$attrs['class'] .= 'language-' . $infoWords[0];
}
return new HtmlElement(
'pre',
[],
new HtmlElement('code', $attrs, Xml::escape($block->getStringContent()))
);
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\Heading;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
final class HeadingRenderer implements BlockRendererInterface
{
/**
* @param Heading $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof Heading)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$tag = 'h' . $block->getLevel();
$attrs = $block->getData('attributes', []);
return new HtmlElement($tag, $attrs, $htmlRenderer->renderInlines($block->children()));
}
}

View File

@@ -0,0 +1,59 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\HtmlBlock;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\EnvironmentInterface;
use League\CommonMark\Util\ConfigurationAwareInterface;
use League\CommonMark\Util\ConfigurationInterface;
final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface
{
/**
* @var ConfigurationInterface
*/
protected $config;
/**
* @param HtmlBlock $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return string
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof HtmlBlock)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) {
return '';
}
if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) {
return \htmlspecialchars($block->getStringContent(), \ENT_NOQUOTES);
}
return $block->getStringContent();
}
public function setConfiguration(ConfigurationInterface $configuration)
{
$this->config = $configuration;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\IndentedCode;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
use League\CommonMark\Util\Xml;
final class IndentedCodeRenderer implements BlockRendererInterface
{
/**
* @param IndentedCode $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof IndentedCode)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$attrs = $block->getData('attributes', []);
return new HtmlElement(
'pre',
[],
new HtmlElement('code', $attrs, Xml::escape($block->getStringContent()))
);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\ListBlock;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
final class ListBlockRenderer implements BlockRendererInterface
{
/**
* @param ListBlock $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof ListBlock)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$listData = $block->getListData();
$tag = $listData->type === ListBlock::TYPE_BULLET ? 'ul' : 'ol';
$attrs = $block->getData('attributes', []);
if ($listData->start !== null && $listData->start !== 1) {
$attrs['start'] = (string) $listData->start;
}
return new HtmlElement(
$tag,
$attrs,
$htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks(
$block->children(),
$block->isTight()
) . $htmlRenderer->getOption('inner_separator', "\n")
);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\ListItem;
use League\CommonMark\Block\Element\Paragraph;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\Extension\TaskList\TaskListItemMarker;
use League\CommonMark\HtmlElement;
final class ListItemRenderer implements BlockRendererInterface
{
/**
* @param ListItem $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return string
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof ListItem)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$contents = $htmlRenderer->renderBlocks($block->children(), $inTightList);
if (\substr($contents, 0, 1) === '<' && !$this->startsTaskListItem($block)) {
$contents = "\n" . $contents;
}
if (\substr($contents, -1, 1) === '>') {
$contents .= "\n";
}
$attrs = $block->getData('attributes', []);
$li = new HtmlElement('li', $attrs, $contents);
return $li;
}
private function startsTaskListItem(ListItem $block): bool
{
$firstChild = $block->firstChild();
return $firstChild instanceof Paragraph && $firstChild->firstChild() instanceof TaskListItemMarker;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\Paragraph;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
final class ParagraphRenderer implements BlockRendererInterface
{
/**
* @param Paragraph $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement|string
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof Paragraph)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
if ($inTightList) {
return $htmlRenderer->renderInlines($block->children());
}
$attrs = $block->getData('attributes', []);
return new HtmlElement('p', $attrs, $htmlRenderer->renderInlines($block->children()));
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
* - (c) John MacFarlane
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Block\Renderer;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\ThematicBreak;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;
final class ThematicBreakRenderer implements BlockRendererInterface
{
/**
* @param ThematicBreak $block
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement
*/
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
{
if (!($block instanceof ThematicBreak)) {
throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
}
$attrs = $block->getData('attributes', []);
return new HtmlElement('hr', $attrs, '', true);
}
}