diff --git a/lib/Twitter/Text/Autolink.php b/lib/Twitter/Text/Autolink.php
index e18ee1c..d03256d 100644
--- a/lib/Twitter/Text/Autolink.php
+++ b/lib/Twitter/Text/Autolink.php
@@ -137,6 +137,22 @@ class Autolink
*/
protected $usernameIncludeSymbol = false;
+ /**
+ * HTML tag to be applied around #/@/# symbols in hashtags/usernames/lists/cashtag
+ *
+ * @var string
+ * @since 3.0.1
+ */
+ protected $symbolTag = '';
+
+ /**
+ * HTML tag to be applied around text part of hashtags/usernames/lists/cashtag
+ *
+ * @var string
+ * @since 3.0.1
+ */
+ protected $textWithSymbolTag = '';
+
/**
*
* @var Extractor
@@ -418,6 +434,52 @@ public function setUsernameIncludeSymbol($usernameIncludeSymbol)
return $this;
}
+ /**
+ * @return string
+ * @since 3.0.1
+ */
+ public function getSymbolTag()
+ {
+ return $this->symbolTag;
+ }
+
+ /**
+ * Set HTML tag to be applied around #/@/# symbols in hashtags/usernames/lists/cashtag
+ *
+ * @param string $symbolTag HTML tag without bracket. e.g., 'b' or 's'
+ * @return Autolink
+ * @since 3.0.1
+ */
+ public function setSymbolTag($symbolTag)
+ {
+ $this->symbolTag = $symbolTag;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ * @since 3.0.1
+ */
+ public function getTextWithSymbolTag()
+ {
+ return $this->textWithSymbolTag;
+ }
+
+ /**
+ * Set HTML tag to be applied around text part of hashtags/usernames/lists/cashtag
+ *
+ * @param string $textWithSymbolTag HTML tag without bracket. e.g., 'b' or 's'
+ * @return Autolink
+ * @since 3.0.1
+ */
+ public function setTextWithSymbolTag($textWithSymbolTag)
+ {
+ $this->textWithSymbolTag = $textWithSymbolTag;
+
+ return $this;
+ }
+
/**
* Autolink with entities
*
@@ -794,6 +856,13 @@ protected function linkToTextWithSymbol(array $entity, $symbol, $linkText, array
{
$includeSymbol = $this->usernameIncludeSymbol || !preg_match('/[@@]/u', $symbol);
+ if (!empty($this->symbolTag)) {
+ $symbol = sprintf('<%1$s>%2$s%1$s>', $this->symbolTag, $symbol);
+ }
+ if (!empty($this->textWithSymbolTag)) {
+ $linkText = sprintf('<%1$s>%2$s%1$s>', $this->textWithSymbolTag, $linkText);
+ }
+
if (!$includeSymbol) {
return $symbol . $this->linkToText($entity, $linkText, $attributes);
}
diff --git a/tests/TestCase/AutolinkTest.php b/tests/TestCase/AutolinkTest.php
index 49c1cae..60c696c 100644
--- a/tests/TestCase/AutolinkTest.php
+++ b/tests/TestCase/AutolinkTest.php
@@ -64,4 +64,26 @@ public function testUsernameIncludeSymbol()
$linkedText = $this->linker->autoLink($tweet);
$this->assertSame($expected, $linkedText);
}
+
+ public function testSymbolTag()
+ {
+ $this->linker
+ ->setExternal(false)
+ ->setTarget(false)
+ ->setNoFollow(false)
+ ->setSymbolTag('s')
+ ->setTextWithSymbolTag('b');
+
+ $tweet = '#hash';
+ $expected = '';
+ $this->assertSame($expected, $this->linker->autoLink($tweet));
+
+ $tweet = '@mention';
+ $expected = '@';
+ $this->assertSame($expected, $this->linker->autoLink($tweet));
+
+ $this->linker->setUsernameIncludeSymbol(true);
+ $expected = '';
+ $this->assertSame($expected, $this->linker->autoLink($tweet));
+ }
}