final class DomBBCodeParser extends SingletonFactory
{
protected array $openTagIdentifiers = [];
+ private \DOMDocument $document;
/**
* Parses bbcodes in the given DOM document.
public function parse(\DOMDocument $document): void
{
$this->openTagIdentifiers = [];
+ $this->document = $document;
foreach ($document->getElementsByTagName('body')->item(0)->childNodes as $node) {
$this->convertBBCodeToMetacodeMarker($node);
}
// get bbcode tags
\preg_match_all($pattern, $node->textContent, $matches);
foreach ($matches[0] as $bbcodeTag) {
- $metaCodeMarker = $this->createMetacodeMarker($node->ownerDocument, $bbcodeTag);
+ $metaCodeMarker = $this->createMetacodeMarker($bbcodeTag);
if ($metaCodeMarker === null) {
continue;
}
}
}
- private function createMetacodeMarker(\DOMDocument $document, string $bbcodeTag): ?\DOMElement
+ private function createMetacodeMarker(string $bbcodeTag): ?\DOMElement
{
$attributes = [];
if (\mb_substr($bbcodeTag, 1, 1) == '/') {
return null;
}
- $metacodeMarker = $document->createElement('woltlab-metacode-marker');
+ $metacodeMarker = $this->document->createElement('woltlab-metacode-marker');
$metacodeMarker->setAttribute('data-source', \base64_encode($bbcodeTag));
if ($isClosingTag) {
if (empty($this->openTagIdentifiers)) {