From a4c43722ccd5ad40b4efe3093f71589e7562e30a Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Nov 2021 20:46:59 +0100 Subject: [PATCH 1/8] Introduce new parser --- src/Parser/CommonMarkParser.php | 50 +++++++++++++++++++ .../Parser/CommonMarkParserTest.php | 49 ++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/Parser/CommonMarkParser.php create mode 100644 tests/Integration/Parser/CommonMarkParserTest.php diff --git a/src/Parser/CommonMarkParser.php b/src/Parser/CommonMarkParser.php new file mode 100644 index 0000000..120fb91 --- /dev/null +++ b/src/Parser/CommonMarkParser.php @@ -0,0 +1,50 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Parser; + +/** + * CommonMarkParser + */ +final class CommonMarkParser +{ + /** + * Create the Parser + */ + public static function create(): CommonMarkParser + { + return new self(); + } + + /** + * Create the Parser + */ + private function __construct() + { + + } + + /** + * parse $test with BBCode to Html + */ + public function parseBbcodeToHtml(string $text): string + { + return $text; + } +} diff --git a/tests/Integration/Parser/CommonMarkParserTest.php b/tests/Integration/Parser/CommonMarkParserTest.php new file mode 100644 index 0000000..cb2bed7 --- /dev/null +++ b/tests/Integration/Parser/CommonMarkParserTest.php @@ -0,0 +1,49 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Tests\Integration\Parser; + +use PHPUnit\Framework\TestCase; +use Youthweb\BBCodeParser\Parser\CommonMarkParser; + +class CommonMarkParserTest extends TestCase +{ + /** + * @dataProvider provideBbcodeAndHtml + * + * @param mixed $text + * @param mixed $expected + */ + public function testParseBbcodeToHtml($text, $expected) + { + $parser = CommonMarkParser::create(); + + $this->assertSame($expected, $parser->parseBbcodeToHtml($text)); + } + + public function provideBbcodeAndHtml() + { + return [ + [ + 'Hello World!', + 'Hello World!', + ], + ]; + } +} From 52ee0e87c353c4ee20eb761dca1dc0e23cdb60d1 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Nov 2021 20:56:11 +0100 Subject: [PATCH 2/8] Parse text with CommonMarkConverter --- composer.json | 1 + src/Parser/CommonMarkParser.php | 8 ++++++-- tests/Integration/Parser/CommonMarkParserTest.php | 7 ++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 2287a44..17488fe 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "cache/void-adapter": "^1.1", "jakeasmith/http_build_url": "^1", "jbbcode/jbbcode": "^1.4", + "league/commonmark": "^2.0", "youthweb/urllinker": "^1.4" }, "require-dev": { diff --git a/src/Parser/CommonMarkParser.php b/src/Parser/CommonMarkParser.php index 120fb91..e960fbe 100644 --- a/src/Parser/CommonMarkParser.php +++ b/src/Parser/CommonMarkParser.php @@ -19,6 +19,8 @@ namespace Youthweb\BBCodeParser\Parser; +use League\CommonMark\CommonMarkConverter; + /** * CommonMarkParser */ @@ -32,12 +34,14 @@ public static function create(): CommonMarkParser return new self(); } + private CommonMarkConverter $converter; + /** * Create the Parser */ private function __construct() { - + $this->converter = new CommonMarkConverter(); } /** @@ -45,6 +49,6 @@ private function __construct() */ public function parseBbcodeToHtml(string $text): string { - return $text; + return $this->converter->convertToHtml($text); } } diff --git a/tests/Integration/Parser/CommonMarkParserTest.php b/tests/Integration/Parser/CommonMarkParserTest.php index cb2bed7..0c26204 100644 --- a/tests/Integration/Parser/CommonMarkParserTest.php +++ b/tests/Integration/Parser/CommonMarkParserTest.php @@ -26,11 +26,8 @@ class CommonMarkParserTest extends TestCase { /** * @dataProvider provideBbcodeAndHtml - * - * @param mixed $text - * @param mixed $expected */ - public function testParseBbcodeToHtml($text, $expected) + public function testParseBbcodeToHtml(string $text, string $expected) { $parser = CommonMarkParser::create(); @@ -42,7 +39,7 @@ public function provideBbcodeAndHtml() return [ [ 'Hello World!', - 'Hello World!', + '

Hello World!

'.\PHP_EOL, ], ]; } From c1561c4e5021df035a835082c7cca8ec237e8ffe Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Nov 2021 21:03:30 +0100 Subject: [PATCH 3/8] Escape all html --- src/Parser/CommonMarkParser.php | 6 +++++- tests/Integration/Parser/CommonMarkParserTest.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Parser/CommonMarkParser.php b/src/Parser/CommonMarkParser.php index e960fbe..f261ae0 100644 --- a/src/Parser/CommonMarkParser.php +++ b/src/Parser/CommonMarkParser.php @@ -41,7 +41,11 @@ public static function create(): CommonMarkParser */ private function __construct() { - $this->converter = new CommonMarkConverter(); + $config = [ + 'html_input' => 'escape', + ]; + + $this->converter = new CommonMarkConverter($config); } /** diff --git a/tests/Integration/Parser/CommonMarkParserTest.php b/tests/Integration/Parser/CommonMarkParserTest.php index 0c26204..df32d33 100644 --- a/tests/Integration/Parser/CommonMarkParserTest.php +++ b/tests/Integration/Parser/CommonMarkParserTest.php @@ -41,6 +41,10 @@ public function provideBbcodeAndHtml() 'Hello World!', '

Hello World!

'.\PHP_EOL, ], + [ + 'Hello World! ', + '

Hello World! </div>

'.\PHP_EOL, + ], ]; } } From eb432816deb9df84079b6db1cca189b647cf2d83 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Nov 2021 21:31:09 +0100 Subject: [PATCH 4/8] Replace CommonMarkConverter with CommonMarkCoreExtension --- src/Parser/CommonMarkParser.php | 21 +++++++++++++++---- .../Parser/CommonMarkParserTest.php | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Parser/CommonMarkParser.php b/src/Parser/CommonMarkParser.php index f261ae0..c1e84a0 100644 --- a/src/Parser/CommonMarkParser.php +++ b/src/Parser/CommonMarkParser.php @@ -19,7 +19,10 @@ namespace Youthweb\BBCodeParser\Parser; -use League\CommonMark\CommonMarkConverter; +use League\CommonMark\Environment\Environment; +use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; +use League\CommonMark\Parser\MarkdownParser; +use League\CommonMark\Renderer\HtmlRenderer; /** * CommonMarkParser @@ -34,7 +37,9 @@ public static function create(): CommonMarkParser return new self(); } - private CommonMarkConverter $converter; + private MarkdownParser $markdownParser; + + private HtmlRenderer $htmlRenderer; /** * Create the Parser @@ -43,9 +48,15 @@ private function __construct() { $config = [ 'html_input' => 'escape', + 'allow_unsafe_links' => false, + 'max_nesting_level' => 5, ]; - $this->converter = new CommonMarkConverter($config); + $environment = new Environment($config); + $environment->addExtension(new CommonMarkCoreExtension()); + + $this->markdownParser = new MarkdownParser($environment); + $this->htmlRenderer = new HtmlRenderer($environment); } /** @@ -53,6 +64,8 @@ private function __construct() */ public function parseBbcodeToHtml(string $text): string { - return $this->converter->convertToHtml($text); + $documentAST = $this->markdownParser->parse($text); + + return $this->htmlRenderer->renderDocument($documentAST)->getContent(); } } diff --git a/tests/Integration/Parser/CommonMarkParserTest.php b/tests/Integration/Parser/CommonMarkParserTest.php index df32d33..d0cb67c 100644 --- a/tests/Integration/Parser/CommonMarkParserTest.php +++ b/tests/Integration/Parser/CommonMarkParserTest.php @@ -45,6 +45,10 @@ public function provideBbcodeAndHtml() 'Hello World! ', '

Hello World! </div>

'.\PHP_EOL, ], + [ + 'Hello World! ', + '

Hello World! <img src="javascript:alert(\'XSS\')">

'.\PHP_EOL, + ], ]; } } From 2d31e06a3f09507d8aa708b5bd86191ef0a8d88b Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 24 Nov 2021 21:58:23 +0100 Subject: [PATCH 5/8] Create BBCodeExtension --- src/Extension/BBCode/BBCodeExtension.php | 44 +++++++++++++++++++ src/Parser/CommonMarkParser.php | 4 +- .../Parser/CommonMarkParserTest.php | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/Extension/BBCode/BBCodeExtension.php diff --git a/src/Extension/BBCode/BBCodeExtension.php b/src/Extension/BBCode/BBCodeExtension.php new file mode 100644 index 0000000..caa1222 --- /dev/null +++ b/src/Extension/BBCode/BBCodeExtension.php @@ -0,0 +1,44 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Extension\BBCode; + +use League\CommonMark\Environment\EnvironmentBuilderInterface; +use League\CommonMark\Extension\ExtensionInterface; +use League\CommonMark\Node as CoreNode; +use League\CommonMark\Parser as CoreParser; +use League\CommonMark\Renderer as CoreRenderer; + +/** + * BBCodeExtension + */ +final class BBCodeExtension implements ExtensionInterface +{ + public function register(EnvironmentBuilderInterface $environment): void + { + $environment + ->addInlineParser(new CoreParser\Inline\NewlineParser(), 200) + + ->addRenderer(CoreNode\Block\Document::class, new CoreRenderer\Block\DocumentRenderer(), 0) + ->addRenderer(CoreNode\Block\Paragraph::class, new CoreRenderer\Block\ParagraphRenderer(), 0) + + ->addRenderer(CoreNode\Inline\Text::class, new CoreRenderer\Inline\TextRenderer(), 0) + ; + } +} diff --git a/src/Parser/CommonMarkParser.php b/src/Parser/CommonMarkParser.php index c1e84a0..7768290 100644 --- a/src/Parser/CommonMarkParser.php +++ b/src/Parser/CommonMarkParser.php @@ -19,8 +19,8 @@ namespace Youthweb\BBCodeParser\Parser; +use Youthweb\BBCodeParser\Extension\BBCode\BBCodeExtension; use League\CommonMark\Environment\Environment; -use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Parser\MarkdownParser; use League\CommonMark\Renderer\HtmlRenderer; @@ -53,7 +53,7 @@ private function __construct() ]; $environment = new Environment($config); - $environment->addExtension(new CommonMarkCoreExtension()); + $environment->addExtension(new BBCodeExtension()); $this->markdownParser = new MarkdownParser($environment); $this->htmlRenderer = new HtmlRenderer($environment); diff --git a/tests/Integration/Parser/CommonMarkParserTest.php b/tests/Integration/Parser/CommonMarkParserTest.php index d0cb67c..b10899d 100644 --- a/tests/Integration/Parser/CommonMarkParserTest.php +++ b/tests/Integration/Parser/CommonMarkParserTest.php @@ -47,7 +47,7 @@ public function provideBbcodeAndHtml() ], [ 'Hello World! ', - '

Hello World! <img src="javascript:alert(\'XSS\')">

'.\PHP_EOL, + '

Hello World! <img src="javascript:alert(\'XSS\')">

'.\PHP_EOL, ], ]; } From 4fcba63595221d791c2ef190cb3a64b4ccf38e12 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Nov 2021 00:20:09 +0100 Subject: [PATCH 6/8] Add inline renderer strong as Markdown style --- src/Extension/BBCode/BBCodeExtension.php | 7 ++ .../Processor/EmphasisDelimiterProcessor.php | 88 +++++++++++++++++++ src/Extension/BBCode/Node/Inline/Strong.php | 50 +++++++++++ .../BBCode/Renderer/Inline/StrongRenderer.php | 62 +++++++++++++ src/Parser/CommonMarkParser.php | 3 + .../Parser/CommonMarkParserTest.php | 4 + 6 files changed, 214 insertions(+) create mode 100644 src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php create mode 100644 src/Extension/BBCode/Node/Inline/Strong.php create mode 100644 src/Extension/BBCode/Renderer/Inline/StrongRenderer.php diff --git a/src/Extension/BBCode/BBCodeExtension.php b/src/Extension/BBCode/BBCodeExtension.php index caa1222..88fd3c2 100644 --- a/src/Extension/BBCode/BBCodeExtension.php +++ b/src/Extension/BBCode/BBCodeExtension.php @@ -1,4 +1,7 @@ @@ -24,6 +27,7 @@ use League\CommonMark\Node as CoreNode; use League\CommonMark\Parser as CoreParser; use League\CommonMark\Renderer as CoreRenderer; +use Youthweb\BBCodeParser\Extension\BBCode\Delimiter\Processor\EmphasisDelimiterProcessor; /** * BBCodeExtension @@ -38,7 +42,10 @@ public function register(EnvironmentBuilderInterface $environment): void ->addRenderer(CoreNode\Block\Document::class, new CoreRenderer\Block\DocumentRenderer(), 0) ->addRenderer(CoreNode\Block\Paragraph::class, new CoreRenderer\Block\ParagraphRenderer(), 0) + ->addRenderer(Node\Inline\Strong::class, new Renderer\Inline\StrongRenderer(), 0) ->addRenderer(CoreNode\Inline\Text::class, new CoreRenderer\Inline\TextRenderer(), 0) ; + + $environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*')); } } diff --git a/src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php b/src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php new file mode 100644 index 0000000..9d7474e --- /dev/null +++ b/src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php @@ -0,0 +1,88 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Extension\BBCode\Delimiter\Processor; + +use League\CommonMark\Delimiter\DelimiterInterface; +use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; +use League\CommonMark\Extension\CommonMark\Node\Inline\Emphasis; +use League\CommonMark\Node\Inline\AbstractStringContainer; +use League\Config\ConfigurationAwareInterface; +use League\Config\ConfigurationInterface; +use Youthweb\BBCodeParser\Extension\BBCode\Node\Inline\Strong; + +final class EmphasisDelimiterProcessor implements DelimiterProcessorInterface +{ + /** @psalm-readonly */ + private string $char; + + /** + * @param string $char The emphasis character to use (typically '*' or '_') + */ + public function __construct(string $char) + { + $this->char = $char; + } + + public function getOpeningCharacter(): string + { + return $this->char; + } + + public function getClosingCharacter(): string + { + return $this->char; + } + + public function getMinLength(): int + { + return 1; + } + + public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int + { + // Calculate actual number of delimiters used from this closer + if ($opener->getLength() >= 2 && $closer->getLength() >= 2) { + return 2; + } + + return 0; + } + + public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void + { + if ($delimiterUse === 2) { + $emphasis = new Strong($this->char . $this->char); + } else { + return; + } + + $next = $opener->next(); + while ($next !== null && $next !== $closer) { + $tmp = $next->next(); + $emphasis->appendChild($next); + $next = $tmp; + } + + $opener->insertAfter($emphasis); + } +} diff --git a/src/Extension/BBCode/Node/Inline/Strong.php b/src/Extension/BBCode/Node/Inline/Strong.php new file mode 100644 index 0000000..4053d10 --- /dev/null +++ b/src/Extension/BBCode/Node/Inline/Strong.php @@ -0,0 +1,50 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Extension\BBCode\Node\Inline; + +use League\CommonMark\Node\Inline\AbstractInline; +use League\CommonMark\Node\Inline\DelimitedInterface; + +final class Strong extends AbstractInline implements DelimitedInterface +{ + private string $delimiter; + + public function __construct(string $delimiter = '::') + { + parent::__construct(); + + $this->delimiter = $delimiter; + } + + public function getOpeningDelimiter(): string + { + return $this->delimiter; + // return '[' . $this->delimiter . ']'; + } + + public function getClosingDelimiter(): string + { + return $this->delimiter; + // return '[/' . $this->delimiter . ']'; + } +} diff --git a/src/Extension/BBCode/Renderer/Inline/StrongRenderer.php b/src/Extension/BBCode/Renderer/Inline/StrongRenderer.php new file mode 100644 index 0000000..13dc67b --- /dev/null +++ b/src/Extension/BBCode/Renderer/Inline/StrongRenderer.php @@ -0,0 +1,62 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Extension\BBCode\Renderer\Inline; + +use League\CommonMark\Node\Node; +use League\CommonMark\Renderer\ChildNodeRendererInterface; +use League\CommonMark\Renderer\NodeRendererInterface; +use League\CommonMark\Util\HtmlElement; +use League\CommonMark\Xml\XmlNodeRendererInterface; +use Youthweb\BBCodeParser\Extension\BBCode\Node\Inline\Strong; + +final class StrongRenderer implements NodeRendererInterface, XmlNodeRendererInterface +{ + /** + * @param Strong $node + * + * {@inheritDoc} + * + * @psalm-suppress MoreSpecificImplementedParamType + */ + public function render(Node $node, ChildNodeRendererInterface $childRenderer): \Stringable + { + Strong::assertInstanceOf($node); + + $attrs = $node->data->get('attributes'); + + return new HtmlElement('b', $attrs, $childRenderer->renderNodes($node->children())); + } + + public function getXmlTagName(Node $node): string + { + return 'b'; + } + + /** + * {@inheritDoc} + */ + public function getXmlAttributes(Node $node): array + { + return []; + } +} diff --git a/src/Parser/CommonMarkParser.php b/src/Parser/CommonMarkParser.php index 7768290..fa0b5e0 100644 --- a/src/Parser/CommonMarkParser.php +++ b/src/Parser/CommonMarkParser.php @@ -1,4 +1,7 @@ diff --git a/tests/Integration/Parser/CommonMarkParserTest.php b/tests/Integration/Parser/CommonMarkParserTest.php index b10899d..f8a58f5 100644 --- a/tests/Integration/Parser/CommonMarkParserTest.php +++ b/tests/Integration/Parser/CommonMarkParserTest.php @@ -49,6 +49,10 @@ public function provideBbcodeAndHtml() 'Hello World! ', '

Hello World! <img src="javascript:alert(\'XSS\')">

'.\PHP_EOL, ], + [ + '**Hello World!**', + '

Hello World!

'.\PHP_EOL, + ], ]; } } From 8b5eb2dfe09d38220ee5205db97317250dcfccf6 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Nov 2021 16:47:58 +0100 Subject: [PATCH 7/8] Replace inline parser with block parser --- src/Extension/BBCode/BBCodeExtension.php | 6 +- .../Processor/EmphasisDelimiterProcessor.php | 88 ------------------- .../BBCode/Node/Block/BBCodeBlock.php | 74 ++++++++++++++++ src/Extension/BBCode/Node/Inline/Strong.php | 50 ----------- .../BBCode/Parser/Block/BoldBlockParser.php | 79 +++++++++++++++++ .../Parser/Block/BoldBlockStartParser.php | 50 +++++++++++ .../BBCodeBlockRenderer.php} | 29 +++--- src/Parser/CommonMarkParser.php | 9 +- .../Parser/CommonMarkParserTest.php | 10 +-- 9 files changed, 236 insertions(+), 159 deletions(-) delete mode 100644 src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php create mode 100644 src/Extension/BBCode/Node/Block/BBCodeBlock.php delete mode 100644 src/Extension/BBCode/Node/Inline/Strong.php create mode 100644 src/Extension/BBCode/Parser/Block/BoldBlockParser.php create mode 100644 src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php rename src/Extension/BBCode/Renderer/{Inline/StrongRenderer.php => Block/BBCodeBlockRenderer.php} (64%) diff --git a/src/Extension/BBCode/BBCodeExtension.php b/src/Extension/BBCode/BBCodeExtension.php index 88fd3c2..5455d2b 100644 --- a/src/Extension/BBCode/BBCodeExtension.php +++ b/src/Extension/BBCode/BBCodeExtension.php @@ -37,15 +37,15 @@ final class BBCodeExtension implements ExtensionInterface public function register(EnvironmentBuilderInterface $environment): void { $environment + ->addBlockStartParser(new Parser\Block\BoldBlockStartParser(), 40) + ->addInlineParser(new CoreParser\Inline\NewlineParser(), 200) ->addRenderer(CoreNode\Block\Document::class, new CoreRenderer\Block\DocumentRenderer(), 0) + ->addRenderer(Node\Block\BBCodeBlock::class, new Renderer\Block\BBCodeBlockRenderer(), 0) ->addRenderer(CoreNode\Block\Paragraph::class, new CoreRenderer\Block\ParagraphRenderer(), 0) - ->addRenderer(Node\Inline\Strong::class, new Renderer\Inline\StrongRenderer(), 0) ->addRenderer(CoreNode\Inline\Text::class, new CoreRenderer\Inline\TextRenderer(), 0) ; - - $environment->addDelimiterProcessor(new EmphasisDelimiterProcessor('*')); } } diff --git a/src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php b/src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php deleted file mode 100644 index 9d7474e..0000000 --- a/src/Extension/BBCode/Delimiter/Processor/EmphasisDelimiterProcessor.php +++ /dev/null @@ -1,88 +0,0 @@ - - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -namespace Youthweb\BBCodeParser\Extension\BBCode\Delimiter\Processor; - -use League\CommonMark\Delimiter\DelimiterInterface; -use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; -use League\CommonMark\Extension\CommonMark\Node\Inline\Emphasis; -use League\CommonMark\Node\Inline\AbstractStringContainer; -use League\Config\ConfigurationAwareInterface; -use League\Config\ConfigurationInterface; -use Youthweb\BBCodeParser\Extension\BBCode\Node\Inline\Strong; - -final class EmphasisDelimiterProcessor implements DelimiterProcessorInterface -{ - /** @psalm-readonly */ - private string $char; - - /** - * @param string $char The emphasis character to use (typically '*' or '_') - */ - public function __construct(string $char) - { - $this->char = $char; - } - - public function getOpeningCharacter(): string - { - return $this->char; - } - - public function getClosingCharacter(): string - { - return $this->char; - } - - public function getMinLength(): int - { - return 1; - } - - public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int - { - // Calculate actual number of delimiters used from this closer - if ($opener->getLength() >= 2 && $closer->getLength() >= 2) { - return 2; - } - - return 0; - } - - public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void - { - if ($delimiterUse === 2) { - $emphasis = new Strong($this->char . $this->char); - } else { - return; - } - - $next = $opener->next(); - while ($next !== null && $next !== $closer) { - $tmp = $next->next(); - $emphasis->appendChild($next); - $next = $tmp; - } - - $opener->insertAfter($emphasis); - } -} diff --git a/src/Extension/BBCode/Node/Block/BBCodeBlock.php b/src/Extension/BBCode/Node/Block/BBCodeBlock.php new file mode 100644 index 0000000..bf89b49 --- /dev/null +++ b/src/Extension/BBCode/Node/Block/BBCodeBlock.php @@ -0,0 +1,74 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Extension\BBCode\Node\Block; + +use League\CommonMark\Node\Block\AbstractBlock; +use League\CommonMark\Node\RawMarkupContainerInterface; + +final class BBCodeBlock extends AbstractBlock implements RawMarkupContainerInterface +{ + public const TYPE_BOLD = 1; + + /** + * @phpstan-var self::TYPE_* $type + */ + private int $type; + + private string $literal = ''; + + /** + * @phpstan-param self::TYPE_* $type + */ + public function __construct(int $type) + { + parent::__construct(); + + $this->type = $type; + } + + /** + * @phpstan-return self::TYPE_* + */ + public function getType(): int + { + return $this->type; + } + + /** + * @phpstan-param self::TYPE_* $type + */ + public function setType(int $type): void + { + $this->type = $type; + } + + public function getLiteral(): string + { + return $this->literal; + } + + public function setLiteral(string $literal): void + { + $this->literal = $literal; + } +} diff --git a/src/Extension/BBCode/Node/Inline/Strong.php b/src/Extension/BBCode/Node/Inline/Strong.php deleted file mode 100644 index 4053d10..0000000 --- a/src/Extension/BBCode/Node/Inline/Strong.php +++ /dev/null @@ -1,50 +0,0 @@ - - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -namespace Youthweb\BBCodeParser\Extension\BBCode\Node\Inline; - -use League\CommonMark\Node\Inline\AbstractInline; -use League\CommonMark\Node\Inline\DelimitedInterface; - -final class Strong extends AbstractInline implements DelimitedInterface -{ - private string $delimiter; - - public function __construct(string $delimiter = '::') - { - parent::__construct(); - - $this->delimiter = $delimiter; - } - - public function getOpeningDelimiter(): string - { - return $this->delimiter; - // return '[' . $this->delimiter . ']'; - } - - public function getClosingDelimiter(): string - { - return $this->delimiter; - // return '[/' . $this->delimiter . ']'; - } -} diff --git a/src/Extension/BBCode/Parser/Block/BoldBlockParser.php b/src/Extension/BBCode/Parser/Block/BoldBlockParser.php new file mode 100644 index 0000000..65db00a --- /dev/null +++ b/src/Extension/BBCode/Parser/Block/BoldBlockParser.php @@ -0,0 +1,79 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Extension\BBCode\Parser\Block; + +use League\CommonMark\Parser\Block\AbstractBlockContinueParser; +use League\CommonMark\Parser\Block\BlockContinue; +use League\CommonMark\Parser\Block\BlockContinueParserInterface; +use League\CommonMark\Parser\Cursor; +use League\CommonMark\Util\RegexHelper; +use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BBCodeBlock; + +final class BoldBlockParser extends AbstractBlockContinueParser +{ + private BBCodeBlock $block; + + private string $content = ''; + + private bool $finished = false; + + /** + * @phpstan-param HtmlBlock::TYPE_* $blockType + */ + public function __construct(int $blockType) + { + $this->block = new BBCodeBlock($blockType); + } + + public function getBlock(): BBCodeBlock + { + return $this->block; + } + + public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue + { + if ($this->finished) { + return BlockContinue::none(); + } + + return BlockContinue::at($cursor); + } + + public function addLine(string $line): void + { + if ($this->content !== '') { + $this->content .= "\n"; + } + + $line = substr($line, 3); + $line = substr($line, 0, -4); + + $this->content .= '

' . $line . '

'; + } + + public function closeBlock(): void + { + $this->block->setLiteral($this->content); + $this->content = ''; + } +} diff --git a/src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php b/src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php new file mode 100644 index 0000000..930e5ca --- /dev/null +++ b/src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php @@ -0,0 +1,50 @@ + + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Youthweb\BBCodeParser\Extension\BBCode\Parser\Block; + +use League\CommonMark\Parser\Block\BlockStart; +use League\CommonMark\Parser\Block\BlockStartParserInterface; +use League\CommonMark\Parser\Cursor; +use League\CommonMark\Parser\MarkdownParserStateInterface; +use League\CommonMark\Util\RegexHelper; +use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BBCodeBlock; + +final class BoldBlockStartParser implements BlockStartParserInterface +{ + public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserState): ?BlockStart + { + if ($cursor->isIndented() || $cursor->getNextNonSpaceCharacter() !== '[') { + return BlockStart::none(); + } + + $tmpCursor = clone $cursor; + $tmpCursor->advanceToNextNonSpaceOrTab(); + $line = $tmpCursor->getSubstring(0, 3); + + if ($line === '[b]') { + return BlockStart::of(new BoldBlockParser(BBCodeBlock::TYPE_BOLD))->at($cursor); + } + + return BlockStart::none(); + } +} diff --git a/src/Extension/BBCode/Renderer/Inline/StrongRenderer.php b/src/Extension/BBCode/Renderer/Block/BBCodeBlockRenderer.php similarity index 64% rename from src/Extension/BBCode/Renderer/Inline/StrongRenderer.php rename to src/Extension/BBCode/Renderer/Block/BBCodeBlockRenderer.php index 13dc67b..b020800 100644 --- a/src/Extension/BBCode/Renderer/Inline/StrongRenderer.php +++ b/src/Extension/BBCode/Renderer/Block/BBCodeBlockRenderer.php @@ -20,36 +20,41 @@ * along with this program. If not, see . */ -namespace Youthweb\BBCodeParser\Extension\BBCode\Renderer\Inline; +namespace Youthweb\BBCodeParser\Extension\BBCode\Renderer\Block; use League\CommonMark\Node\Node; use League\CommonMark\Renderer\ChildNodeRendererInterface; use League\CommonMark\Renderer\NodeRendererInterface; -use League\CommonMark\Util\HtmlElement; +use League\CommonMark\Util\HtmlFilter; use League\CommonMark\Xml\XmlNodeRendererInterface; -use Youthweb\BBCodeParser\Extension\BBCode\Node\Inline\Strong; +use League\Config\ConfigurationAwareInterface; +use League\Config\ConfigurationInterface; +use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BBCodeBlock; -final class StrongRenderer implements NodeRendererInterface, XmlNodeRendererInterface +final class BBCodeBlockRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface { + private ConfigurationInterface $config; + /** - * @param Strong $node + * @param BBCodeBlock $node * * {@inheritDoc} - * - * @psalm-suppress MoreSpecificImplementedParamType */ - public function render(Node $node, ChildNodeRendererInterface $childRenderer): \Stringable + public function render(Node $node, ChildNodeRendererInterface $childRenderer): string { - Strong::assertInstanceOf($node); + BBCodeBlock::assertInstanceOf($node); - $attrs = $node->data->get('attributes'); + return $node->getLiteral(); + } - return new HtmlElement('b', $attrs, $childRenderer->renderNodes($node->children())); + public function setConfiguration(ConfigurationInterface $configuration): void + { + $this->config = $configuration; } public function getXmlTagName(Node $node): string { - return 'b'; + return 'html_block'; } /** diff --git a/src/Parser/CommonMarkParser.php b/src/Parser/CommonMarkParser.php index fa0b5e0..a0563e9 100644 --- a/src/Parser/CommonMarkParser.php +++ b/src/Parser/CommonMarkParser.php @@ -53,6 +53,11 @@ private function __construct() 'html_input' => 'escape', 'allow_unsafe_links' => false, 'max_nesting_level' => 5, + 'renderer' => [ + 'block_separator' => \PHP_EOL, + 'inner_separator' => \PHP_EOL, + 'soft_break' => \PHP_EOL, + ], ]; $environment = new Environment($config); @@ -69,6 +74,8 @@ public function parseBbcodeToHtml(string $text): string { $documentAST = $this->markdownParser->parse($text); - return $this->htmlRenderer->renderDocument($documentAST)->getContent(); + $content = $this->htmlRenderer->renderDocument($documentAST); + + return trim($content->getContent()); } } diff --git a/tests/Integration/Parser/CommonMarkParserTest.php b/tests/Integration/Parser/CommonMarkParserTest.php index f8a58f5..9e9bc0c 100644 --- a/tests/Integration/Parser/CommonMarkParserTest.php +++ b/tests/Integration/Parser/CommonMarkParserTest.php @@ -39,19 +39,19 @@ public function provideBbcodeAndHtml() return [ [ 'Hello World!', - '

Hello World!

'.\PHP_EOL, + '

Hello World!

', ], [ 'Hello World! ', - '

Hello World! </div>

'.\PHP_EOL, + '

Hello World! </div>

', ], [ 'Hello World! ', - '

Hello World! <img src="javascript:alert(\'XSS\')">

'.\PHP_EOL, + '

Hello World! <img src="javascript:alert(\'XSS\')">

', ], [ - '**Hello World!**', - '

Hello World!

'.\PHP_EOL, + '[b]Hello World![/b]', + '

Hello World!

', ], ]; } From 5e9562a6d2362df0962e811aeebe5d238efe51d1 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 25 Nov 2021 23:13:39 +0100 Subject: [PATCH 8/8] change universal BBCodeBlock into specific BoldBlock --- src/Extension/BBCode/BBCodeExtension.php | 2 +- .../Block/{BBCodeBlock.php => BoldBlock.php} | 36 +---------------- .../BBCode/Parser/Block/BoldBlockParser.php | 40 +++++++++++++------ .../Parser/Block/BoldBlockStartParser.php | 9 +++-- ...lockRenderer.php => BoldBlockRenderer.php} | 22 ++++++---- 5 files changed, 49 insertions(+), 60 deletions(-) rename src/Extension/BBCode/Node/Block/{BBCodeBlock.php => BoldBlock.php} (64%) rename src/Extension/BBCode/Renderer/Block/{BBCodeBlockRenderer.php => BoldBlockRenderer.php} (74%) diff --git a/src/Extension/BBCode/BBCodeExtension.php b/src/Extension/BBCode/BBCodeExtension.php index 5455d2b..91e5e86 100644 --- a/src/Extension/BBCode/BBCodeExtension.php +++ b/src/Extension/BBCode/BBCodeExtension.php @@ -42,7 +42,7 @@ public function register(EnvironmentBuilderInterface $environment): void ->addInlineParser(new CoreParser\Inline\NewlineParser(), 200) ->addRenderer(CoreNode\Block\Document::class, new CoreRenderer\Block\DocumentRenderer(), 0) - ->addRenderer(Node\Block\BBCodeBlock::class, new Renderer\Block\BBCodeBlockRenderer(), 0) + ->addRenderer(Node\Block\BoldBlock::class, new Renderer\Block\BoldBlockRenderer(), 0) ->addRenderer(CoreNode\Block\Paragraph::class, new CoreRenderer\Block\ParagraphRenderer(), 0) ->addRenderer(CoreNode\Inline\Text::class, new CoreRenderer\Inline\TextRenderer(), 0) diff --git a/src/Extension/BBCode/Node/Block/BBCodeBlock.php b/src/Extension/BBCode/Node/Block/BoldBlock.php similarity index 64% rename from src/Extension/BBCode/Node/Block/BBCodeBlock.php rename to src/Extension/BBCode/Node/Block/BoldBlock.php index bf89b49..69715eb 100644 --- a/src/Extension/BBCode/Node/Block/BBCodeBlock.php +++ b/src/Extension/BBCode/Node/Block/BoldBlock.php @@ -24,44 +24,12 @@ use League\CommonMark\Node\Block\AbstractBlock; use League\CommonMark\Node\RawMarkupContainerInterface; +use League\CommonMark\Node\StringContainerInterface; -final class BBCodeBlock extends AbstractBlock implements RawMarkupContainerInterface +final class BoldBlock extends AbstractBlock implements RawMarkupContainerInterface, StringContainerInterface { - public const TYPE_BOLD = 1; - - /** - * @phpstan-var self::TYPE_* $type - */ - private int $type; - private string $literal = ''; - /** - * @phpstan-param self::TYPE_* $type - */ - public function __construct(int $type) - { - parent::__construct(); - - $this->type = $type; - } - - /** - * @phpstan-return self::TYPE_* - */ - public function getType(): int - { - return $this->type; - } - - /** - * @phpstan-param self::TYPE_* $type - */ - public function setType(int $type): void - { - $this->type = $type; - } - public function getLiteral(): string { return $this->literal; diff --git a/src/Extension/BBCode/Parser/Block/BoldBlockParser.php b/src/Extension/BBCode/Parser/Block/BoldBlockParser.php index 65db00a..3711b75 100644 --- a/src/Extension/BBCode/Parser/Block/BoldBlockParser.php +++ b/src/Extension/BBCode/Parser/Block/BoldBlockParser.php @@ -25,35 +25,42 @@ use League\CommonMark\Parser\Block\AbstractBlockContinueParser; use League\CommonMark\Parser\Block\BlockContinue; use League\CommonMark\Parser\Block\BlockContinueParserInterface; +use League\CommonMark\Parser\Block\BlockContinueParserWithInlinesInterface; use League\CommonMark\Parser\Cursor; +use League\CommonMark\Parser\InlineParserEngineInterface; use League\CommonMark\Util\RegexHelper; -use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BBCodeBlock; +use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BoldBlock; -final class BoldBlockParser extends AbstractBlockContinueParser +final class BoldBlockParser extends AbstractBlockContinueParser implements BlockContinueParserWithInlinesInterface { - private BBCodeBlock $block; + private BoldBlock $block; private string $content = ''; private bool $finished = false; - /** - * @phpstan-param HtmlBlock::TYPE_* $blockType - */ - public function __construct(int $blockType) + public function __construct() { - $this->block = new BBCodeBlock($blockType); + $this->block = new BoldBlock(); } - public function getBlock(): BBCodeBlock + public function getBlock(): BoldBlock { return $this->block; } public function tryContinue(Cursor $cursor, BlockContinueParserInterface $activeBlockParser): ?BlockContinue { - if ($this->finished) { - return BlockContinue::none(); + if ($cursor->getNextNonSpaceCharacter() !== '[') { + return BlockContinue::at($cursor); + } + + $tmpCursor = clone $cursor; + $tmpCursor->advanceToNextNonSpaceOrTab(); + $line = $tmpCursor->getSubstring(0, 4); + + if ($line === '[/b]') { + return BlockStart::none(); } return BlockContinue::at($cursor); @@ -65,10 +72,9 @@ public function addLine(string $line): void $this->content .= "\n"; } - $line = substr($line, 3); $line = substr($line, 0, -4); - $this->content .= '

' . $line . '

'; + $this->content .= $line; } public function closeBlock(): void @@ -76,4 +82,12 @@ public function closeBlock(): void $this->block->setLiteral($this->content); $this->content = ''; } + + /** + * Parse any inlines inside of the current block + */ + public function parseInlines(InlineParserEngineInterface $inlineParser): void + { + // #TODO + } } diff --git a/src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php b/src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php index 930e5ca..507bc34 100644 --- a/src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php +++ b/src/Extension/BBCode/Parser/Block/BoldBlockStartParser.php @@ -27,7 +27,6 @@ use League\CommonMark\Parser\Cursor; use League\CommonMark\Parser\MarkdownParserStateInterface; use League\CommonMark\Util\RegexHelper; -use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BBCodeBlock; final class BoldBlockStartParser implements BlockStartParserInterface { @@ -41,10 +40,12 @@ public function tryStart(Cursor $cursor, MarkdownParserStateInterface $parserSta $tmpCursor->advanceToNextNonSpaceOrTab(); $line = $tmpCursor->getSubstring(0, 3); - if ($line === '[b]') { - return BlockStart::of(new BoldBlockParser(BBCodeBlock::TYPE_BOLD))->at($cursor); + if ($line !== '[b]') { + return BlockStart::none(); } - return BlockStart::none(); + $cursor->advanceBy(3); + + return BlockStart::of(new BoldBlockParser())->at($cursor); } } diff --git a/src/Extension/BBCode/Renderer/Block/BBCodeBlockRenderer.php b/src/Extension/BBCode/Renderer/Block/BoldBlockRenderer.php similarity index 74% rename from src/Extension/BBCode/Renderer/Block/BBCodeBlockRenderer.php rename to src/Extension/BBCode/Renderer/Block/BoldBlockRenderer.php index b020800..750dc00 100644 --- a/src/Extension/BBCode/Renderer/Block/BBCodeBlockRenderer.php +++ b/src/Extension/BBCode/Renderer/Block/BoldBlockRenderer.php @@ -25,26 +25,32 @@ use League\CommonMark\Node\Node; use League\CommonMark\Renderer\ChildNodeRendererInterface; use League\CommonMark\Renderer\NodeRendererInterface; -use League\CommonMark\Util\HtmlFilter; +use League\CommonMark\Util\HtmlElement; use League\CommonMark\Xml\XmlNodeRendererInterface; use League\Config\ConfigurationAwareInterface; use League\Config\ConfigurationInterface; -use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BBCodeBlock; +use Youthweb\BBCodeParser\Extension\BBCode\Node\Block\BoldBlock; -final class BBCodeBlockRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface +final class BoldBlockRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface { private ConfigurationInterface $config; /** - * @param BBCodeBlock $node + * @param BoldBlock $node * * {@inheritDoc} */ - public function render(Node $node, ChildNodeRendererInterface $childRenderer): string + public function render(Node $node, ChildNodeRendererInterface $childRenderer): HtmlElement { - BBCodeBlock::assertInstanceOf($node); + BoldBlock::assertInstanceOf($node); - return $node->getLiteral(); + $innerHtml = $childRenderer->renderNodes($node->children()); + + if ($innerHtml === '') { + $innerHtml = $node->getLiteral(); + } + + return new HtmlElement('b', [], $innerHtml); } public function setConfiguration(ConfigurationInterface $configuration): void @@ -54,7 +60,7 @@ public function setConfiguration(ConfigurationInterface $configuration): void public function getXmlTagName(Node $node): string { - return 'html_block'; + return 'strong'; } /**