diff --git a/src/Application.php b/src/Application.php index c4e13661..ef171b49 100644 --- a/src/Application.php +++ b/src/Application.php @@ -273,8 +273,8 @@ class Application extends ApplicationBase $this->templatingInstance->addFilter('colour_get_red'); $this->templatingInstance->addFilter('colour_get_green'); $this->templatingInstance->addFilter('colour_get_blue'); - $this->templatingInstance->addFilter('md', 'parse_markdown'); - $this->templatingInstance->addFilter('bbcode', 'parse_bbcode'); + $this->templatingInstance->addFilter('parse_line'); + $this->templatingInstance->addFilter('parse_text'); $this->templatingInstance->addFunction('git_commit_hash'); $this->templatingInstance->addFunction('git_branch'); diff --git a/utility.php b/utility.php index 5ece9be5..807cdea5 100644 --- a/utility.php +++ b/utility.php @@ -203,6 +203,38 @@ function parse_bbcode(string $text): string return \Misuzu\Parsers\BBCode\BBCodeParser::instance()->parseText($text); } +function parse_text(string $text, string $parser): string +{ + switch (strtolower($parser)) { + case 'md': + case 'markdown': + return \Misuzu\Parsers\MarkdownParser::instance()->parseText($text); + + case 'bb': + case 'bbcode': + return \Misuzu\Parsers\BBCode\BBCodeParser::instance()->parseText($text); + + default: + return $text; + } +} + +function parse_line(string $line, string $parser): string +{ + switch (strtolower($parser)) { + case 'md': + case 'markdown': + return \Misuzu\Parsers\MarkdownParser::instance()->parseLine($line); + + case 'bb': + case 'bbcode': + return \Misuzu\Parsers\BBCode\BBCodeParser::instance()->parseLine($line); + + default: + return $line; + } +} + function render_error(int $code, string $template = 'errors.%d'): string { http_response_code($code); diff --git a/views/mio/changelog/change.twig b/views/mio/changelog/change.twig index 6283c684..b388d23d 100644 --- a/views/mio/changelog/change.twig +++ b/views/mio/changelog/change.twig @@ -62,7 +62,7 @@
{% if change.change_text|length >= 1 %} - {{ change.change_text|md|raw }} + {{ change.change_text|parse_text('md')|raw }} {% else %}

This change has no additional notes.

{% endif %} diff --git a/views/mio/forum/macros.twig b/views/mio/forum/macros.twig index aa7cab7c..71b5ba05 100644 --- a/views/mio/forum/macros.twig +++ b/views/mio/forum/macros.twig @@ -291,9 +291,9 @@
{% if post.post_parse == 2 %} - {{ post.post_text|escape|md|raw }} + {{ post.post_text|escape|parse_text('md')|raw }} {% elseif post.post_parse == 1 %} - {{ post.post_text|escape|bbcode|raw }} + {{ post.post_text|escape|parse_text('bb')|raw }} {% else %} {{ post.post_text|escape }} {% endif %} diff --git a/views/mio/news/macros.twig b/views/mio/news/macros.twig index 14171439..3cfdbb2a 100644 --- a/views/mio/news/macros.twig +++ b/views/mio/news/macros.twig @@ -6,7 +6,7 @@
- {{ post.post_text|first_paragraph|md|raw }} + {{ post.post_text|first_paragraph|parse_text('md')|raw }}
diff --git a/views/mio/news/post.twig b/views/mio/news/post.twig index fab1ef4c..bb44af42 100644 --- a/views/mio/news/post.twig +++ b/views/mio/news/post.twig @@ -12,7 +12,7 @@
- {{ post.post_text|md|raw }} + {{ post.post_text|parse_text('md')|raw }}