Skip to content

Commit

Permalink
Merge pull request #1717 from Oha-you/spoiler
Browse files Browse the repository at this point in the history
(Fix) Spoilers on Pages with markdown
  • Loading branch information
HDVinnie authored Apr 14, 2021
2 parents 7eff944 + 3ece203 commit cdcacce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 16 additions & 2 deletions app/Helpers/BBCodeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,22 @@ function ($matches) {
*/
protected function replaceSpoilers()
{
$this->text = \preg_replace_callback('#\[spoiler\]([\W\D\w\s]*?)\[/spoiler\]#iu',
$this->text = \preg_replace_callback('#\[spoiler\](.*?)\[\/spoiler\]#ius',

fn ($matches) => '<details><summary>Spoiler!</summary><pre><code>'.\trim($matches[1], ' ').'</code></pre></details>',
fn ($matches) => '<p><details class="label label-primary"><summary>Spoiler</summary><pre><code>'.\trim($matches[1]).'</code></pre></details></p>',

$this->text
);
}

/**
* @brief Replace BBCode named spoiler.
*/
protected function replaceNamedSpoilers()
{
$this->text = \preg_replace_callback('#\[spoiler\=(.*?)\](.*?)\[\/spoiler\]#ius',

fn ($matches) => '<p><details class="label label-primary"><summary>'.\trim($matches[1]).'</summary><pre><code>'.\trim($matches[2]).'</code></pre></details></p>',

$this->text
);
Expand Down Expand Up @@ -408,6 +421,7 @@ public function toMarkdown()
$this->replaceQuotes();
$this->replaceSnippets();
$this->replaceSpoilers();
$this->replaceNamedSpoilers();
$this->replaceColor();
$this->replaceVideo();
$this->replaceYoutube();
Expand Down
11 changes: 8 additions & 3 deletions resources/sass/main/_custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9411,11 +9411,16 @@ section.recommendations div.scroller div.item span.glyphicons {
font-size: 1.2em;
}

.page-content p {
.page-content p,
.page-content details {
margin-top: 0.5em;
margin-bottom: 0.5em;
}

.page-content details {
text-align: left;
}

.page-content>blockquote {
color: #555;
border-color: #555;
Expand All @@ -9424,7 +9429,7 @@ section.recommendations div.scroller div.item span.glyphicons {
}

.page-content code,
pre {
.page-content pre {
color: #555;
background-color: #f5f5f5;
border: 1px solid #ccc;
Expand All @@ -9435,7 +9440,7 @@ pre {
word-break: normal;
}

.page-content>pre>code {
.page-content pre>code {
border: none;
}

Expand Down

0 comments on commit cdcacce

Please sign in to comment.