From e2ff821fcccfe96ea257baea587c4c2dbdfc29b8 Mon Sep 17 00:00:00 2001
From: Gerben Oolbekkink
Date: Thu, 16 Mar 2023 22:47:15 +0100
Subject: [PATCH 1/5] Add type hints
---
src/BbEnv.php | 3 +-
src/BbException.php | 3 +-
src/BbTag.php | 38 ++++++++++++----------
src/DefaultParser.php | 61 +++++++++++++++++++-----------------
src/Parser.php | 14 +++++----
src/internal/BbError.php | 24 ++++++++------
src/internal/BbString.php | 18 +++++------
src/tag/BbBold.php | 35 ++++++++++++---------
src/tag/BbClear.php | 20 +++++++-----
src/tag/BbCode.php | 33 ++++++++++++-------
src/tag/BbCommentaar.php | 22 ++++++++-----
src/tag/BbDiv.php | 27 +++++++++-------
src/tag/BbEmail.php | 17 ++++++----
src/tag/BbHeading.php | 42 +++++++++++++++----------
src/tag/BbHorizontalRule.php | 32 +++++++++++--------
src/tag/BbItalic.php | 22 +++++++------
src/tag/BbLeet.php | 27 +++++++++-------
src/tag/BbLishort.php | 25 +++++++++------
src/tag/BbList.php | 22 +++++++------
src/tag/BbListItem.php | 25 +++++++++------
src/tag/BbMe.php | 31 +++++++++---------
src/tag/BbNewline.php | 25 +++++++++------
src/tag/BbNobold.php | 19 ++++++-----
src/tag/BbNode.php | 37 ++++++----------------
src/tag/BbQuote.php | 34 +++++++++++---------
src/tag/BbStrikethrough.php | 22 +++++++------
src/tag/BbSubscript.php | 19 ++++++-----
src/tag/BbSuperscript.php | 19 ++++++-----
src/tag/BbTable.php | 39 +++++++++++++----------
src/tag/BbTableCell.php | 31 +++++++++---------
src/tag/BbTableHeader.php | 19 ++++++-----
src/tag/BbTableRow.php | 19 ++++++-----
src/tag/BbUnderline.php | 22 ++++++++-----
33 files changed, 481 insertions(+), 365 deletions(-)
diff --git a/src/BbEnv.php b/src/BbEnv.php
index 47597e7..d7c8e3a 100644
--- a/src/BbEnv.php
+++ b/src/BbEnv.php
@@ -6,7 +6,8 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbEnv {
+class BbEnv
+{
/**
* @var string One of default, light, preview, plain
*/
diff --git a/src/BbException.php b/src/BbException.php
index a7b60bd..5b9a946 100644
--- a/src/BbException.php
+++ b/src/BbException.php
@@ -8,6 +8,7 @@
* @author G.J.W. Oolbekkink
* @since 06/07/2019
*/
-class BbException extends Exception {
+class BbException extends Exception
+{
}
diff --git a/src/BbTag.php b/src/BbTag.php
index 8e8916f..088449b 100644
--- a/src/BbTag.php
+++ b/src/BbTag.php
@@ -44,7 +44,7 @@ public function setEnv($env)
$this->env = $env;
}
- public function isAllowed()
+ public function isAllowed(): bool
{
return true;
}
@@ -54,12 +54,12 @@ public function isAllowed()
* @return mixed
* @throws BbException
*/
- abstract public function parse($arguments = []);
+ abstract public function parse(array $arguments = []): void;
/**
* @return BbNode[]|null
*/
- public function getChildren()
+ public function getChildren(): ?array
{
return $this->children;
}
@@ -76,7 +76,7 @@ public function setChildren($children)
* @return string
* @throws BbException
*/
- public function getContent()
+ public function getContent(): string
{
if ($this->content === null) {
throw new BbException("Cannot read content during parsing");
@@ -85,7 +85,7 @@ public function getContent()
return $this->content;
}
- public function setContent($content)
+ public function setContent(string $content): void
{
$this->content = $content;
}
@@ -93,22 +93,21 @@ public function setContent($content)
/**
* ParseLight defaults to parse
*
- * @return mixed
* @throws BbException
*/
- public function renderLight()
+ public function renderLight(): string
{
return $this->render();
}
- abstract public function render();
+ abstract public function render(): string;
/**
* render preview will strip html tags by default.
*
* @return string
*/
- public function renderPreview()
+ public function renderPreview(): string
{
return strip_tags($this->render());
}
@@ -118,7 +117,7 @@ public function renderPreview()
*
* @return string
*/
- public function renderPlain()
+ public function renderPlain(): string
{
return strip_tags($this->render());
}
@@ -128,10 +127,10 @@ public function renderPlain()
*
* [tag=123] or [tag]123[/tag]
*
- * @param $arguments
+ * @param string[] $arguments
* @return string
*/
- protected function readMainArgument($arguments)
+ protected function readMainArgument(array $arguments): string
{
if (is_array($this->getTagName())) {
foreach ($this->getTagName() as $tagName) {
@@ -152,6 +151,9 @@ protected function readMainArgument($arguments)
}
}
+ /**
+ * @return string|string[]
+ */
abstract public static function getTagName();
/**
@@ -161,10 +163,11 @@ abstract public static function getTagName();
*
* @param string[] $forbidden Tag names that cannot exist in this tag.
*/
- protected function readContent($forbidden = [], $parse_bb = true)
+ protected function readContent(array $forbidden = [], bool $parse_bb = true): void
{
- if ($this->content != NULL)
+ if ($this->content != null) {
throw new Error("Can not call readContent twice on the same tag");
+ }
$stoppers = $this->getStoppers();
$parse_bb_state_before = $this->parser->bb_mode;
$this->parser->bb_mode &= $parse_bb;
@@ -175,7 +178,10 @@ protected function readContent($forbidden = [], $parse_bb = true)
$this->children = $result;
}
- protected function getStoppers()
+ /**
+ * @return string[]
+ */
+ protected function getStoppers(): array
{
$stoppers = [];
@@ -190,7 +196,7 @@ protected function getStoppers()
return $stoppers;
}
- private function createStopper($tagName)
+ private function createStopper($tagName): string
{
return "[/$tagName]";
}
diff --git a/src/DefaultParser.php b/src/DefaultParser.php
index 82ad794..78df4bc 100644
--- a/src/DefaultParser.php
+++ b/src/DefaultParser.php
@@ -1,4 +1,5 @@
* @since 06/07/2019
*/
-final class DefaultParser extends Parser {
- protected $tags = [
- BbBold::class,
- BbClear::class,
- BbCode::class,
- BbCommentaar::class,
- BbDiv::class,
- BbEmail::class,
- BbHeading::class,
- BbHorizontalRule::class,
- BbItalic::class,
- BbLeet::class,
- BbLishort::class,
- BbListItem::class,
- BbMe::class,
- BbNewline::class,
- BbNobold::class,
- BbQuote::class,
- BbStrikethrough::class,
- BbSubscript::class,
- BbSuperscript::class,
- BbTable::class,
- BbTableCell::class,
- BbTableHeader::class,
- BbTableRow::class,
- BbList::class,
- BbUnderline::class,
- ];
+final class DefaultParser extends Parser
+{
+ public function getTags()
+ {
+ return [
+ BbBold::class,
+ BbClear::class,
+ BbCode::class,
+ BbCommentaar::class,
+ BbDiv::class,
+ BbEmail::class,
+ BbHeading::class,
+ BbHorizontalRule::class,
+ BbItalic::class,
+ BbLeet::class,
+ BbLishort::class,
+ BbListItem::class,
+ BbMe::class,
+ BbNewline::class,
+ BbNobold::class,
+ BbQuote::class,
+ BbStrikethrough::class,
+ BbSubscript::class,
+ BbSuperscript::class,
+ BbTable::class,
+ BbTableCell::class,
+ BbTableHeader::class,
+ BbTableRow::class,
+ BbList::class,
+ BbUnderline::class,
+ ];
+ }
}
diff --git a/src/Parser.php b/src/Parser.php
index e71214a..ae07a38 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -124,7 +124,7 @@ public function __construct($env = null) {
$this->env = $env;
- foreach ($this->tags as $tag) {
+ foreach ($this->getTags() as $tag) {
if (is_array($tag::getTagName())) {
foreach ($tag::getTagName() as $tagName) {
$this->registry[$tagName] = $tag;
@@ -139,6 +139,8 @@ public function __construct($env = null) {
}
}
+ public abstract function getTags();
+
/**
* Transform BB code to HTML code.
*
@@ -469,12 +471,11 @@ private function getTag($fullTag) {
* return arguments of a tag in array-form
*
* When supplied with a full tag ([h=5] or [img=blah.gif w=5 h=10]), return array with argument/value as key/value pairs
- * @return array
+ * @return string[]
* @param string $fullTag The full tag to get the arguments from
*/
- private function getArguments($fullTag) {
-
- $argument_array = Array();
+ private function getArguments(string $fullTag): array {
+ $argument_array = [];
$tag = substr($fullTag, 1, strlen($fullTag) - 2);
$argList = explode(' ', $tag);
$i = 0;
@@ -504,7 +505,8 @@ private function getArguments($fullTag) {
return $argument_array;
}
- protected function createTagInstance(string $tag, Parser $parser, $env) {
+ protected function createTagInstance(string $tag, Parser $parser, $env): BbTag
+ {
/** @var BbTag $tagInstance */
$tagInstance = new $tag($parser, $env);
$tagInstance->setParser($parser);
diff --git a/src/internal/BbError.php b/src/internal/BbError.php
index cf44dca..e744e94 100644
--- a/src/internal/BbError.php
+++ b/src/internal/BbError.php
@@ -4,6 +4,7 @@
namespace CsrDelft\bb\internal;
+use CsrDelft\bb\BbException;
use CsrDelft\bb\tag\BbNode;
class BbError implements BbNode
@@ -18,43 +19,46 @@ public function __construct(string $error)
$this->error = $error;
}
- public function isAllowed()
+ public function isAllowed(): bool
{
return true;
}
- public function render()
+ public function render(): string
{
return $this->error;
}
- public function getChildren()
+ public function getChildren(): array
{
return [];
}
- public function setContent($content)
+ public function setContent($content): void
{
// Nop
}
- public function getContent()
+ /**
+ * @throws BbException
+ */
+ public function getContent(): string
{
- return null;
+ throw new BbException("Error heeft geen content");
}
- public function renderPlain()
+ public function renderPlain(): string
{
return $this->render();
}
- public function renderPreview()
+ public function renderPreview(): string
{
return $this->render();
}
- public function renderLight()
+ public function renderLight(): string
{
return $this->render();
}
-}
\ No newline at end of file
+}
diff --git a/src/internal/BbString.php b/src/internal/BbString.php
index b1cb5d0..44841e5 100644
--- a/src/internal/BbString.php
+++ b/src/internal/BbString.php
@@ -17,43 +17,43 @@ public function __construct(string $string)
$this->string = $string;
}
- public function isAllowed()
+ public function isAllowed(): bool
{
return true;
}
- public function render()
+ public function render(): string
{
return $this->string;
}
- public function getChildren()
+ public function getChildren(): array
{
return [];
}
- public function setContent($content)
+ public function setContent($content): void
{
// Nop
}
- public function getContent()
+ public function getContent(): string
{
return $this->string;
}
- public function renderPlain()
+ public function renderPlain(): string
{
return $this->render();
}
- public function renderPreview()
+ public function renderPreview(): string
{
return $this->render();
}
- public function renderLight()
+ public function renderLight(): string
{
return $this->render();
}
-}
\ No newline at end of file
+}
diff --git a/src/tag/BbBold.php b/src/tag/BbBold.php
index c638097..d72ee64 100644
--- a/src/tag/BbBold.php
+++ b/src/tag/BbBold.php
@@ -8,21 +8,25 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbBold extends BbTag {
+class BbBold extends BbTag
+{
private $disabled = false;
- public static function getTagName() {
- return 'b';
- }
+ public static function getTagName(): string
+ {
+ return 'b';
+ }
- public function parse($arguments = []) {
- if ($this->env->nobold === true && $this->env->quote_level == 0) {
- $this->disabled = true;
+ public function parse($arguments = []): void
+ {
+ if ($this->env->nobold === true && $this->env->quote_level == 0) {
+ $this->disabled = true;
}
$this->readContent();
}
- public function renderPlain() {
+ public function renderPlain(): string
+ {
if ($this->disabled) {
return $this->getContent();
} else {
@@ -30,11 +34,12 @@ public function renderPlain() {
}
}
- public function render() {
- if ($this->disabled) {
- return $this->getContent();
- } else {
- return '' . $this->getContent() . '';
- }
- }
+ public function render(): string
+ {
+ if ($this->disabled) {
+ return $this->getContent();
+ } else {
+ return '' . $this->getContent() . '';
+ }
+ }
}
diff --git a/src/tag/BbClear.php b/src/tag/BbClear.php
index a57ba02..b8f50a4 100644
--- a/src/tag/BbClear.php
+++ b/src/tag/BbClear.php
@@ -8,25 +8,29 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbClear extends BbTag {
+class BbClear extends BbTag
+{
/**
* @var string
*/
private $clearClass;
- public static function getTagName() {
- return 'clear';
- }
+ public static function getTagName(): string
+ {
+ return 'clear';
+ }
- public function parse($arguments = []) {
+ public function parse($arguments = []): void
+ {
$this->clearClass = 'clear';
if (isset($arguments['clear']) && ($arguments['clear'] === 'left' || $arguments['clear'] === 'right')) {
$this->clearClass .= '-' . $arguments['clear'];
}
}
- public function render() {
- return '';
- }
+ public function render(): string
+ {
+ return '';
+ }
}
diff --git a/src/tag/BbCode.php b/src/tag/BbCode.php
index c503649..fa216f9 100644
--- a/src/tag/BbCode.php
+++ b/src/tag/BbCode.php
@@ -7,33 +7,44 @@
/**
* Code
*
- * @author G.J.W. Oolbekkink
- * @since 27/03/2019
* @param optional String $arguments['code'] Description of code type
*
+ * @since 27/03/2019
+ * @author G.J.W. Oolbekkink
* @example [code=PHP]phpinfo();[/code]
*/
-class BbCode extends BbTag {
+class BbCode extends BbTag
+{
/**
* @var string
*/
private $code;
- public static function getTagName() {
- return 'code';
- }
+ public static function getTagName(): string
+ {
+ return 'code';
+ }
- public function parse($arguments = []) {
+ public function parse($arguments = []): void
+ {
$this->readContent(['br'], false);
$this->code = isset($arguments['code']) ? $arguments['code'] . ' ' : '';
}
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return "$this->code\n\t" . str_replace("\n", "\n\t", $this->getContent());
}
- public function render() {
- return '' . $this->code . 'code:' . $this->getContent() . '
';
- }
+ public function render(): string
+ {
+ return vsprintf(
+ "",
+ [
+ $this->code,
+ $this->getContent()
+ ]
+ );
+ }
}
diff --git a/src/tag/BbCommentaar.php b/src/tag/BbCommentaar.php
index d8759a8..e27a3ea 100644
--- a/src/tag/BbCommentaar.php
+++ b/src/tag/BbCommentaar.php
@@ -8,15 +8,21 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbCommentaar extends BbTag {
+class BbCommentaar extends BbTag
+{
- public static function getTagName() {
- return 'commentaar';
- }
- public function parse($arguments = []) {
+ public static function getTagName(): string
+ {
+ return 'commentaar';
+ }
+
+ public function parse($arguments = []): void
+ {
$this->readContent([], false);
}
- public function render() {
- return '';
- }
+
+ public function render(): string
+ {
+ return '';
+ }
}
diff --git a/src/tag/BbDiv.php b/src/tag/BbDiv.php
index e8b7d15..93a151c 100644
--- a/src/tag/BbDiv.php
+++ b/src/tag/BbDiv.php
@@ -5,19 +5,19 @@
use CsrDelft\bb\BbTag;
/**
- * @author G.J.W. Oolbekkink
- * @since 27/03/2019
- *
* @param string optional $arguments['class'] Class attribute
* @param boolean optional $arguments['clear'] CSS clear: both
* @param string optional $arguments['float'] CSS float left or right
* @param integer optional $arguments['w'] CSS width in pixels
* @param integer optional $arguments['h'] CSS height in pixels
*
+ * @since 27/03/2019
+ *
+ * @author G.J.W. Oolbekkink
* @example [div class=special clear float=left w=20 h=50]...[/div]
*/
-class BbDiv extends BbTag {
-
+class BbDiv extends BbTag
+{
/**
* @var string
*/
@@ -31,11 +31,13 @@ class BbDiv extends BbTag {
*/
private $title;
- public static function getTagName() {
- return 'div';
- }
+ public static function getTagName(): string
+ {
+ return 'div';
+ }
- public function parse($arguments = []) {
+ public function parse($arguments = []): void
+ {
$this->readContent();
$this->class = '';
if (isset($arguments['class'])) {
@@ -67,7 +69,8 @@ public function parse($arguments = []) {
}
}
- public function render($arguments = []) {
- return 'class . $this->style . $this->title . '>' . $this->getContent() . '
';
- }
+ public function render($arguments = []): string
+ {
+ return 'class . $this->style . $this->title . '>' . $this->getContent() . '
';
+ }
}
diff --git a/src/tag/BbEmail.php b/src/tag/BbEmail.php
index ea9c1b6..88f5d5e 100644
--- a/src/tag/BbEmail.php
+++ b/src/tag/BbEmail.php
@@ -15,17 +15,20 @@
* @example [email]noreply@csrdelft.nl[/email]
* @example [email=noreply@csrdelft.nl spamsafe]text[/email]
*/
-class BbEmail extends BbTag {
+class BbEmail extends BbTag
+{
private $text;
private $email;
private $mailto;
- public static function getTagName() {
+ public static function getTagName(): string
+ {
return 'email';
}
- public function render($arguments = []) {
+ public function render($arguments = []): string
+ {
if (!empty($this->email)) {
$html = '' . $this->text . '';
@@ -39,7 +42,8 @@ public function render($arguments = []) {
return $html;
}
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return $this->text . " <" . $this->email . ">";
}
@@ -49,7 +53,8 @@ public function renderPlain() {
*
* @return bool
*/
- function emailLike($email) {
+ private function emailLike($email): bool
+ {
if (empty($email)) {
return false;
}
@@ -60,7 +65,7 @@ function emailLike($email) {
* @param array $arguments
* @return array
*/
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->mailto = array_shift($this->parser->parseArray);
$endtag = array_shift($this->parser->parseArray);
diff --git a/src/tag/BbHeading.php b/src/tag/BbHeading.php
index bffe1d1..ea8b96d 100644
--- a/src/tag/BbHeading.php
+++ b/src/tag/BbHeading.php
@@ -7,14 +7,15 @@
/**
* Heading
*
- * @author G.J.W. Oolbekkink
- * @since 27/03/2019
* @param Integer $arguments ['h'] Heading level (1-6)
* @param string optional $arguments['id'] ID attribute
*
+ * @author G.J.W. Oolbekkink
+ * @since 27/03/2019
* @example [h=1 id=special]Heading[/h]
*/
-class BbHeading extends BbTag {
+class BbHeading extends BbTag
+{
private $id;
/**
@@ -22,10 +23,13 @@ class BbHeading extends BbTag {
*/
private $heading_level = 1;
- public static function getTagName() {
- return 'h';
- }
- public function parse($arguments= []) {
+ public static function getTagName(): string
+ {
+ return 'h';
+ }
+
+ public function parse($arguments = []): void
+ {
if (isset($arguments['id'])) {
$this->id = $arguments['id'];
}
@@ -46,22 +50,26 @@ public function parse($arguments= []) {
}
}
- public function getHeadingLevel() {
+ public function getHeadingLevel(): int
+ {
return $this->heading_level;
}
- public function render() {
- $id = $this->id == null ? '' : ' id="' . htmlspecialchars($this->id) . '"';
- $text = "heading_level$id class=\"bb-tag-h\">{$this->getContent()}heading_level>\n\n";
- return $text;
- }
+ public function render(): string
+ {
+ $id = $this->id == null ? '' : ' id="' . htmlspecialchars($this->id) . '"';
+ $text = "heading_level$id class=\"bb-tag-h\">{$this->getContent()}heading_level>\n\n";
+ return $text;
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
$lines = explode("\n", $this->getContent());
return $this->getContent() . "\n" . str_repeat("-", strlen(end($lines)));
}
- public static function isParagraphLess() {
- return true;
- }
+ public static function isParagraphLess(): bool
+ {
+ return true;
+ }
}
diff --git a/src/tag/BbHorizontalRule.php b/src/tag/BbHorizontalRule.php
index ae0938b..e30dfab 100644
--- a/src/tag/BbHorizontalRule.php
+++ b/src/tag/BbHorizontalRule.php
@@ -11,29 +11,35 @@
* @since 27/03/2019
* @example [hr]
*/
-class BbHorizontalRule extends BbTag {
+class BbHorizontalRule extends BbTag
+{
- public static function getTagName() {
- return 'hr';
- }
+ public static function getTagName(): string
+ {
+ return 'hr';
+ }
- public function render() {
- return '
';
- }
+ public function render(): string
+ {
+ return '
';
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return "---";
}
- public function renderPreview() {
+ public function renderPreview(): string
+ {
return "---";
}
- public static function isParagraphLess() {
- return true;
- }
+ public static function isParagraphLess(): bool
+ {
+ return true;
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
// No arguments
}
diff --git a/src/tag/BbItalic.php b/src/tag/BbItalic.php
index 901b96a..229380a 100644
--- a/src/tag/BbItalic.php
+++ b/src/tag/BbItalic.php
@@ -8,20 +8,24 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbItalic extends BbTag {
- public static function getTagName() {
- return 'i';
- }
+class BbItalic extends BbTag
+{
+ public static function getTagName(): string
+ {
+ return 'i';
+ }
- public function render() {
- return '' . $this->getContent() . '';
- }
+ public function render(): string
+ {
+ return '' . $this->getContent() . '';
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return "_" . $this->getContent() . "_";
}
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent(['i']);
}
diff --git a/src/tag/BbLeet.php b/src/tag/BbLeet.php
index 71417bb..73fee91 100644
--- a/src/tag/BbLeet.php
+++ b/src/tag/BbLeet.php
@@ -8,21 +8,24 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbLeet extends BbTag {
+class BbLeet extends BbTag
+{
- public static function getTagName() {
- return '1337';
- }
+ public static function getTagName(): string
+ {
+ return '1337';
+ }
- public function render() {
- $html = $this->getContent();
- $html = str_replace('er ', '0r ', $html);
- $html = str_replace('you', 'j00', $html);
- $html = str_replace('elite', '1337', $html);
- return strtr($html, "abelostABELOST", "48310574831057");
- }
+ public function render(): string
+ {
+ $html = $this->getContent();
+ $html = str_replace('er ', '0r ', $html);
+ $html = str_replace('you', 'j00', $html);
+ $html = str_replace('elite', '1337', $html);
+ return strtr($html, "abelostABELOST", "48310574831057");
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent();
}
diff --git a/src/tag/BbLishort.php b/src/tag/BbLishort.php
index 50e761e..a5a5cfb 100644
--- a/src/tag/BbLishort.php
+++ b/src/tag/BbLishort.php
@@ -12,25 +12,30 @@
* @example [lishort]First item
* @example [*]Next item
*/
-class BbLishort extends BbTag {
+class BbLishort extends BbTag
+{
- public static function getTagName() {
- return ['lishort', '*'];
- }
+ public static function getTagName(): array
+ {
+ return ['lishort', '*'];
+ }
- public function render() {
- return '' . $this->getContent() . '';
- }
+ public function render(): string
+ {
+ return '' . $this->getContent() . '';
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return " * " . $this->getContent();
}
- public function renderPreview() {
+ public function renderPreview(): string
+ {
return " - " . $this->getContent();
}
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->setChildren($this->parser->parseArray(['[br]']));
}
diff --git a/src/tag/BbList.php b/src/tag/BbList.php
index b194c82..b42bbd0 100644
--- a/src/tag/BbList.php
+++ b/src/tag/BbList.php
@@ -7,33 +7,35 @@
/**
* List
*
- * @author G.J.W. Oolbekkink
- * @since 27/03/2019
* @param optional String $arguments['list'] Type of ordered list
*
+ * @since 27/03/2019
+ * @author G.J.W. Oolbekkink
* @example [list]Unordered list[/list]
* @example [ulist]Unordered list[/ulist]
* @example [list=a]Ordered list numbered with lowercase letters[/list]
*/
-class BbList extends BbTag {
+class BbList extends BbTag
+{
private $type;
- public static function getTagName() {
- return ['list', 'ulist'];
- }
+ public static function getTagName(): array
+ {
+ return ['list', 'ulist'];
+ }
- public function render() {
+ public function render(): string
+ {
if ($this->type == null) {
return "";
} else {
return "type\" >{$this->getContent()}
";
}
- }
-
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent(['br']);
$this->type = $arguments['list'] ?? null;
diff --git a/src/tag/BbListItem.php b/src/tag/BbListItem.php
index 6d4f3ba..9f1cca1 100644
--- a/src/tag/BbListItem.php
+++ b/src/tag/BbListItem.php
@@ -11,25 +11,30 @@
* @since 27/03/2019
* @example [li]Item[/li]
*/
-class BbListItem extends BbTag{
+class BbListItem extends BbTag
+{
- public static function getTagName() {
- return 'li';
- }
+ public static function getTagName(): string
+ {
+ return 'li';
+ }
- public function render() {
- return '' . $this->getContent() . '';
- }
+ public function render(): string
+ {
+ return '' . $this->getContent() . '';
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return " * " . $this->getContent();
}
- public function renderPreview() {
+ public function renderPreview(): string
+ {
return " - " . $this->getContent();
}
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent();
}
diff --git a/src/tag/BbMe.php b/src/tag/BbMe.php
index 830674c..a251edb 100644
--- a/src/tag/BbMe.php
+++ b/src/tag/BbMe.php
@@ -7,30 +7,33 @@
/**
* Slash me
*
- * @author G.J.W. Oolbekkink
- * @since 27/03/2019
* @param optional String $arguments['me'] Name of who is me
*
+ * @since 27/03/2019
+ * @author G.J.W. Oolbekkink
* @example [me] waves
* @example [me=Name] waves
*/
-class BbMe extends BbTag {
+class BbMe extends BbTag
+{
private $name;
- public static function getTagName() {
- return 'me';
- }
+ public static function getTagName(): string
+ {
+ return 'me';
+ }
- public function render($arguments = []) {
- if ($this->name != null) {
- return '* ' . $this->name . $this->getContent() . '';
- } else {
- return '/me' . $this->getContent() . '';
- }
- }
+ public function render($arguments = []): string
+ {
+ if ($this->name != null) {
+ return '* ' . $this->name . $this->getContent() . '';
+ } else {
+ return '/me' . $this->getContent() . '';
+ }
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->setChildren($this->parser->parseArray(['[br]']));
array_unshift($this->parser->parseArray, '[br]');
diff --git a/src/tag/BbNewline.php b/src/tag/BbNewline.php
index fa8e4b2..8c08059 100644
--- a/src/tag/BbNewline.php
+++ b/src/tag/BbNewline.php
@@ -8,25 +8,30 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbNewline extends BbTag {
+class BbNewline extends BbTag
+{
- public static function getTagName() {
- return 'rn';
- }
+ public static function getTagName(): string
+ {
+ return 'rn';
+ }
- public function render($arguments = []) {
- return '
';
- }
+ public function render($arguments = []): string
+ {
+ return '
';
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return "\n";
}
- public function renderPreview() {
+ public function renderPreview(): string
+ {
return " ";
}
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
// No arguments
}
diff --git a/src/tag/BbNobold.php b/src/tag/BbNobold.php
index cbdfcb2..e358c8f 100644
--- a/src/tag/BbNobold.php
+++ b/src/tag/BbNobold.php
@@ -8,16 +8,19 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbNobold extends BbTag {
- public static function getTagName() {
- return 'nobold';
- }
+class BbNobold extends BbTag
+{
+ public static function getTagName(): string
+ {
+ return 'nobold';
+ }
- public function render($arguments = []) {
- return $this->getContent();
- }
+ public function render($arguments = []): string
+ {
+ return $this->getContent();
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->env->nobold = true;
$this->readContent();
diff --git a/src/tag/BbNode.php b/src/tag/BbNode.php
index 91959c4..a0c64ac 100644
--- a/src/tag/BbNode.php
+++ b/src/tag/BbNode.php
@@ -9,47 +9,30 @@
interface BbNode
{
/**
- * @return string
* @throws BbException
*/
- public function renderPlain();
+ public function renderPlain(): string;
/**
- * @return string
* @throws BbException
*/
- public function renderPreview();
+ public function renderPreview(): string;
/**
- * @return string
* @throws BbException
*/
- public function renderLight();
+ public function renderLight(): string;
/**
- * @return string
* @throws BbException
*/
- public function render();
+ public function render(): string;
/**
- * @return BbNode[]
+ * @return BbNode[]|null
*/
- public function getChildren();
-
- /**
- * @param string $content
- * @return void
- */
- public function setContent($content);
-
- /**
- * @return void
- */
- public function getContent();
-
- /**
- * @return bool
- */
- public function isAllowed();
-}
\ No newline at end of file
+ public function getChildren(): ?array;
+ public function setContent(string $content): void;
+ public function getContent(): string;
+ public function isAllowed(): bool;
+}
diff --git a/src/tag/BbQuote.php b/src/tag/BbQuote.php
index 5a997f9..f740891 100644
--- a/src/tag/BbQuote.php
+++ b/src/tag/BbQuote.php
@@ -12,29 +12,35 @@
* @since 27/03/2019
* @example [quote]Citaat[/quote]
*/
-class BbQuote extends BbTag {
- public static function getTagName() {
- return 'quote';
- }
+class BbQuote extends BbTag
+{
+ public static function getTagName(): string
+ {
+ return 'quote';
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return "> " . str_replace("\n", "\n> ", $this->getContent());
}
- public function renderPreview() {
+ public function renderPreview(): string
+ {
return "\"" . str_replace("\n", "\n> ", $this->getContent()) . "\"";
}
- public function render($arguments = []) {
- return 'Citaat' .
- '
' . $this->getContent() . '
';
- }
+ public function render($arguments = []): string
+ {
+ return 'Citaat' .
+ '
' . $this->getContent() . '
';
+ }
- public static function isParagraphLess() {
- return true;
- }
+ public static function isParagraphLess(): bool
+ {
+ return true;
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
if ($this->env->quote_level == 0) {
$this->env->quote_level = 1;
diff --git a/src/tag/BbStrikethrough.php b/src/tag/BbStrikethrough.php
index 9f2d2cc..7b89461 100644
--- a/src/tag/BbStrikethrough.php
+++ b/src/tag/BbStrikethrough.php
@@ -8,21 +8,25 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbStrikethrough extends BbTag {
+class BbStrikethrough extends BbTag
+{
- public static function getTagName() {
- return 's';
- }
+ public static function getTagName(): string
+ {
+ return 's';
+ }
- public function render($arguments = []) {
- return '' . $this->getContent() . '';
- }
+ public function render($arguments = []): string
+ {
+ return '' . $this->getContent() . '';
+ }
- public function renderPlain() {
+ public function renderPlain(): string
+ {
return "~" . $this->getContent() . "~";
}
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent(['s']);
}
diff --git a/src/tag/BbSubscript.php b/src/tag/BbSubscript.php
index 6cd872b..a485d9e 100644
--- a/src/tag/BbSubscript.php
+++ b/src/tag/BbSubscript.php
@@ -11,17 +11,20 @@
* @since 27/03/2019
* @example [sub]Subscript[/sub]
*/
-class BbSubscript extends BbTag {
+class BbSubscript extends BbTag
+{
- public static function getTagName() {
- return 'sub';
- }
+ public static function getTagName(): string
+ {
+ return 'sub';
+ }
- public function render($arguments = []) {
- return '' . $this->getContent() . '';
- }
+ public function render($arguments = []): string
+ {
+ return '' . $this->getContent() . '';
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent(['sub', 'sup']);
}
diff --git a/src/tag/BbSuperscript.php b/src/tag/BbSuperscript.php
index 37b318f..351a043 100644
--- a/src/tag/BbSuperscript.php
+++ b/src/tag/BbSuperscript.php
@@ -11,17 +11,20 @@
* @since 27/03/2019
* @example [sup]Superscript[/sup]
*/
-class BbSuperscript extends BbTag {
+class BbSuperscript extends BbTag
+{
- public static function getTagName() {
- return 'sup';
- }
+ public static function getTagName(): string
+ {
+ return 'sup';
+ }
- public function render($arguments = []) {
- return '' . $this->getContent() . '';
- }
+ public function render($arguments = []): string
+ {
+ return '' . $this->getContent() . '';
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent(['sub', 'sup']);
}
diff --git a/src/tag/BbTable.php b/src/tag/BbTable.php
index a703736..e841f00 100644
--- a/src/tag/BbTable.php
+++ b/src/tag/BbTable.php
@@ -7,35 +7,40 @@
/**
* Table
*
- * @author G.J.W. Oolbekkink
- * @since 27/03/2019
* @param string optional $arguments['border'] CSS border style
* @param string optional $arguments['color'] CSS color style
* @param string optional $arguments['background-color'] CSS background-color style
* @param string optional $arguments['border-collapse'] CSS border-collapse style
*
+ * @author G.J.W. Oolbekkink
+ * @since 27/03/2019
* @example [table border=1px_solid_blue]...[/table]
*/
-class BbTable extends BbTag {
+class BbTable extends BbTag
+{
private $styleProperties = [];
- public static function getTagName() {
- return 'table';
- }
- public function render($arguments = []) {
- $style = '';
- foreach ($this->styleProperties as $name => $value) {
- $style .= $name . ': ' . str_replace('_', ' ', htmlspecialchars($value)) . '; ';
- }
+ public static function getTagName(): string
+ {
+ return 'table';
+ }
+
+ public function render($arguments = []): string
+ {
+ $style = '';
+ foreach ($this->styleProperties as $name => $value) {
+ $style .= $name . ': ' . str_replace('_', ' ', htmlspecialchars($value)) . '; ';
+ }
- return '' . $this->getContent() . '
';
- }
+ return '' . $this->getContent() . '
';
+ }
- public static function isParagraphLess() {
- return true;
- }
+ public static function isParagraphLess(): bool
+ {
+ return true;
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent(['br']);
$tableProperties = array('border', 'color', 'background-color', 'border-collapse');
diff --git a/src/tag/BbTableCell.php b/src/tag/BbTableCell.php
index 9c37124..5b9d68d 100644
--- a/src/tag/BbTableCell.php
+++ b/src/tag/BbTableCell.php
@@ -7,29 +7,32 @@
/**
* Table cell
*
- * @author G.J.W. Oolbekkink
- * @since 27/03/2019
* @param integer optional $arguments['w'] CSS width in pixels
+ * @since 27/03/2019
+ * @author G.J.W. Oolbekkink
* @example [td w=50]...[/td]
*/
-class BbTableCell extends BbTag {
+class BbTableCell extends BbTag
+{
private $width;
- public static function getTagName() {
- return 'td';
- }
+ public static function getTagName(): string
+ {
+ return 'td';
+ }
- public function render($arguments = []) {
- $style = '';
- if ($this->width != null) {
- $style .= 'width: ' . (int)$this->width . 'px; ';
- }
+ public function render($arguments = []): string
+ {
+ $style = '';
+ if ($this->width != null) {
+ $style .= 'width: ' . (int)$this->width . 'px; ';
+ }
- return '' . $this->getContent() . ' | ';
- }
+ return '' . $this->getContent() . ' | ';
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent();
$this->width = $arguments['w'] ?? null;
diff --git a/src/tag/BbTableHeader.php b/src/tag/BbTableHeader.php
index a21e31e..e883df1 100644
--- a/src/tag/BbTableHeader.php
+++ b/src/tag/BbTableHeader.php
@@ -11,16 +11,19 @@
* @since 27/03/2019
* @example [th]...[/th]
*/
-class BbTableHeader extends BbTag {
- public static function getTagName() {
- return 'th';
- }
+class BbTableHeader extends BbTag
+{
+ public static function getTagName(): string
+ {
+ return 'th';
+ }
- public function render($arguments = []) {
- return '' . $this->getContent() . ' | ';
- }
+ public function render($arguments = []): string
+ {
+ return '' . $this->getContent() . ' | ';
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent();
}
diff --git a/src/tag/BbTableRow.php b/src/tag/BbTableRow.php
index ff0dc9b..b4647c6 100644
--- a/src/tag/BbTableRow.php
+++ b/src/tag/BbTableRow.php
@@ -12,17 +12,20 @@
* @example [tr]...
* @example [tr]...[/tr]
*/
-class BbTableRow extends BbTag {
+class BbTableRow extends BbTag
+{
- public static function getTagName() {
- return 'tr';
- }
+ public static function getTagName(): string
+ {
+ return 'tr';
+ }
- public function render($arguments = []) {
- return '' . $this->getContent() . '
';
- }
+ public function render($arguments = []): string
+ {
+ return '' . $this->getContent() . '
';
+ }
- public function parse($arguments = [])
+ public function parse($arguments = []): void
{
$this->readContent(['br']);
}
diff --git a/src/tag/BbUnderline.php b/src/tag/BbUnderline.php
index 945833f..076451f 100644
--- a/src/tag/BbUnderline.php
+++ b/src/tag/BbUnderline.php
@@ -8,14 +8,20 @@
* @author G.J.W. Oolbekkink
* @since 27/03/2019
*/
-class BbUnderline extends BbTag{
- public static function getTagName() {
- return 'u';
- }
- public function parse($arguments = []) {
+class BbUnderline extends BbTag
+{
+ public static function getTagName(): string
+ {
+ return 'u';
+ }
+
+ public function parse($arguments = []): void
+ {
$this->readContent();
}
- public function render() {
- return '' . $this->getContent() . '';
- }
+
+ public function render(): string
+ {
+ return '' . $this->getContent() . '';
+ }
}
From 67ef30b2719e9fd35296fb3bcf081b60e2327303 Mon Sep 17 00:00:00 2001
From: Gerben Oolbekkink
Date: Thu, 16 Mar 2023 22:50:19 +0100
Subject: [PATCH 2/5] Update README.md
---
README.md | 80 +++++++++++++++++++++++++++----------------------------
1 file changed, 40 insertions(+), 40 deletions(-)
diff --git a/README.md b/README.md
index 2dd9ebc..42c38e6 100644
--- a/README.md
+++ b/README.md
@@ -23,39 +23,39 @@ echo $parser->getHtml('[h=1]Hello World[/h]');
### Tags
The default tags available are:
-|Tag name|Description|
-|---|---|
-|`[b]`| Bold text |
-|`[i]`|Italic|
-|`[u]`|Underline|
-|`[s]`|Strikethrough|
-|`[sub]`|Subscript|
-|`[sup]`|Superscript|
-|`[clear]`|Clear|
-|`[code]`|Code block|
-|`[commentaar]`|Comment|
-|`[div class=? w=? h=? float=left/right clear?]`|Div|
-|`[email]`|Email|
-|`[h]`|Header|
-|`[hr]`|Horizontal rule|
-|`[1337]`|Leet speak|
-|`[lishort]`, `[*]`| List item|
-|`[list]`, `[ulist]`| List|
-|`[li]`|List item|
-|`[me]`| /me|
-|`[rn]`| New line|
-|`[nobold]`|Disable `[b]`|
-|`[quote]`|Blockquote|
-|`[table]`|Table element|
-|`[td]`| Table cell|
-|`[th]`| Table header|
-|`[tr]`|Table Row|
+| Tag name | Description |
+|-------------------------------------------------|-----------------|
+| `[b]` | Bold text |
+| `[i]` | Italic |
+| `[u]` | Underline |
+| `[s]` | Strikethrough |
+| `[sub]` | Subscript |
+| `[sup]` | Superscript |
+| `[clear]` | Clear |
+| `[code]` | Code block |
+| `[commentaar]` | Comment |
+| `[div class=? w=? h=? float=left/right clear?]` | Div |
+| `[email]` | Email |
+| `[h]` | Header |
+| `[hr]` | Horizontal rule |
+| `[1337]` | Leet speak |
+| `[lishort]`, `[*]` | List item |
+| `[list]`, `[ulist]` | List |
+| `[li]` | List item |
+| `[me]` | /me |
+| `[rn]` | New line |
+| `[nobold]` | Disable `[b]` |
+| `[quote]` | Blockquote |
+| `[table]` | Table element |
+| `[td]` | Table cell |
+| `[th]` | Table header |
+| `[tr]` | Table Row |
### Custom tags
Tags must extend the `\CsrDelft\bb\BbTag` class. Tags must implement the `parse($arguments)` and `getTagName()` methods.
-The `getTagName` method retuns a string or list of strings with the name(s) of this tag.
+The `getTagName` method returns a string or list of strings with the name(s) of this tag.
The `parse` method receives a map of arguments. The `readContent` method can be used to retrieve the contents of
the tag, this content is parsed by the parser when it is received. The parser reads the input until an end tag is
@@ -68,21 +68,21 @@ A tag has access to an environment, which is by default of type `CsrDelft\bb\BBe
```php
class BbSuperscript extends BbTag {
- public static function getTagName() {
- return 'sup';
- }
-
- public function render() {
- return '' . $this->getContent() . '';
- }
-
- public function parse($arguments = []) {
- $this->readContent(['sub', 'sup']);
- }
+ public static function getTagName(): string {
+ return 'sup';
+ }
+
+ public function render(): string {
+ return '' . $this->getContent() . '';
+ }
+
+ public function parse($arguments = []): void {
+ $this->readContent(['sub', 'sup']);
+ }
}
```
### Custom parser
-A custom parser must extend `Parser` and contains a list of tags in the `$tags` field. See `DefaultParser` for the
+A custom parser must extend `Parser` and contains a list of tags in the `getTags` method. See `DefaultParser` for the
list of default tags.
From abcff335d78138f5c6c06c64641f18c9ee3cce6b Mon Sep 17 00:00:00 2001
From: Gerben Oolbekkink
Date: Thu, 16 Mar 2023 22:57:03 +0100
Subject: [PATCH 3/5] New packages
---
README.md | 6 +--
composer.json | 4 +-
src/BbEnv.php | 2 +-
src/BbException.php | 2 +-
src/BbTag.php | 4 +-
src/DefaultParser.php | 52 +++++++++++-----------
src/{internal => Internal}/BbError.php | 6 +--
src/{internal => Internal}/BbString.php | 4 +-
src/Parser.php | 8 ++--
src/{tag => Tag}/BbBold.php | 4 +-
src/{tag => Tag}/BbClear.php | 4 +-
src/{tag => Tag}/BbCode.php | 4 +-
src/{tag => Tag}/BbCommentaar.php | 4 +-
src/{tag => Tag}/BbDiv.php | 4 +-
src/{tag => Tag}/BbEmail.php | 4 +-
src/{tag => Tag}/BbHeading.php | 4 +-
src/{tag => Tag}/BbHorizontalRule.php | 4 +-
src/{tag => Tag}/BbItalic.php | 4 +-
src/{tag => Tag}/BbLeet.php | 4 +-
src/{tag => Tag}/BbLishort.php | 4 +-
src/{tag => Tag}/BbList.php | 4 +-
src/{tag => Tag}/BbListItem.php | 4 +-
src/{tag => Tag}/BbMe.php | 4 +-
src/{tag => Tag}/BbNewline.php | 4 +-
src/{tag => Tag}/BbNobold.php | 4 +-
src/{tag => Tag}/BbNode.php | 4 +-
src/{tag => Tag}/BbQuote.php | 6 +--
src/{tag => Tag}/BbStrikethrough.php | 4 +-
src/{tag => Tag}/BbSubscript.php | 4 +-
src/{tag => Tag}/BbSuperscript.php | 4 +-
src/{tag => Tag}/BbTable.php | 4 +-
src/{tag => Tag}/BbTableCell.php | 4 +-
src/{tag => Tag}/BbTableHeader.php | 4 +-
src/{tag => Tag}/BbTableRow.php | 4 +-
src/{tag => Tag}/BbUnderline.php | 4 +-
tests/PlainTagsTest.php | 6 +--
tests/TagsTest.php | 4 +-
tests/lib/VarDriverPlatformIndependent.php | 10 ++---
38 files changed, 107 insertions(+), 107 deletions(-)
rename src/{internal => Internal}/BbError.php (89%)
rename src/{internal => Internal}/BbString.php (92%)
rename src/{tag => Tag}/BbBold.php (93%)
rename src/{tag => Tag}/BbClear.php (91%)
rename src/{tag => Tag}/BbCode.php (94%)
rename src/{tag => Tag}/BbCommentaar.php (86%)
rename src/{tag => Tag}/BbDiv.php (97%)
rename src/{tag => Tag}/BbEmail.php (97%)
rename src/{tag => Tag}/BbHeading.php (96%)
rename src/{tag => Tag}/BbHorizontalRule.php (91%)
rename src/{tag => Tag}/BbItalic.php (89%)
rename src/{tag => Tag}/BbLeet.php (90%)
rename src/{tag => Tag}/BbLishort.php (92%)
rename src/{tag => Tag}/BbList.php (93%)
rename src/{tag => Tag}/BbListItem.php (91%)
rename src/{tag => Tag}/BbMe.php (93%)
rename src/{tag => Tag}/BbNewline.php (89%)
rename src/{tag => Tag}/BbNobold.php (88%)
rename src/{tag => Tag}/BbNode.php (89%)
rename src/{tag => Tag}/BbQuote.php (92%)
rename src/{tag => Tag}/BbStrikethrough.php (90%)
rename src/{tag => Tag}/BbSubscript.php (89%)
rename src/{tag => Tag}/BbSuperscript.php (89%)
rename src/{tag => Tag}/BbTable.php (95%)
rename src/{tag => Tag}/BbTableCell.php (92%)
rename src/{tag => Tag}/BbTableHeader.php (88%)
rename src/{tag => Tag}/BbTableRow.php (89%)
rename src/{tag => Tag}/BbUnderline.php (87%)
diff --git a/README.md b/README.md
index 42c38e6..5e69dba 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ composer require csrdelft/bb
Either use the `DefaultParser` or implement your own parser.
```php
-$parser = new \CsrDelft\bb\DefaultParser();
+$parser = new \CsrDelft\BbParser\DefaultParser();
echo $parser->getHtml('[h=1]Hello World[/h]');
```
@@ -53,7 +53,7 @@ The default tags available are:
### Custom tags
-Tags must extend the `\CsrDelft\bb\BbTag` class. Tags must implement the `parse($arguments)` and `getTagName()` methods.
+Tags must extend the `\CsrDelft\BbParser\BbTag` class. Tags must implement the `parse($arguments)` and `getTagName()` methods.
The `getTagName` method returns a string or list of strings with the name(s) of this tag.
@@ -62,7 +62,7 @@ the tag, this content is parsed by the parser when it is received. The parser re
found. `readContent` has an optional parameter for tags which are forbidden to be in this tag. For instance a `[sup]`
tag cannot contain another sup tag or a sub tag.
-A tag has access to an environment, which is by default of type `CsrDelft\bb\BBenv` (can be overridden).
+A tag has access to an environment, which is by default of type `CsrDelft\BbParser\BBenv` (can be overridden).
### Custom tag example
diff --git a/composer.json b/composer.json
index e5dafbc..6052096 100644
--- a/composer.json
+++ b/composer.json
@@ -15,8 +15,8 @@
},
"autoload": {
"psr-4": {
- "CsrDelft\\bb\\": "src/",
- "CsrDelft\\bb\\test\\": "tests/lib/"
+ "CsrDelft\\BbParser\\": "src/",
+ "CsrDelft\\BbParser\\Test\\": "tests/lib/"
}
},
"scripts": {
diff --git a/src/BbEnv.php b/src/BbEnv.php
index d7c8e3a..cf1d15c 100644
--- a/src/BbEnv.php
+++ b/src/BbEnv.php
@@ -1,6 +1,6 @@
diff --git a/src/BbException.php b/src/BbException.php
index 5b9a946..e6ba7de 100644
--- a/src/BbException.php
+++ b/src/BbException.php
@@ -1,6 +1,6 @@
diff --git a/src/internal/BbError.php b/src/Internal/BbError.php
similarity index 89%
rename from src/internal/BbError.php
rename to src/Internal/BbError.php
index e744e94..dd5c7e7 100644
--- a/src/internal/BbError.php
+++ b/src/Internal/BbError.php
@@ -1,11 +1,11 @@
diff --git a/src/tag/BbClear.php b/src/Tag/BbClear.php
similarity index 91%
rename from src/tag/BbClear.php
rename to src/Tag/BbClear.php
index b8f50a4..228e116 100644
--- a/src/tag/BbClear.php
+++ b/src/Tag/BbClear.php
@@ -1,8 +1,8 @@
diff --git a/src/tag/BbCode.php b/src/Tag/BbCode.php
similarity index 94%
rename from src/tag/BbCode.php
rename to src/Tag/BbCode.php
index fa216f9..c5c430e 100644
--- a/src/tag/BbCode.php
+++ b/src/Tag/BbCode.php
@@ -1,8 +1,8 @@
diff --git a/src/tag/BbDiv.php b/src/Tag/BbDiv.php
similarity index 97%
rename from src/tag/BbDiv.php
rename to src/Tag/BbDiv.php
index 93a151c..a075d50 100644
--- a/src/tag/BbDiv.php
+++ b/src/Tag/BbDiv.php
@@ -1,8 +1,8 @@
diff --git a/src/tag/BbLeet.php b/src/Tag/BbLeet.php
similarity index 90%
rename from src/tag/BbLeet.php
rename to src/Tag/BbLeet.php
index 73fee91..c7bddab 100644
--- a/src/tag/BbLeet.php
+++ b/src/Tag/BbLeet.php
@@ -1,8 +1,8 @@
diff --git a/src/tag/BbLishort.php b/src/Tag/BbLishort.php
similarity index 92%
rename from src/tag/BbLishort.php
rename to src/Tag/BbLishort.php
index a5a5cfb..2779050 100644
--- a/src/tag/BbLishort.php
+++ b/src/Tag/BbLishort.php
@@ -1,8 +1,8 @@
diff --git a/src/tag/BbNobold.php b/src/Tag/BbNobold.php
similarity index 88%
rename from src/tag/BbNobold.php
rename to src/Tag/BbNobold.php
index e358c8f..8584692 100644
--- a/src/tag/BbNobold.php
+++ b/src/Tag/BbNobold.php
@@ -1,8 +1,8 @@
diff --git a/src/tag/BbNode.php b/src/Tag/BbNode.php
similarity index 89%
rename from src/tag/BbNode.php
rename to src/Tag/BbNode.php
index a0c64ac..b21220b 100644
--- a/src/tag/BbNode.php
+++ b/src/Tag/BbNode.php
@@ -1,10 +1,10 @@
diff --git a/src/tag/BbSubscript.php b/src/Tag/BbSubscript.php
similarity index 89%
rename from src/tag/BbSubscript.php
rename to src/Tag/BbSubscript.php
index a485d9e..52827c6 100644
--- a/src/tag/BbSubscript.php
+++ b/src/Tag/BbSubscript.php
@@ -1,8 +1,8 @@
diff --git a/tests/PlainTagsTest.php b/tests/PlainTagsTest.php
index cdafcbc..96f878a 100644
--- a/tests/PlainTagsTest.php
+++ b/tests/PlainTagsTest.php
@@ -1,9 +1,9 @@
Date: Thu, 16 Mar 2023 23:12:10 +0100
Subject: [PATCH 4/5] hashFiles composer.json in composer cache
---
.github/workflows/ci.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8b16273..d0529ef 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,7 +25,7 @@ jobs:
uses: actions/cache@v2
with:
path: vendor
- key: ${{ runner.os }}-composer-dev-${{ hashFiles('**/composer.lock') }}
+ key: ${{ runner.os }}-composer-dev-${{ hashFiles('**/composer.lock', '**/composer.json') }}
restore-keys: |
${{ runner.os }}-composer-dev-
From 140f25b29a29a1b147ee98a31a9acb974b01b483 Mon Sep 17 00:00:00 2001
From: Gerben Oolbekkink
Date: Mon, 20 Mar 2023 23:19:00 +0100
Subject: [PATCH 5/5] Cleanup Parser
---
README.md | 6 +-
composer.json | 4 +-
src/BbEnv.php | 2 +-
src/BbException.php | 2 +-
src/BbTag.php | 10 +-
src/DefaultParser.php | 108 +++++------
src/Internal/BbError.php | 6 +-
src/Internal/BbString.php | 4 +-
src/Parser.php | 197 +++++++++++----------
src/Tag/BbBold.php | 4 +-
src/Tag/BbClear.php | 4 +-
src/Tag/BbCode.php | 4 +-
src/Tag/BbCommentaar.php | 4 +-
src/Tag/BbDiv.php | 4 +-
src/Tag/BbEmail.php | 4 +-
src/Tag/BbHeading.php | 4 +-
src/Tag/BbHorizontalRule.php | 4 +-
src/Tag/BbItalic.php | 4 +-
src/Tag/BbLeet.php | 4 +-
src/Tag/BbLishort.php | 4 +-
src/Tag/BbList.php | 4 +-
src/Tag/BbListItem.php | 4 +-
src/Tag/BbMe.php | 4 +-
src/Tag/BbNewline.php | 4 +-
src/Tag/BbNobold.php | 4 +-
src/Tag/BbNode.php | 4 +-
src/Tag/BbQuote.php | 6 +-
src/Tag/BbStrikethrough.php | 4 +-
src/Tag/BbSubscript.php | 4 +-
src/Tag/BbSuperscript.php | 4 +-
src/Tag/BbTable.php | 4 +-
src/Tag/BbTableCell.php | 4 +-
src/Tag/BbTableHeader.php | 4 +-
src/Tag/BbTableRow.php | 4 +-
src/Tag/BbUnderline.php | 4 +-
tests/PlainTagsTest.php | 6 +-
tests/TagsTest.php | 4 +-
tests/lib/VarDriverPlatformIndependent.php | 2 +-
38 files changed, 234 insertions(+), 223 deletions(-)
diff --git a/README.md b/README.md
index 5e69dba..26d45d9 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ composer require csrdelft/bb
Either use the `DefaultParser` or implement your own parser.
```php
-$parser = new \CsrDelft\BbParser\DefaultParser();
+$parser = new \CsrDelft\Lib\Bb\DefaultParser();
echo $parser->getHtml('[h=1]Hello World[/h]');
```
@@ -53,7 +53,7 @@ The default tags available are:
### Custom tags
-Tags must extend the `\CsrDelft\BbParser\BbTag` class. Tags must implement the `parse($arguments)` and `getTagName()` methods.
+Tags must extend the `\CsrDelft\Lib\Bb\BbTag` class. Tags must implement the `parse($arguments)` and `getTagName()` methods.
The `getTagName` method returns a string or list of strings with the name(s) of this tag.
@@ -62,7 +62,7 @@ the tag, this content is parsed by the parser when it is received. The parser re
found. `readContent` has an optional parameter for tags which are forbidden to be in this tag. For instance a `[sup]`
tag cannot contain another sup tag or a sub tag.
-A tag has access to an environment, which is by default of type `CsrDelft\BbParser\BBenv` (can be overridden).
+A tag has access to an environment, which is by default of type `CsrDelft\Lib\Bb\BBenv` (can be overridden).
### Custom tag example
diff --git a/composer.json b/composer.json
index 6052096..c0f3ead 100644
--- a/composer.json
+++ b/composer.json
@@ -15,8 +15,8 @@
},
"autoload": {
"psr-4": {
- "CsrDelft\\BbParser\\": "src/",
- "CsrDelft\\BbParser\\Test\\": "tests/lib/"
+ "CsrDelft\\Lib\\Bb\\": "src/",
+ "CsrDelft\\Lib\\Bb\\Test\\": "tests/lib/"
}
},
"scripts": {
diff --git a/src/BbEnv.php b/src/BbEnv.php
index cf1d15c..317ace3 100644
--- a/src/BbEnv.php
+++ b/src/BbEnv.php
@@ -1,6 +1,6 @@
diff --git a/src/BbException.php b/src/BbException.php
index e6ba7de..b8f3261 100644
--- a/src/BbException.php
+++ b/src/BbException.php
@@ -1,6 +1,6 @@
getStoppers();
- $parse_bb_state_before = $this->parser->bb_mode;
- $this->parser->bb_mode &= $parse_bb;
+ $parse_bb_state_before = $this->parser->bbMode;
+ $this->parser->bbMode &= $parse_bb;
$result = $this->parser->parseArray($stoppers, $forbidden);
- $this->parser->bb_mode = $parse_bb_state_before;
+ $this->parser->bbMode = $parse_bb_state_before;
$this->children = $result;
}
diff --git a/src/DefaultParser.php b/src/DefaultParser.php
index e5a46d9..473a066 100644
--- a/src/DefaultParser.php
+++ b/src/DefaultParser.php
@@ -1,32 +1,33 @@
@@ -34,34 +35,37 @@
*/
final class DefaultParser extends Parser
{
- public function getTags()
+ /**
+ * @return BbNode[]
+ */
+ public function getTags(): array
{
return [
- BbBold::class,
- BbClear::class,
- BbCode::class,
- BbCommentaar::class,
- BbDiv::class,
- BbEmail::class,
- BbHeading::class,
- BbHorizontalRule::class,
- BbItalic::class,
- BbLeet::class,
- BbLishort::class,
- BbListItem::class,
- BbMe::class,
- BbNewline::class,
- BbNobold::class,
- BbQuote::class,
- BbStrikethrough::class,
- BbSubscript::class,
- BbSuperscript::class,
- BbTable::class,
- BbTableCell::class,
- BbTableHeader::class,
- BbTableRow::class,
- BbList::class,
- BbUnderline::class,
+ new BbBold(),
+ new BbClear(),
+ new BbCode(),
+ new BbCommentaar(),
+ new BbDiv(),
+ new BbEmail(),
+ new BbHeading(),
+ new BbHorizontalRule(),
+ new BbItalic(),
+ new BbLeet(),
+ new BbLishort(),
+ new BbListItem(),
+ new BbMe(),
+ new BbNewline(),
+ new BbNobold(),
+ new BbQuote(),
+ new BbStrikethrough(),
+ new BbSubscript(),
+ new BbSuperscript(),
+ new BbTable(),
+ new BbTableCell(),
+ new BbTableHeader(),
+ new BbTableRow(),
+ new BbList(),
+ new BbUnderline(),
];
}
}
diff --git a/src/Internal/BbError.php b/src/Internal/BbError.php
index dd5c7e7..1544e61 100644
--- a/src/Internal/BbError.php
+++ b/src/Internal/BbError.php
@@ -1,11 +1,11 @@
This is an experimental feature! Please let me know if you find strange behaviour!
+ * When set to true, the parser will try to use <p> tags around text, and remove unnecessary br's.
+ * This is an experimental feature! Please let me know if you find strange behaviour!
* @var boolean
*/
- protected $paragraph_mode = false;
- /**
- * List of possible tags.
- *
- * @var array
- */
- protected $tags = [];
- /**
- * Storage for BB code
- */
- private $bbcode;
+ protected $paragraphMode = false;
/**
* Storage for outgoing HTML
*/
- private $HTML;
+ private $html;
/**
* How deep are we; e.g. How many open tags?
*/
@@ -91,33 +85,35 @@ abstract class Parser {
/**
* Amount of tags already parsed
*/
- private $tags_counted = 0;
+ private $tagsCounted = 0;
/**
* Keep track of open paragraphs
*/
- private $paragraph_open = false;
+ private $paragraphOpen = false;
/**
* Tags that do not need to be encapsulated in paragraphs, filled in constructor.
*/
- private $paragraphless_tags = ['br'];
+ private $paragraphlessTags = ['br'];
/**
* Keep track of current paragraph-required-status
*
- * When we're in a tag that does not need to be encapsulate in a paragraph, this var will be false, otherwise true. Works only when in paragraph mode.
+ * When we're in a tag that does not need to be encapsulate in a paragraph, this var will be false, otherwise true.
+ * Works only when in paragraph mode.
*/
- private $paragraph_required = true;
+ private $paragraphRequired = true;
/**
* Environment
*
* @var BbEnv
*/
- private $env = [];
+ private $env = null;
/**
- * @var BbTag[]
+ * @var BbTag[]|string[]
*/
private $registry = [];
- public function __construct($env = null) {
+ public function __construct($env = null)
+ {
if (is_null($env)) {
$env = new BbEnv();
}
@@ -134,12 +130,20 @@ public function __construct($env = null) {
}
if ($tag::isParagraphLess()) {
- $this->paragraphless_tags[] = $tag::getTagName();
+ $this->paragraphlessTags[] = $tag::getTagName();
}
}
}
- public abstract function getTags();
+ /**
+ * @param BbEnv|mixed|null $env
+ */
+ public function setEnv($env): void
+ {
+ $this->env = $env;
+ }
+
+ abstract public function getTags();
/**
* Transform BB code to HTML code.
@@ -148,7 +152,8 @@ public abstract function getTags();
* @param string $bbcode BB code to be transformed
* @return string HTML
*/
- public function getHtml($bbcode) {
+ public function getHtml($bbcode)
+ {
if (strlen($bbcode) == 0) {
return null;
}
@@ -157,22 +162,23 @@ public function getHtml($bbcode) {
$html = $this->render($blocks, $this->env->mode);
- $this->HTML = str_replace(self::BR_TAG, "
\n", $html);
+ $this->html = str_replace(self::BR_TAG, "
\n", $html);
- return $this->HTML;
+ return $this->html;
}
/**
* @param string $bbcode
* @return BbNode[]|null
*/
- public function parseString($bbcode) {
+ public function parseString($bbcode)
+ {
if ($this->env->mode !== "preview" && $this->env->mode !== "plain") {
$bbcode = str_replace(array("\r\n", "\n"), self::BR_TAG, $bbcode);
}
// Create the parsearray with the buildarray function, pretty nice ;)
- $this->tags_counted = 0;
+ $this->tagsCounted = 0;
$this->parseArray = $this->tokenize($bbcode);
// Fix html rights
@@ -221,7 +227,8 @@ public function render($blocks, $mode)
return $text;
}
- private function tokenize($str) {
+ private function tokenize($str)
+ {
$tokens = "[]";
$index = 0;
@@ -248,7 +255,7 @@ private function tokenize($str) {
$prevIndex = $index;
- if ($numTags > $this->max_tags) {
+ if ($numTags > $this->maxTags) {
return ['[max # of tags reached, quitting splitting procedure]' . $str];
}
}
@@ -265,11 +272,12 @@ private function tokenize($str) {
/**
* Set [html] and [nohtml] tags according to settings
*/
- private function htmlFix() {
+ private function htmlFix()
+ {
// First, check if html is allowed
- if (!$this->allow_html) {
+ if (!$this->allowHtml) {
$html = false;
- } elseif ($this->standard_html) {
+ } elseif ($this->standardHtml) {
$html = true;
} else {
$html = false;
@@ -284,7 +292,7 @@ private function htmlFix() {
break;
case self::TAG_HTML_OPEN:
case self::TAG_NOHTML_CLOSE:
- if ($this->allow_html) {
+ if ($this->allowHtml) {
$html = true;
}
break;
@@ -312,64 +320,58 @@ private function htmlFix() {
* @param array $forbidden
* @return BbNode[]
*/
- public function parseArray($stoppers = [], $forbidden = []) {
-
+ public function parseArray($stoppers = [], $forbidden = [])
+ {
if (!is_array($this->parseArray)) { // Well, nothing to parse
return null;
}
$blocks = [];
- $forbidden_aantal_open = 0;
+ $forbiddenAantalOpen = 0;
while ($entry = array_shift($this->parseArray)) {
-
if (in_array($entry, $stoppers)) {
-
- if ($forbidden_aantal_open == 0) {
-
+ if ($forbiddenAantalOpen == 0) {
$this->level--;
return $blocks;
} else {
- $forbidden_aantal_open--;
+ $forbiddenAantalOpen--;
$blocks[] = new BbString($entry);
}
} else {
-
$tag = $this->getTag($entry);
if ($tag && in_array($tag, $forbidden)) {
if ($tag != 'br') {
- $forbidden_aantal_open++;
+ $forbiddenAantalOpen++;
} else {
$entry = "\n";
}
}
- $isOpenTag = substr($entry, 0, 1) == '[' && substr($entry, strlen($entry) - 1, 1) == ']' && substr($entry, 1, 1) != '/';
+ $isOpenTag = $this->isOpenTag($entry);
$isAllowed = !in_array($tag, $forbidden) && !isset($forbidden['all']);
$exists = isset($this->registry[$tag]);
- if ($this->bb_mode && $isOpenTag && $exists && $isAllowed) {
+ if ($this->bbMode && $isOpenTag && $exists && $isAllowed) {
$tagInstance = $this->createTagInstance($this->registry[$tag], $this, $this->env);
$arguments = $this->getArguments($entry);
- if ($this->paragraph_mode) {
+ if ($this->paragraphMode) {
// Add paragraphs if necessary
- $paragraph_setting_modified = false;
- if (!$this->paragraph_open && !in_array($tag, $this->paragraphless_tags) && $this->level == 0) { // Only encaps when level = 0, we don't want paragraphs inside lists or stuff
+ $paragraphSettingModified = false;
+ if (!$this->paragraphOpen && !in_array($tag, $this->paragraphlessTags) && $this->level == 0) { // Only encaps when level = 0, we don't want paragraphs inside lists or stuff
$text .= '';
- $this->paragraph_open = true;
- } elseif (in_array($tag, $this->paragraphless_tags)) {
+ $this->paragraphOpen = true;
+ } elseif (in_array($tag, $this->paragraphlessTags)) {
// We're in some tag that doesn't need to be
enclosed, like a heading or a table.
- if ($this->paragraph_required) {
- $paragraph_setting_modified = true;
- $this->paragraph_required = false;
+ if ($this->paragraphRequired) {
+ $paragraphSettingModified = true;
+ $this->paragraphRequired = false;
}
- if ($this->paragraph_open && $this->level == 0) {
-
- $text .= "
\n\n";
- $this->paragraph_open = false;
+ if ($this->paragraphOpen && $this->level == 0) {
+ $this->paragraphOpen = false;
}
}
}
@@ -382,15 +384,14 @@ public function parseArray($stoppers = [], $forbidden = []) {
}
// Reset paragraph_required.
- if ($this->paragraph_mode && $paragraph_setting_modified) {
- $this->paragraph_required = true;
+ if ($this->paragraphMode && $paragraphSettingModified) {
+ $this->paragraphRequired = true;
}
$blocks[] = $tagInstance;
} else {
- if ($this->paragraph_mode && $entry == self::BR_TAG) {
-
+ if ($this->paragraphMode && $entry == self::BR_TAG) {
$shift = array_shift($this->parseArray);
if ($shift == self::BR_TAG) {
// Two brs, looks like a new paragraph!
@@ -399,24 +400,23 @@ public function parseArray($stoppers = [], $forbidden = []) {
$secondshift = array_shift($this->parseArray);
while ($secondshift == self::BR_TAG) {
$secondshift = array_shift($this->parseArray);
- $text .= "
\n";
}
array_unshift($this->parseArray, $secondshift);
$shift = array_shift($this->parseArray);
- if ($this->paragraph_required && !in_array($this->getTag($shift), $this->paragraphless_tags)) {
- if ($this->paragraph_open) {
+ if ($this->paragraphRequired && !in_array($this->getTag($shift), $this->paragraphlessTags)) {
+ if ($this->paragraphOpen) {
if ($this->level == 0) {
// Close old one, and open new one
$entry = "
\n\n";
- $this->paragraph_open = true;
+ $this->paragraphOpen = true;
}
} else {
if ($this->level == 0) {
/** @noinspection HtmlUnknownAttribute */
$entry = "
";
- $this->paragraph_open = true;
+ $this->paragraphOpen = true;
}
}
} else {
@@ -426,7 +426,7 @@ public function parseArray($stoppers = [], $forbidden = []) {
// We have found 1 [br], so normally we'd put it back
// But if next thing is a paragraphless tag (say, table) or end of document,
// We can skip the [br], since there will be a
anyway.
- } elseif (in_array($this->getTag($shift), $this->paragraphless_tags)) {
+ } elseif (in_array($this->getTag($shift), $this->paragraphlessTags)) {
$entry = null;
}
@@ -434,9 +434,8 @@ public function parseArray($stoppers = [], $forbidden = []) {
}
// Add paragraphs if necessary
- if ($this->paragraph_mode && !$this->paragraph_open && $this->paragraph_required && $this->level == 0) {
- $text .= '';
- $this->paragraph_open = true;
+ if ($this->paragraphMode && !$this->paragraphOpen && $this->paragraphRequired && $this->level == 0) {
+ $this->paragraphOpen = true;
}
$blocks[] = new BbString($entry);
@@ -444,8 +443,8 @@ public function parseArray($stoppers = [], $forbidden = []) {
}
} // End of BIG while!
- if ($this->paragraph_open) { // No need for a level check, should be zero anyway.
- $this->paragraph_open = false;
+ if ($this->paragraphOpen) { // No need for a level check, should be zero anyway.
+ $this->paragraphOpen = false;
$blocks[] = new BbString("
");
}
@@ -456,10 +455,11 @@ public function parseArray($stoppers = [], $forbidden = []) {
* return name of a tag
*
* When supplied with a full tag ([b] or [img w=5 h=10]), return tag name
- * @return string
* @param string $fullTag The full tag to get the tagname from
+ * @return string
*/
- private function getTag($fullTag) {
+ private function getTag($fullTag)
+ {
if (substr($fullTag, 0, 1) == '[' && substr($fullTag, strlen($fullTag) - 1, 1) == ']') {
return strtok($fullTag, '[ =]');
} else {
@@ -471,11 +471,12 @@ private function getTag($fullTag) {
* return arguments of a tag in array-form
*
* When supplied with a full tag ([h=5] or [img=blah.gif w=5 h=10]), return array with argument/value as key/value pairs
- * @return string[]
* @param string $fullTag The full tag to get the arguments from
+ * @return string[]
*/
- private function getArguments(string $fullTag): array {
- $argument_array = [];
+ private function getArguments(string $fullTag): array
+ {
+ $arguments = [];
$tag = substr($fullTag, 1, strlen($fullTag) - 2);
$argList = explode(' ', $tag);
$i = 0;
@@ -491,18 +492,14 @@ private function getArguments(string $fullTag): array {
}
}
if (isset($value) && isset($key)) {
- // FIXME: stupid javascript filtering detected
if (strstr(strtolower($value), 'javascript:')) {
$value = 'disabled';
}
- // if(strstr(strtolower($value), '(')){
- // $value = 'disabled';
- // }
- $argument_array[$key] = $value;
+ $arguments[$key] = $value;
}
}
- return $argument_array;
+ return $arguments;
}
protected function createTagInstance(string $tag, Parser $parser, $env): BbTag
@@ -515,4 +512,14 @@ protected function createTagInstance(string $tag, Parser $parser, $env): BbTag
return $tagInstance;
}
+ /**
+ * @param string $entry
+ * @return bool
+ */
+ private function isOpenTag(string $entry): bool
+ {
+ return substr($entry, 0, 1) == '[' && substr($entry, strlen($entry) - 1, 1) == ']'
+ && substr($entry, 1, 1) != '/';
+ }
+
}
diff --git a/src/Tag/BbBold.php b/src/Tag/BbBold.php
index 2e1012b..6b18bbe 100644
--- a/src/Tag/BbBold.php
+++ b/src/Tag/BbBold.php
@@ -1,8 +1,8 @@
diff --git a/src/Tag/BbClear.php b/src/Tag/BbClear.php
index 228e116..3a13977 100644
--- a/src/Tag/BbClear.php
+++ b/src/Tag/BbClear.php
@@ -1,8 +1,8 @@
diff --git a/src/Tag/BbCode.php b/src/Tag/BbCode.php
index c5c430e..ccd369d 100644
--- a/src/Tag/BbCode.php
+++ b/src/Tag/BbCode.php
@@ -1,8 +1,8 @@
diff --git a/src/Tag/BbDiv.php b/src/Tag/BbDiv.php
index a075d50..26b9a7b 100644
--- a/src/Tag/BbDiv.php
+++ b/src/Tag/BbDiv.php
@@ -1,8 +1,8 @@
diff --git a/src/Tag/BbLeet.php b/src/Tag/BbLeet.php
index c7bddab..994181f 100644
--- a/src/Tag/BbLeet.php
+++ b/src/Tag/BbLeet.php
@@ -1,8 +1,8 @@
diff --git a/src/Tag/BbLishort.php b/src/Tag/BbLishort.php
index 2779050..0c55bbd 100644
--- a/src/Tag/BbLishort.php
+++ b/src/Tag/BbLishort.php
@@ -1,8 +1,8 @@
diff --git a/src/Tag/BbNobold.php b/src/Tag/BbNobold.php
index 8584692..2a2123b 100644
--- a/src/Tag/BbNobold.php
+++ b/src/Tag/BbNobold.php
@@ -1,8 +1,8 @@
diff --git a/src/Tag/BbNode.php b/src/Tag/BbNode.php
index b21220b..62778d1 100644
--- a/src/Tag/BbNode.php
+++ b/src/Tag/BbNode.php
@@ -1,10 +1,10 @@
diff --git a/src/Tag/BbSubscript.php b/src/Tag/BbSubscript.php
index 52827c6..5b858c3 100644
--- a/src/Tag/BbSubscript.php
+++ b/src/Tag/BbSubscript.php
@@ -1,8 +1,8 @@
diff --git a/tests/PlainTagsTest.php b/tests/PlainTagsTest.php
index 96f878a..5885167 100644
--- a/tests/PlainTagsTest.php
+++ b/tests/PlainTagsTest.php
@@ -1,9 +1,9 @@