From 9c71f59061f7a2ffcb676d75f3c87522ec43eff3 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 24 Aug 2014 16:55:00 +0100 Subject: [PATCH 1/2] [anchor] bbcode tag, to make linking to parts of a page easier --- ext/bbcode/main.php | 2 ++ ext/bbcode/test.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index 1fe39202..d30d89db 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -39,6 +39,7 @@ class BBCode extends FormatterExtension { } $text = preg_replace('!^>>([^\d].+)!', '
$1
', $text); $text = preg_replace('!>>(\d+)(#c?\d+)?!s', '>>$1$2', $text); + $text = preg_replace('!\[anchor=(.*?)\](.*?)\[/anchor\]!s', '$2', $text); // add "bb-" to avoid clashing with eg #top $text = preg_replace('!\[url=site://(.*?)(#c\d+)?\](.*?)\[/url\]!s', '$3', $text); $text = preg_replace('!\[url\]site://(.*?)(#c\d+)?\[/url\]!s', '$1$2', $text); $text = preg_replace('!\[url=((?:https?|ftp|irc|mailto)://.*?)\](.*?)\[/url\]!s', '$2', $text); @@ -77,6 +78,7 @@ class BBCode extends FormatterExtension { ) as $el) { $text = preg_replace("!\[$el\](.*?)\[/$el\]!s", '$1', $text); } + $text = preg_replace("!\[anchor=(.*?)\](.*?)\[/anchor\]!s", '$2', $text); $text = preg_replace("!\[url=(.*?)\](.*?)\[/url\]!s", '$2', $text); $text = preg_replace("!\[img\](.*?)\[/img\]!s", "", $text); $text = preg_replace("!\[\[([^\|\]]+)\|([^\]]+)\]\]!s", '$2', $text); diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php index 14aac004..4e3fd832 100644 --- a/ext/bbcode/test.php +++ b/ext/bbcode/test.php @@ -71,6 +71,12 @@ class BBCodeUnitTest extends UnitTestCase { "spam@shishnet.org"); } + public function testAnchor() { + $this->assertEqual( + $this->filter("[anchor=rules]Rules[/anchor]"), + "Rules"); + } + private function filter($in) { $bb = new BBCode(); return $bb->format($in); From c6518454010dca7e7a674f6850310bcdc0824418 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 30 Aug 2014 13:18:14 +0100 Subject: [PATCH 2/2] make anchors visible in the page, not just in the markup --- ext/bbcode/main.php | 2 +- ext/bbcode/style.css | 6 ++++++ ext/bbcode/test.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index d30d89db..6c4d404e 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -39,7 +39,7 @@ class BBCode extends FormatterExtension { } $text = preg_replace('!^>>([^\d].+)!', '
$1
', $text); $text = preg_replace('!>>(\d+)(#c?\d+)?!s', '>>$1$2', $text); - $text = preg_replace('!\[anchor=(.*?)\](.*?)\[/anchor\]!s', '$2', $text); // add "bb-" to avoid clashing with eg #top + $text = preg_replace('!\[anchor=(.*?)\](.*?)\[/anchor\]!s', '$2 ', $text); // add "bb-" to avoid clashing with eg #top $text = preg_replace('!\[url=site://(.*?)(#c\d+)?\](.*?)\[/url\]!s', '$3', $text); $text = preg_replace('!\[url\]site://(.*?)(#c\d+)?\[/url\]!s', '$1$2', $text); $text = preg_replace('!\[url=((?:https?|ftp|irc|mailto)://.*?)\](.*?)\[/url\]!s', '$2', $text); diff --git a/ext/bbcode/style.css b/ext/bbcode/style.css index ef73687a..200221cc 100644 --- a/ext/bbcode/style.css +++ b/ext/bbcode/style.css @@ -8,3 +8,9 @@ BLOCKQUOTE { padding: 8px; background: #DDD; } +.anchor A.alink { + visibility: hidden; +} +.anchor:hover A.alink { + visibility: visible; +} diff --git a/ext/bbcode/test.php b/ext/bbcode/test.php index 4e3fd832..a1832653 100644 --- a/ext/bbcode/test.php +++ b/ext/bbcode/test.php @@ -74,7 +74,7 @@ class BBCodeUnitTest extends UnitTestCase { public function testAnchor() { $this->assertEqual( $this->filter("[anchor=rules]Rules[/anchor]"), - "Rules"); + 'Rules '); } private function filter($in) {