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- diff --git a/README.md b/README.md index 2dd9ebc..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\bb\DefaultParser(); +$parser = new \CsrDelft\Lib\Bb\DefaultParser(); echo $parser->getHtml('[h=1]Hello World[/h]'); ``` @@ -23,66 +23,66 @@ 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. +Tags must extend the `\CsrDelft\Lib\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 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\Lib\Bb\BBenv` (can be overridden). ### Custom tag example ```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. diff --git a/composer.json b/composer.json index e5dafbc..c0f3ead 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ }, "autoload": { "psr-4": { - "CsrDelft\\bb\\": "src/", - "CsrDelft\\bb\\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 47597e7..317ace3 100644 --- a/src/BbEnv.php +++ b/src/BbEnv.php @@ -1,12 +1,13 @@ * @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..b8f3261 100644 --- a/src/BbException.php +++ b/src/BbException.php @@ -1,6 +1,6 @@ * @since 06/07/2019 */ -class BbException extends Exception { +class BbException extends Exception +{ } diff --git a/src/BbTag.php b/src/BbTag.php index 8e8916f..eadb599 100644 --- a/src/BbTag.php +++ b/src/BbTag.php @@ -1,8 +1,8 @@ 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,21 +163,25 @@ 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; + $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; } - 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..473a066 100644 --- a/src/DefaultParser.php +++ b/src/DefaultParser.php @@ -1,62 +1,71 @@ * @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 +{ + /** + * @return BbNode[] + */ + public function getTags(): array + { + return [ + 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 new file mode 100644 index 0000000..1544e61 --- /dev/null +++ b/src/Internal/BbError.php @@ -0,0 +1,64 @@ +error = $error; + } + + public function isAllowed(): bool + { + return true; + } + + public function render(): string + { + return $this->error; + } + + public function getChildren(): array + { + return []; + } + + public function setContent($content): void + { + // Nop + } + + /** + * @throws BbException + */ + public function getContent(): string + { + throw new BbException("Error heeft geen content"); + } + + public function renderPlain(): string + { + return $this->render(); + } + + public function renderPreview(): string + { + return $this->render(); + } + + public function renderLight(): string + { + return $this->render(); + } +} diff --git a/src/internal/BbString.php b/src/Internal/BbString.php similarity index 55% rename from src/internal/BbString.php rename to src/Internal/BbString.php index b1cb5d0..07dbdf5 100644 --- a/src/internal/BbString.php +++ b/src/Internal/BbString.php @@ -1,9 +1,9 @@ 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/Parser.php b/src/Parser.php index e71214a..97fafc5 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -1,17 +1,18 @@ 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,40 +85,42 @@ 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(); } $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; @@ -134,11 +130,21 @@ public function __construct($env = null) { } if ($tag::isParagraphLess()) { - $this->paragraphless_tags[] = $tag::getTagName(); + $this->paragraphlessTags[] = $tag::getTagName(); } } } + /** + * @param BbEnv|mixed|null $env + */ + public function setEnv($env): void + { + $this->env = $env; + } + + abstract public function getTags(); + /** * Transform BB code to HTML code. * @@ -146,7 +152,8 @@ public function __construct($env = null) { * @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; } @@ -155,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 @@ -219,7 +227,8 @@ public function render($blocks, $mode) return $text; } - private function tokenize($str) { + private function tokenize($str) + { $tokens = "[]"; $index = 0; @@ -246,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]; } } @@ -263,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; @@ -282,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; @@ -310,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; } } } @@ -380,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! @@ -397,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 { @@ -424,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; } @@ -432,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); @@ -442,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("

"); } @@ -454,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 { @@ -469,12 +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 array * @param string $fullTag The full tag to get the arguments from + * @return string[] */ - private function getArguments($fullTag) { - - $argument_array = Array(); + private function getArguments(string $fullTag): array + { + $arguments = []; $tag = substr($fullTag, 1, strlen($fullTag) - 2); $argList = explode(' ', $tag); $i = 0; @@ -490,21 +492,18 @@ private function getArguments($fullTag) { } } 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) { + protected function createTagInstance(string $tag, Parser $parser, $env): BbTag + { /** @var BbTag $tagInstance */ $tagInstance = new $tag($parser, $env); $tagInstance->setParser($parser); @@ -513,4 +512,14 @@ protected function createTagInstance(string $tag, Parser $parser, $env) { 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 new file mode 100644 index 0000000..6b18bbe --- /dev/null +++ b/src/Tag/BbBold.php @@ -0,0 +1,45 @@ + + * @since 27/03/2019 + */ +class BbBold extends BbTag +{ + private $disabled = false; + + public static function getTagName(): string + { + return 'b'; + } + + public function parse($arguments = []): void + { + if ($this->env->nobold === true && $this->env->quote_level == 0) { + $this->disabled = true; + } + $this->readContent(); + } + + public function renderPlain(): string + { + 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 similarity index 53% rename from src/tag/BbClear.php rename to src/Tag/BbClear.php index a57ba02..3a13977 100644 --- a/src/tag/BbClear.php +++ b/src/Tag/BbClear.php @@ -1,32 +1,36 @@ * @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 new file mode 100644 index 0000000..ccd369d --- /dev/null +++ b/src/Tag/BbCode.php @@ -0,0 +1,50 @@ + + * @example [code=PHP]phpinfo();[/code] + */ +class BbCode extends BbTag +{ + + /** + * @var string + */ + private $code; + + public static function getTagName(): string + { + return 'code'; + } + + public function parse($arguments = []): void + { + $this->readContent(['br'], false); + $this->code = isset($arguments['code']) ? $arguments['code'] . ' ' : ''; + } + + public function renderPlain(): string + { + return "$this->code\n\t" . str_replace("\n", "\n\t", $this->getContent()); + } + + public function render(): string + { + return vsprintf( + "
%scode:
%s
", + [ + $this->code, + $this->getContent() + ] + ); + } +} diff --git a/src/Tag/BbCommentaar.php b/src/Tag/BbCommentaar.php new file mode 100644 index 0000000..45f6881 --- /dev/null +++ b/src/Tag/BbCommentaar.php @@ -0,0 +1,28 @@ + + * @since 27/03/2019 + */ +class BbCommentaar extends BbTag +{ + + public static function getTagName(): string + { + return 'commentaar'; + } + + public function parse($arguments = []): void + { + $this->readContent([], false); + } + + public function render(): string + { + return ''; + } +} diff --git a/src/tag/BbDiv.php b/src/Tag/BbDiv.php similarity index 82% rename from src/tag/BbDiv.php rename to src/Tag/BbDiv.php index e8b7d15..26b9a7b 100644 --- a/src/tag/BbDiv.php +++ b/src/Tag/BbDiv.php @@ -1,23 +1,23 @@ - * @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 similarity index 88% rename from src/tag/BbEmail.php rename to src/Tag/BbEmail.php index ea9c1b6..1725d82 100644 --- a/src/tag/BbEmail.php +++ b/src/Tag/BbEmail.php @@ -1,8 +1,8 @@ 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 similarity index 63% rename from src/tag/BbHeading.php rename to src/Tag/BbHeading.php index bffe1d1..be608bf 100644 --- a/src/tag/BbHeading.php +++ b/src/Tag/BbHeading.php @@ -1,20 +1,21 @@ - * @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 new file mode 100644 index 0000000..7326f38 --- /dev/null +++ b/src/Tag/BbHorizontalRule.php @@ -0,0 +1,46 @@ + + * @since 27/03/2019 + * @example [hr] + */ +class BbHorizontalRule extends BbTag +{ + + public static function getTagName(): string + { + return 'hr'; + } + + public function render(): string + { + return '
'; + } + + public function renderPlain(): string + { + return "---"; + } + + public function renderPreview(): string + { + return "---"; + } + + public static function isParagraphLess(): bool + { + return true; + } + + public function parse($arguments = []): void + { + // No arguments + } +} diff --git a/src/Tag/BbItalic.php b/src/Tag/BbItalic.php new file mode 100644 index 0000000..2d29ee8 --- /dev/null +++ b/src/Tag/BbItalic.php @@ -0,0 +1,32 @@ + + * @since 27/03/2019 + */ +class BbItalic extends BbTag +{ + public static function getTagName(): string + { + return 'i'; + } + + public function render(): string + { + return '' . $this->getContent() . ''; + } + + public function renderPlain(): string + { + return "_" . $this->getContent() . "_"; + } + + public function parse($arguments = []): void + { + $this->readContent(['i']); + } +} diff --git a/src/Tag/BbLeet.php b/src/Tag/BbLeet.php new file mode 100644 index 0000000..994181f --- /dev/null +++ b/src/Tag/BbLeet.php @@ -0,0 +1,32 @@ + + * @since 27/03/2019 + */ +class BbLeet extends BbTag +{ + + public static function getTagName(): string + { + return '1337'; + } + + 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 = []): void + { + $this->readContent(); + } +} diff --git a/src/Tag/BbLishort.php b/src/Tag/BbLishort.php new file mode 100644 index 0000000..0c55bbd --- /dev/null +++ b/src/Tag/BbLishort.php @@ -0,0 +1,42 @@ + + * @since 27/03/2019 + * @example [lishort]First item + * @example [*]Next item + */ +class BbLishort extends BbTag +{ + + public static function getTagName(): array + { + return ['lishort', '*']; + } + + public function render(): string + { + return '
  • ' . $this->getContent() . '
  • '; + } + + public function renderPlain(): string + { + return " * " . $this->getContent(); + } + + public function renderPreview(): string + { + return " - " . $this->getContent(); + } + + public function parse($arguments = []): void + { + $this->setChildren($this->parser->parseArray(['[br]'])); + } +} diff --git a/src/tag/BbList.php b/src/Tag/BbList.php similarity index 71% rename from src/tag/BbList.php rename to src/Tag/BbList.php index b194c82..5a55367 100644 --- a/src/tag/BbList.php +++ b/src/Tag/BbList.php @@ -1,39 +1,41 @@ - * @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 "
      {$this->getContent()}
    "; } 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 new file mode 100644 index 0000000..a63c573 --- /dev/null +++ b/src/Tag/BbListItem.php @@ -0,0 +1,41 @@ + + * @since 27/03/2019 + * @example [li]Item[/li] + */ +class BbListItem extends BbTag +{ + + public static function getTagName(): string + { + return 'li'; + } + + public function render(): string + { + return '
  • ' . $this->getContent() . '
  • '; + } + + public function renderPlain(): string + { + return " * " . $this->getContent(); + } + + public function renderPreview(): string + { + return " - " . $this->getContent(); + } + + public function parse($arguments = []): void + { + $this->readContent(); + } +} diff --git a/src/Tag/BbMe.php b/src/Tag/BbMe.php new file mode 100644 index 0000000..38bae55 --- /dev/null +++ b/src/Tag/BbMe.php @@ -0,0 +1,42 @@ + + * @example [me] waves + * @example [me=Name] waves + */ +class BbMe extends BbTag +{ + + private $name; + + public static function getTagName(): string + { + return 'me'; + } + + public function render($arguments = []): string + { + if ($this->name != null) { + return '* ' . $this->name . $this->getContent() . ''; + } else { + return '/me' . $this->getContent() . ''; + } + } + + public function parse($arguments = []): void + { + $this->setChildren($this->parser->parseArray(['[br]'])); + array_unshift($this->parser->parseArray, '[br]'); + $this->name = $arguments['me'] ?? null; + } +} diff --git a/src/Tag/BbNewline.php b/src/Tag/BbNewline.php new file mode 100644 index 0000000..1c6f6d7 --- /dev/null +++ b/src/Tag/BbNewline.php @@ -0,0 +1,38 @@ + + * @since 27/03/2019 + */ +class BbNewline extends BbTag +{ + + public static function getTagName(): string + { + return 'rn'; + } + + public function render($arguments = []): string + { + return '
    '; + } + + public function renderPlain(): string + { + return "\n"; + } + + public function renderPreview(): string + { + return " "; + } + + public function parse($arguments = []): void + { + // No arguments + } +} diff --git a/src/Tag/BbNobold.php b/src/Tag/BbNobold.php new file mode 100644 index 0000000..2a2123b --- /dev/null +++ b/src/Tag/BbNobold.php @@ -0,0 +1,29 @@ + + * @since 27/03/2019 + */ +class BbNobold extends BbTag +{ + public static function getTagName(): string + { + return 'nobold'; + } + + public function render($arguments = []): string + { + return $this->getContent(); + } + + public function parse($arguments = []): void + { + $this->env->nobold = true; + $this->readContent(); + $this->env->nobold = false; + } +} diff --git a/src/Tag/BbNode.php b/src/Tag/BbNode.php new file mode 100644 index 0000000..62778d1 --- /dev/null +++ b/src/Tag/BbNode.php @@ -0,0 +1,38 @@ + " . 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 new file mode 100644 index 0000000..7ec45a2 --- /dev/null +++ b/src/Tag/BbStrikethrough.php @@ -0,0 +1,33 @@ + + * @since 27/03/2019 + */ +class BbStrikethrough extends BbTag +{ + + public static function getTagName(): string + { + return 's'; + } + + public function render($arguments = []): string + { + return '' . $this->getContent() . ''; + } + + public function renderPlain(): string + { + return "~" . $this->getContent() . "~"; + } + + public function parse($arguments = []): void + { + $this->readContent(['s']); + } +} diff --git a/src/Tag/BbSubscript.php b/src/Tag/BbSubscript.php new file mode 100644 index 0000000..5b858c3 --- /dev/null +++ b/src/Tag/BbSubscript.php @@ -0,0 +1,31 @@ + + * @since 27/03/2019 + * @example [sub]Subscript[/sub] + */ +class BbSubscript extends BbTag +{ + + public static function getTagName(): string + { + return 'sub'; + } + + public function render($arguments = []): string + { + return '' . $this->getContent() . ''; + } + + public function parse($arguments = []): void + { + $this->readContent(['sub', 'sup']); + } +} diff --git a/src/Tag/BbSuperscript.php b/src/Tag/BbSuperscript.php new file mode 100644 index 0000000..327c515 --- /dev/null +++ b/src/Tag/BbSuperscript.php @@ -0,0 +1,31 @@ + + * @since 27/03/2019 + * @example [sup]Superscript[/sup] + */ +class BbSuperscript extends BbTag +{ + + public static function getTagName(): string + { + return 'sup'; + } + + public function render($arguments = []): string + { + return '' . $this->getContent() . ''; + } + + public function parse($arguments = []): void + { + $this->readContent(['sub', 'sup']); + } +} diff --git a/src/tag/BbTable.php b/src/Tag/BbTable.php similarity index 55% rename from src/tag/BbTable.php rename to src/Tag/BbTable.php index a703736..545705a 100644 --- a/src/tag/BbTable.php +++ b/src/Tag/BbTable.php @@ -1,41 +1,46 @@ - * @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 new file mode 100644 index 0000000..7b42244 --- /dev/null +++ b/src/Tag/BbTableCell.php @@ -0,0 +1,40 @@ + + * @example [td w=50]...[/td] + */ +class BbTableCell extends BbTag +{ + + private $width; + + public static function getTagName(): string + { + return 'td'; + } + + public function render($arguments = []): string + { + $style = ''; + if ($this->width != null) { + $style .= 'width: ' . (int)$this->width . 'px; '; + } + + return '' . $this->getContent() . ''; + } + + public function parse($arguments = []): void + { + $this->readContent(); + $this->width = $arguments['w'] ?? null; + } +} diff --git a/src/Tag/BbTableHeader.php b/src/Tag/BbTableHeader.php new file mode 100644 index 0000000..1821ad3 --- /dev/null +++ b/src/Tag/BbTableHeader.php @@ -0,0 +1,30 @@ + + * @since 27/03/2019 + * @example [th]...[/th] + */ +class BbTableHeader extends BbTag +{ + public static function getTagName(): string + { + return 'th'; + } + + public function render($arguments = []): string + { + return '' . $this->getContent() . ''; + } + + public function parse($arguments = []): void + { + $this->readContent(); + } +} diff --git a/src/Tag/BbTableRow.php b/src/Tag/BbTableRow.php new file mode 100644 index 0000000..6e2ecf0 --- /dev/null +++ b/src/Tag/BbTableRow.php @@ -0,0 +1,32 @@ + + * @since 27/03/2019 + * @example [tr]... + * @example [tr]...[/tr] + */ +class BbTableRow extends BbTag +{ + + public static function getTagName(): string + { + return 'tr'; + } + + public function render($arguments = []): string + { + return '' . $this->getContent() . ''; + } + + public function parse($arguments = []): void + { + $this->readContent(['br']); + } +} diff --git a/src/Tag/BbUnderline.php b/src/Tag/BbUnderline.php new file mode 100644 index 0000000..6ed637c --- /dev/null +++ b/src/Tag/BbUnderline.php @@ -0,0 +1,27 @@ + + * @since 27/03/2019 + */ +class BbUnderline extends BbTag +{ + public static function getTagName(): string + { + return 'u'; + } + + public function parse($arguments = []): void + { + $this->readContent(); + } + + public function render(): string + { + return '' . $this->getContent() . ''; + } +} diff --git a/src/internal/BbError.php b/src/internal/BbError.php deleted file mode 100644 index cf44dca..0000000 --- a/src/internal/BbError.php +++ /dev/null @@ -1,60 +0,0 @@ -error = $error; - } - - public function isAllowed() - { - return true; - } - - public function render() - { - return $this->error; - } - - public function getChildren() - { - return []; - } - - public function setContent($content) - { - // Nop - } - - public function getContent() - { - return null; - } - - public function renderPlain() - { - return $this->render(); - } - - public function renderPreview() - { - return $this->render(); - } - - public function renderLight() - { - return $this->render(); - } -} \ No newline at end of file diff --git a/src/tag/BbBold.php b/src/tag/BbBold.php deleted file mode 100644 index c638097..0000000 --- a/src/tag/BbBold.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @since 27/03/2019 - */ -class BbBold extends BbTag { - private $disabled = false; - - public static function getTagName() { - return 'b'; - } - - public function parse($arguments = []) { - if ($this->env->nobold === true && $this->env->quote_level == 0) { - $this->disabled = true; - } - $this->readContent(); - } - - public function renderPlain() { - if ($this->disabled) { - return $this->getContent(); - } else { - return '*' . $this->getContent() . '*'; - } - } - - public function render() { - if ($this->disabled) { - return $this->getContent(); - } else { - return '' . $this->getContent() . ''; - } - } -} diff --git a/src/tag/BbCode.php b/src/tag/BbCode.php deleted file mode 100644 index c503649..0000000 --- a/src/tag/BbCode.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @since 27/03/2019 - * @param optional String $arguments['code'] Description of code type - * - * @example [code=PHP]phpinfo();[/code] - */ -class BbCode extends BbTag { - - /** - * @var string - */ - private $code; - - public static function getTagName() { - return 'code'; - } - - public function parse($arguments = []) { - $this->readContent(['br'], false); - $this->code = isset($arguments['code']) ? $arguments['code'] . ' ' : ''; - } - - public function renderPlain() { - return "$this->code\n\t" . str_replace("\n", "\n\t", $this->getContent()); - } - - public function render() { - return '
    ' . $this->code . 'code:
    ' . $this->getContent() . '
    '; - } -} diff --git a/src/tag/BbCommentaar.php b/src/tag/BbCommentaar.php deleted file mode 100644 index d8759a8..0000000 --- a/src/tag/BbCommentaar.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @since 27/03/2019 - */ -class BbCommentaar extends BbTag { - - public static function getTagName() { - return 'commentaar'; - } - public function parse($arguments = []) { - $this->readContent([], false); - } - public function render() { - return ''; - } -} diff --git a/src/tag/BbHorizontalRule.php b/src/tag/BbHorizontalRule.php deleted file mode 100644 index ae0938b..0000000 --- a/src/tag/BbHorizontalRule.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @since 27/03/2019 - * @example [hr] - */ -class BbHorizontalRule extends BbTag { - - public static function getTagName() { - return 'hr'; - } - - public function render() { - return '
    '; - } - - public function renderPlain() { - return "---"; - } - - public function renderPreview() { - return "---"; - } - - public static function isParagraphLess() { - return true; - } - - public function parse($arguments = []) - { - // No arguments - } -} diff --git a/src/tag/BbItalic.php b/src/tag/BbItalic.php deleted file mode 100644 index 901b96a..0000000 --- a/src/tag/BbItalic.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @since 27/03/2019 - */ -class BbItalic extends BbTag { - public static function getTagName() { - return 'i'; - } - - public function render() { - return '' . $this->getContent() . ''; - } - - public function renderPlain() { - return "_" . $this->getContent() . "_"; - } - - public function parse($arguments = []) - { - $this->readContent(['i']); - } -} diff --git a/src/tag/BbLeet.php b/src/tag/BbLeet.php deleted file mode 100644 index 71417bb..0000000 --- a/src/tag/BbLeet.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @since 27/03/2019 - */ -class BbLeet extends BbTag { - - public static function getTagName() { - 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 parse($arguments = []) - { - $this->readContent(); - } -} diff --git a/src/tag/BbLishort.php b/src/tag/BbLishort.php deleted file mode 100644 index 50e761e..0000000 --- a/src/tag/BbLishort.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @since 27/03/2019 - * @example [lishort]First item - * @example [*]Next item - */ -class BbLishort extends BbTag { - - public static function getTagName() { - return ['lishort', '*']; - } - - public function render() { - return '
  • ' . $this->getContent() . '
  • '; - } - - public function renderPlain() { - return " * " . $this->getContent(); - } - - public function renderPreview() { - return " - " . $this->getContent(); - } - - public function parse($arguments = []) - { - $this->setChildren($this->parser->parseArray(['[br]'])); - } -} diff --git a/src/tag/BbListItem.php b/src/tag/BbListItem.php deleted file mode 100644 index 6d4f3ba..0000000 --- a/src/tag/BbListItem.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @since 27/03/2019 - * @example [li]Item[/li] - */ -class BbListItem extends BbTag{ - - public static function getTagName() { - return 'li'; - } - - public function render() { - return '
  • ' . $this->getContent() . '
  • '; - } - - public function renderPlain() { - return " * " . $this->getContent(); - } - - public function renderPreview() { - return " - " . $this->getContent(); - } - - public function parse($arguments = []) - { - $this->readContent(); - } -} diff --git a/src/tag/BbMe.php b/src/tag/BbMe.php deleted file mode 100644 index 830674c..0000000 --- a/src/tag/BbMe.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @since 27/03/2019 - * @param optional String $arguments['me'] Name of who is me - * - * @example [me] waves - * @example [me=Name] waves - */ -class BbMe extends BbTag { - - private $name; - - public static function getTagName() { - return 'me'; - } - - public function render($arguments = []) { - if ($this->name != null) { - return '* ' . $this->name . $this->getContent() . ''; - } else { - return '/me' . $this->getContent() . ''; - } - } - - public function parse($arguments = []) - { - $this->setChildren($this->parser->parseArray(['[br]'])); - array_unshift($this->parser->parseArray, '[br]'); - $this->name = $arguments['me'] ?? null; - } -} diff --git a/src/tag/BbNewline.php b/src/tag/BbNewline.php deleted file mode 100644 index fa8e4b2..0000000 --- a/src/tag/BbNewline.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @since 27/03/2019 - */ -class BbNewline extends BbTag { - - public static function getTagName() { - return 'rn'; - } - - public function render($arguments = []) { - return '
    '; - } - - public function renderPlain() { - return "\n"; - } - - public function renderPreview() { - return " "; - } - - public function parse($arguments = []) - { - // No arguments - } -} diff --git a/src/tag/BbNobold.php b/src/tag/BbNobold.php deleted file mode 100644 index cbdfcb2..0000000 --- a/src/tag/BbNobold.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @since 27/03/2019 - */ -class BbNobold extends BbTag { - public static function getTagName() { - return 'nobold'; - } - - public function render($arguments = []) { - return $this->getContent(); - } - - public function parse($arguments = []) - { - $this->env->nobold = true; - $this->readContent(); - $this->env->nobold = false; - } -} diff --git a/src/tag/BbNode.php b/src/tag/BbNode.php deleted file mode 100644 index 91959c4..0000000 --- a/src/tag/BbNode.php +++ /dev/null @@ -1,55 +0,0 @@ - - * @since 27/03/2019 - */ -class BbStrikethrough extends BbTag { - - public static function getTagName() { - return 's'; - } - - public function render($arguments = []) { - return '' . $this->getContent() . ''; - } - - public function renderPlain() { - return "~" . $this->getContent() . "~"; - } - - public function parse($arguments = []) - { - $this->readContent(['s']); - } -} diff --git a/src/tag/BbSubscript.php b/src/tag/BbSubscript.php deleted file mode 100644 index 6cd872b..0000000 --- a/src/tag/BbSubscript.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @since 27/03/2019 - * @example [sub]Subscript[/sub] - */ -class BbSubscript extends BbTag { - - public static function getTagName() { - return 'sub'; - } - - public function render($arguments = []) { - return '' . $this->getContent() . ''; - } - - public function parse($arguments = []) - { - $this->readContent(['sub', 'sup']); - } -} diff --git a/src/tag/BbSuperscript.php b/src/tag/BbSuperscript.php deleted file mode 100644 index 37b318f..0000000 --- a/src/tag/BbSuperscript.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @since 27/03/2019 - * @example [sup]Superscript[/sup] - */ -class BbSuperscript extends BbTag { - - public static function getTagName() { - return 'sup'; - } - - public function render($arguments = []) { - return '' . $this->getContent() . ''; - } - - public function parse($arguments = []) - { - $this->readContent(['sub', 'sup']); - } -} diff --git a/src/tag/BbTableCell.php b/src/tag/BbTableCell.php deleted file mode 100644 index 9c37124..0000000 --- a/src/tag/BbTableCell.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @since 27/03/2019 - * @param integer optional $arguments['w'] CSS width in pixels - * @example [td w=50]...[/td] - */ -class BbTableCell extends BbTag { - - private $width; - - public static function getTagName() { - return 'td'; - } - - public function render($arguments = []) { - $style = ''; - if ($this->width != null) { - $style .= 'width: ' . (int)$this->width . 'px; '; - } - - return '' . $this->getContent() . ''; - } - - public function parse($arguments = []) - { - $this->readContent(); - $this->width = $arguments['w'] ?? null; - } -} diff --git a/src/tag/BbTableHeader.php b/src/tag/BbTableHeader.php deleted file mode 100644 index a21e31e..0000000 --- a/src/tag/BbTableHeader.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @since 27/03/2019 - * @example [th]...[/th] - */ -class BbTableHeader extends BbTag { - public static function getTagName() { - return 'th'; - } - - public function render($arguments = []) { - return '' . $this->getContent() . ''; - } - - public function parse($arguments = []) - { - $this->readContent(); - } -} diff --git a/src/tag/BbTableRow.php b/src/tag/BbTableRow.php deleted file mode 100644 index ff0dc9b..0000000 --- a/src/tag/BbTableRow.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @since 27/03/2019 - * @example [tr]... - * @example [tr]...[/tr] - */ -class BbTableRow extends BbTag { - - public static function getTagName() { - return 'tr'; - } - - public function render($arguments = []) { - return '' . $this->getContent() . ''; - } - - public function parse($arguments = []) - { - $this->readContent(['br']); - } -} diff --git a/src/tag/BbUnderline.php b/src/tag/BbUnderline.php deleted file mode 100644 index 945833f..0000000 --- a/src/tag/BbUnderline.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @since 27/03/2019 - */ -class BbUnderline extends BbTag{ - public static function getTagName() { - return 'u'; - } - public function parse($arguments = []) { - $this->readContent(); - } - public function render() { - return '' . $this->getContent() . ''; - } -} diff --git a/tests/PlainTagsTest.php b/tests/PlainTagsTest.php index cdafcbc..5885167 100644 --- a/tests/PlainTagsTest.php +++ b/tests/PlainTagsTest.php @@ -1,9 +1,9 @@