Change parse functions within templates a bit.

This commit is contained in:
flash 2018-07-17 21:12:51 +02:00
parent a41f7d64c7
commit d0d8d82f60
6 changed files with 39 additions and 7 deletions

View file

@ -273,8 +273,8 @@ class Application extends ApplicationBase
$this->templatingInstance->addFilter('colour_get_red'); $this->templatingInstance->addFilter('colour_get_red');
$this->templatingInstance->addFilter('colour_get_green'); $this->templatingInstance->addFilter('colour_get_green');
$this->templatingInstance->addFilter('colour_get_blue'); $this->templatingInstance->addFilter('colour_get_blue');
$this->templatingInstance->addFilter('md', 'parse_markdown'); $this->templatingInstance->addFilter('parse_line');
$this->templatingInstance->addFilter('bbcode', 'parse_bbcode'); $this->templatingInstance->addFilter('parse_text');
$this->templatingInstance->addFunction('git_commit_hash'); $this->templatingInstance->addFunction('git_commit_hash');
$this->templatingInstance->addFunction('git_branch'); $this->templatingInstance->addFunction('git_branch');

View file

@ -203,6 +203,38 @@ function parse_bbcode(string $text): string
return \Misuzu\Parsers\BBCode\BBCodeParser::instance()->parseText($text); 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 function render_error(int $code, string $template = 'errors.%d'): string
{ {
http_response_code($code); http_response_code($code);

View file

@ -62,7 +62,7 @@
<div class="changelog__change__column changelog__change__column--change-info"> <div class="changelog__change__column changelog__change__column--change-info">
<div class="changelog__change__text"> <div class="changelog__change__text">
{% if change.change_text|length >= 1 %} {% if change.change_text|length >= 1 %}
{{ change.change_text|md|raw }} {{ change.change_text|parse_text('md')|raw }}
{% else %} {% else %}
<p>This change has no additional notes.</p> <p>This change has no additional notes.</p>
{% endif %} {% endif %}

View file

@ -291,9 +291,9 @@
</div> </div>
<div class="forum__post__content__text"> <div class="forum__post__content__text">
{% if post.post_parse == 2 %} {% if post.post_parse == 2 %}
{{ post.post_text|escape|md|raw }} {{ post.post_text|escape|parse_text('md')|raw }}
{% elseif post.post_parse == 1 %} {% elseif post.post_parse == 1 %}
{{ post.post_text|escape|bbcode|raw }} {{ post.post_text|escape|parse_text('bb')|raw }}
{% else %} {% else %}
{{ post.post_text|escape }} {{ post.post_text|escape }}
{% endif %} {% endif %}

View file

@ -6,7 +6,7 @@
<div class="container__content news__preview__content"> <div class="container__content news__preview__content">
<div class="news__preview__text"> <div class="news__preview__text">
{{ post.post_text|first_paragraph|md|raw }} {{ post.post_text|first_paragraph|parse_text('md')|raw }}
</div> </div>
<div class="news__preview__info"> <div class="news__preview__info">

View file

@ -12,7 +12,7 @@
<div class="container__content news__post__content"> <div class="container__content news__post__content">
<div class="news__post__text"> <div class="news__post__text">
{{ post.post_text|md|raw }} {{ post.post_text|parse_text('md')|raw }}
</div> </div>
<div class="news__sidebar news__post__details"> <div class="news__sidebar news__post__details">