diff --git a/src/BbEnv.php b/src/BbEnv.php index f1edd6a..47597e7 100644 --- a/src/BbEnv.php +++ b/src/BbEnv.php @@ -8,7 +8,7 @@ */ class BbEnv { /** - * @var string One of default, light, plain + * @var string One of default, light, preview, plain */ public $mode = "default"; public $quote_level = 0; diff --git a/src/BbTag.php b/src/BbTag.php index 0bb7aaa..8e8916f 100644 --- a/src/BbTag.php +++ b/src/BbTag.php @@ -103,6 +103,16 @@ public function renderLight() abstract public function render(); + /** + * render preview will strip html tags by default. + * + * @return string + */ + public function renderPreview() + { + return strip_tags($this->render()); + } + /** * render plain will strip html tags by default. * diff --git a/src/Parser.php b/src/Parser.php index f80aa92..e71214a 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -165,7 +165,7 @@ public function getHtml($bbcode) { * @return BbNode[]|null */ public function parseString($bbcode) { - if ($this->env->mode !== "plain") { + if ($this->env->mode !== "preview" && $this->env->mode !== "plain") { $bbcode = str_replace(array("\r\n", "\n"), self::BR_TAG, $bbcode); } @@ -201,6 +201,8 @@ public function render($blocks, $mode) if ($mode == "light") { $text .= $block->renderLight(); + } elseif ($mode == "preview") { + $text .= $block->renderPreview(); } elseif ($mode == "plain") { $text .= $block->renderPlain(); } else { diff --git a/src/internal/BbError.php b/src/internal/BbError.php index b2a5b0d..cf44dca 100644 --- a/src/internal/BbError.php +++ b/src/internal/BbError.php @@ -48,6 +48,11 @@ public function renderPlain() return $this->render(); } + public function renderPreview() + { + return $this->render(); + } + public function renderLight() { return $this->render(); diff --git a/src/internal/BbString.php b/src/internal/BbString.php index 8b9b07e..b1cb5d0 100644 --- a/src/internal/BbString.php +++ b/src/internal/BbString.php @@ -47,6 +47,11 @@ public function renderPlain() return $this->render(); } + public function renderPreview() + { + return $this->render(); + } + public function renderLight() { return $this->render(); diff --git a/src/tag/BbHorizontalRule.php b/src/tag/BbHorizontalRule.php index 1a46bd4..ae0938b 100644 --- a/src/tag/BbHorizontalRule.php +++ b/src/tag/BbHorizontalRule.php @@ -25,6 +25,10 @@ public function renderPlain() { return "---"; } + public function renderPreview() { + return "---"; + } + public static function isParagraphLess() { return true; } diff --git a/src/tag/BbLishort.php b/src/tag/BbLishort.php index fd4ddd0..50e761e 100644 --- a/src/tag/BbLishort.php +++ b/src/tag/BbLishort.php @@ -26,6 +26,10 @@ 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 index 1bac371..6d4f3ba 100644 --- a/src/tag/BbListItem.php +++ b/src/tag/BbListItem.php @@ -25,6 +25,10 @@ public function renderPlain() { return " * " . $this->getContent(); } + public function renderPreview() { + return " - " . $this->getContent(); + } + public function parse($arguments = []) { $this->readContent(); diff --git a/src/tag/BbNewline.php b/src/tag/BbNewline.php index cd5a363..fa8e4b2 100644 --- a/src/tag/BbNewline.php +++ b/src/tag/BbNewline.php @@ -22,6 +22,10 @@ public function renderPlain() { return "\n"; } + public function renderPreview() { + return " "; + } + public function parse($arguments = []) { // No arguments diff --git a/src/tag/BbNode.php b/src/tag/BbNode.php index 5142b73..91959c4 100644 --- a/src/tag/BbNode.php +++ b/src/tag/BbNode.php @@ -14,6 +14,12 @@ interface BbNode */ public function renderPlain(); + /** + * @return string + * @throws BbException + */ + public function renderPreview(); + /** * @return string * @throws BbException diff --git a/src/tag/BbQuote.php b/src/tag/BbQuote.php index 104855b..5a997f9 100644 --- a/src/tag/BbQuote.php +++ b/src/tag/BbQuote.php @@ -21,6 +21,10 @@ public function renderPlain() { return "> " . str_replace("\n", "\n> ", $this->getContent()); } + public function renderPreview() { + return "\"" . str_replace("\n", "\n> ", $this->getContent()) . "\""; + } + public function render($arguments = []) { return '
Citaat' . '
' . $this->getContent() . '
';