[bbcode] make sure bbcode css only applies to bbcode

This commit is contained in:
Shish
2024-01-01 16:05:48 +00:00
parent 7563576557
commit f611f9b1e4
3 changed files with 15 additions and 10 deletions

View File

@ -7,6 +7,12 @@ namespace Shimmie2;
class BBCode extends FormatterExtension class BBCode extends FormatterExtension
{ {
public function format(string $text): string public function format(string $text): string
{
$text = $this->_format($text);
return "<span class='bbcode'>$text</span>";
}
public function _format(string $text): string
{ {
$text = $this->extract_code($text); $text = $this->extract_code($text);
foreach ([ foreach ([
@ -158,7 +164,7 @@ class BBCode extends FormatterExtension
$middle = base64_decode(substr($text, $start + $l1, ($end - $start - $l1))); $middle = base64_decode(substr($text, $start + $l1, ($end - $start - $l1)));
$ending = substr($text, $end + $l2, (strlen($text) - $end + $l2)); $ending = substr($text, $end + $l2, (strlen($text) - $end + $l2));
$text = $beginning . "<pre>" . $middle . "</pre>" . $ending; $text = $beginning . "<pre class='code'>" . $middle . "</pre>" . $ending;
} }
return $text; return $text;
} }

View File

@ -1,16 +1,15 @@
.bbcode PRE.code {
CODE { background: #DEDEDE;
background: #DEDEDE; font-size: 0.9rem;
font-size: 0.8rem;
} }
BLOCKQUOTE { .bbcode BLOCKQUOTE {
border: 1px solid black; border: 1px solid black;
padding: 8px; padding: 8px;
background: #DDD; background: #DDD;
} }
.anchor A.alink { .bbcode .anchor A.alink {
visibility: hidden; visibility: hidden;
} }
.anchor:hover A.alink { .bbcode .anchor:hover A.alink {
visibility: visible; visibility: visible;
} }

View File

@ -37,7 +37,7 @@ class BBCodeTest extends ShimmiePHPUnitTestCase
public function testCode() public function testCode()
{ {
$this->assertEquals( $this->assertEquals(
"<pre>[b]bold[/b]</pre>", "<pre class='code'>[b]bold[/b]</pre>",
$this->filter("[code][b]bold[/b][/code]") $this->filter("[code][b]bold[/b][/code]")
); );
} }
@ -104,7 +104,7 @@ class BBCodeTest extends ShimmiePHPUnitTestCase
private function filter($in): string private function filter($in): string
{ {
$bb = new BBCode(); $bb = new BBCode();
return $bb->format($in); return $bb->_format($in);
} }
private function strip($in): string private function strip($in): string