Added cashtag support for statuses
• Added:
- cashtag support for statuses
Ref: e23931b255
This commit is contained in:
@@ -13,10 +13,12 @@ module Extractor
|
||||
|
||||
text.to_s.scan(Account::MENTION_RE) do |screen_name, _|
|
||||
match_data = $LAST_MATCH_INFO
|
||||
after = $'
|
||||
after = $'
|
||||
|
||||
unless after =~ Twitter::Regex[:end_mention_match]
|
||||
start_position = match_data.char_begin(1) - 1
|
||||
end_position = match_data.char_end(1)
|
||||
end_position = match_data.char_end(1)
|
||||
|
||||
possible_entries << {
|
||||
screen_name: screen_name,
|
||||
indices: [start_position, end_position],
|
||||
@@ -24,26 +26,25 @@ module Extractor
|
||||
end
|
||||
end
|
||||
|
||||
if block_given?
|
||||
possible_entries.each do |mention|
|
||||
yield mention[:screen_name], mention[:indices].first, mention[:indices].last
|
||||
end
|
||||
end
|
||||
possible_entries.each { |mention| yield mention[:screen_name], mention[:indices].first, mention[:indices].last } if block_given?
|
||||
possible_entries
|
||||
end
|
||||
|
||||
# :yields: hashtag, start, end
|
||||
def extract_hashtags_with_indices(text, **)
|
||||
return [] unless text =~ /#/
|
||||
|
||||
tags = []
|
||||
|
||||
text.scan(Tag::HASHTAG_RE) do |hash_text, _|
|
||||
match_data = $LAST_MATCH_INFO
|
||||
match_data = $LAST_MATCH_INFO
|
||||
start_position = match_data.char_begin(1) - 1
|
||||
end_position = match_data.char_end(1)
|
||||
after = $'
|
||||
end_position = match_data.char_end(1)
|
||||
after = $'
|
||||
|
||||
if after =~ %r{\A://}
|
||||
hash_text.match(/(.+)(https?\Z)/) do |matched|
|
||||
hash_text = matched[1]
|
||||
hash_text = matched[1]
|
||||
end_position -= matched[2].char_length
|
||||
end
|
||||
end
|
||||
@@ -58,7 +59,34 @@ module Extractor
|
||||
tags
|
||||
end
|
||||
|
||||
def extract_cashtags_with_indices(_text)
|
||||
[] # always returns empty array
|
||||
# :yields: cashtag, start, end
|
||||
def extract_cashtags_with_indices(text)
|
||||
return [] unless text =~ /\$/
|
||||
|
||||
tags = []
|
||||
|
||||
text.scan(Tag::CASHTAG_RE) do |cash_text, _|
|
||||
match_data = $LAST_MATCH_INFO
|
||||
start_position = match_data.char_begin(1) - 1
|
||||
end_position = match_data.char_end(1)
|
||||
after = $'
|
||||
|
||||
next if cash_text.size > 5
|
||||
|
||||
if after =~ %r{\A://}
|
||||
cash_text.match(/(.+)(https?\Z)/) do |matched|
|
||||
cash_text = matched[1]
|
||||
end_position -= matched[2].char_length
|
||||
end
|
||||
end
|
||||
|
||||
tags << {
|
||||
cashtag: cash_text,
|
||||
indices: [start_position, end_position],
|
||||
}
|
||||
end
|
||||
|
||||
tags.each { |tag| yield tag[:cashtag], tag[:indices].first, tag[:indices].last } if block_given?
|
||||
tags
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -258,6 +258,8 @@ class Formatter
|
||||
link_to_url(entity, options)
|
||||
elsif entity[:hashtag]
|
||||
link_to_hashtag(entity)
|
||||
elsif entity[:cashtag]
|
||||
link_to_cashtag(entity)
|
||||
elsif entity[:screen_name]
|
||||
link_to_mention(entity, accounts)
|
||||
end
|
||||
@@ -396,6 +398,7 @@ class Formatter
|
||||
end
|
||||
|
||||
entities = Extractor.extract_hashtags_with_indices(escaped, :check_url_overlap => false) +
|
||||
Extractor.extract_cashtags_with_indices(escaped, :check_url_overlap => false) +
|
||||
Extractor.extract_mentions_or_lists_with_indices(escaped)
|
||||
Extractor.remove_overlapping_entities(entities).map do |extract|
|
||||
pos = extract[:indices].first
|
||||
@@ -440,6 +443,10 @@ class Formatter
|
||||
hashtag_html(entity[:hashtag])
|
||||
end
|
||||
|
||||
def link_to_cashtag(entity)
|
||||
cashtag_html(entity[:cashtag])
|
||||
end
|
||||
|
||||
def link_html(url)
|
||||
url = Addressable::URI.parse(url).to_s
|
||||
prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s
|
||||
@@ -454,6 +461,10 @@ class Formatter
|
||||
"<a data-focusable=\"true\" role=\"link\" href=\"#{encode(tag_url(tag.downcase))}\" class=\"mention hashtag\" rel=\"tag\">##{encode(tag)}</a>"
|
||||
end
|
||||
|
||||
def cashtag_html(tag)
|
||||
"<a data-focusable=\"true\" role=\"link\" href=\"#{encode(tag_url(tag.downcase))}\" class=\"mention hashtag cashtag\" rel=\"tag\">$#{encode(tag)}</a>"
|
||||
end
|
||||
|
||||
def mention_html(account)
|
||||
return "<span>@#{encode(account.acct)}</span>" unless account.local?
|
||||
"<a data-focusable=\"true\" role=\"link\" href=\"#{encode(TagManager.instance.url_for(account))}\" class=\"u-url mention\">@#{encode(account.acct)}</a>"
|
||||
|
||||
Reference in New Issue
Block a user