Added cashtag support for statuses

• Added:
- cashtag support for statuses

Ref: e23931b255
This commit is contained in:
mgabdev
2020-10-30 14:01:55 -05:00
parent 9f712198dc
commit 6db1cf421b
6 changed files with 67 additions and 18 deletions

View File

@@ -54,6 +54,10 @@ function hashtagStrategy(contentBlock, callback, contentState) {
findWithRegex(HASHTAG_REGEX, contentBlock, callback)
}
function cashtagStrategy(contentBlock, callback, contentState) {
findWithRegex(CASHTAG_REGEX, contentBlock, callback)
}
function urlStrategy(contentBlock, callback, contentState) {
findWithRegex(urlRegex, contentBlock, callback)
}
@@ -87,6 +91,10 @@ const compositeDecorator = new CompositeDecorator([
strategy: hashtagStrategy,
component: HighlightedSpan,
},
{
strategy: cashtagStrategy,
component: HighlightedSpan,
},
{
strategy: urlStrategy,
component: HighlightedSpan,
@@ -109,6 +117,7 @@ const styleMap = {
const GROUP_HANDLE_REGEX = /\g\/[\w]+/g
const HANDLE_REGEX = /\@[\w]+/g
const HASHTAG_REGEX = /\#[\w\u0590-\u05ff]+/g
const CASHTAG_REGEX = /\$[\w\u0590-\u05ff]+/g
class Composer extends React.PureComponent {

View File

@@ -50,7 +50,7 @@ class StatusContent extends ImmutablePureComponent {
link.addEventListener('click', this.onMentionClick.bind(this, mention), false)
link.setAttribute('title', mention.get('acct'))
link.removeAttribute('target')
} else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
} else if (['#', '$'].includes(link.textContent[0]) || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false)
link.removeAttribute('target')
} else {
@@ -85,7 +85,7 @@ class StatusContent extends ImmutablePureComponent {
}
onHashtagClick = (hashtag, e) => {
hashtag = hashtag.replace(/^#/, '').toLowerCase()
hashtag = hashtag.replace(/^(#|\$)/, '').toLowerCase()
if (this.context.router && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
e.preventDefault()