[anchor] bbcode tag, to make linking to parts of a page easier
This commit is contained in:
parent
b1d634a8de
commit
9c71f59061
2 changed files with 8 additions and 0 deletions
|
@ -39,6 +39,7 @@ class BBCode extends FormatterExtension {
|
|||
}
|
||||
$text = preg_replace('!^>>([^\d].+)!', '<blockquote><small>$1</small></blockquote>', $text);
|
||||
$text = preg_replace('!>>(\d+)(#c?\d+)?!s', '<a class="shm-clink" data-clink-sel="$2" href="'.make_link('post/view/$1$2').'">>>$1$2</a>', $text);
|
||||
$text = preg_replace('!\[anchor=(.*?)\](.*?)\[/anchor\]!s', '<a name="bb-$1">$2</a>', $text); // add "bb-" to avoid clashing with eg #top
|
||||
$text = preg_replace('!\[url=site://(.*?)(#c\d+)?\](.*?)\[/url\]!s', '<a class="shm-clink" data-clink-sel="$2" href="'.make_link('$1$2').'">$3</a>', $text);
|
||||
$text = preg_replace('!\[url\]site://(.*?)(#c\d+)?\[/url\]!s', '<a class="shm-clink" data-clink-sel="$2" href="'.make_link('$1$2').'">$1$2</a>', $text);
|
||||
$text = preg_replace('!\[url=((?:https?|ftp|irc|mailto)://.*?)\](.*?)\[/url\]!s', '<a href="$1">$2</a>', $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);
|
||||
|
|
|
@ -71,6 +71,12 @@ class BBCodeUnitTest extends UnitTestCase {
|
|||
"<a href=\"mailto:spam@shishnet.org\">spam@shishnet.org</a>");
|
||||
}
|
||||
|
||||
public function testAnchor() {
|
||||
$this->assertEqual(
|
||||
$this->filter("[anchor=rules]Rules[/anchor]"),
|
||||
"<a name=\"bb-rules\">Rules</a>");
|
||||
}
|
||||
|
||||
private function filter($in) {
|
||||
$bb = new BBCode();
|
||||
return $bb->format($in);
|
||||
|
|
Reference in a new issue