Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:twitter/twitter-text-rb into bett…
Browse files Browse the repository at this point in the history
…er_copy
  • Loading branch information
keita committed Feb 10, 2012
2 parents 8bc4ddd + e128728 commit d91a9ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
15 changes: 11 additions & 4 deletions README.rdoc
Expand Up @@ -55,9 +55,16 @@ numbers but cannot be solely numbers and cannot contain punctuation.

=== URLs

Auto-linking and extraction of URLs differs from the Rails default so that it
will work correctly in Tweets written in languages that do not include spaces
between words.
Asian languages like Chinese, Japanese or Korean may not use a delimiter such as
a space to separate normal text from URLs making it difficult to identify where
the URL ends and the text starts.

For this reason twitter-text currently does not support extracting or auto-linking
of URLs immediately followed by non-Latin characters.

Example: "http://twitter.com/は素晴らしい" .
The normal text is "は素晴らしい" and is not part of the URL even though
it isn't space separated.

=== International

Expand Down Expand Up @@ -112,4 +119,4 @@ Thanks to everybody who has filed issues, provided feedback or contributed patch
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
4 changes: 2 additions & 2 deletions lib/autolink.rb
Expand Up @@ -237,10 +237,10 @@ def auto_link_urls_custom(text, href_options = {})
BOOLEAN_ATTRIBUTES = Set.new([:disabled, :readonly, :multiple, :checked]).freeze

def html_attrs_for_options(options)
html_attrs options.reject{|k, v| OPTIONS_NOT_ATTRIBUTES.include?(k)}
autolink_html_attrs options.reject{|k, v| OPTIONS_NOT_ATTRIBUTES.include?(k)}
end

def html_attrs(options)
def autolink_html_attrs(options)
options.inject("") do |attrs, (key, value)|
if BOOLEAN_ATTRIBUTES.include?(key)
value = value ? key : nil
Expand Down
18 changes: 15 additions & 3 deletions lib/regex.rb
Expand Up @@ -65,7 +65,19 @@ def self.regex_range(from, to = nil) # :nodoc:
regex_range(0xc0, 0xd6),
regex_range(0xd8, 0xf6),
regex_range(0xf8, 0xff),
regex_range(0x015f)
regex_range(0x0100, 0x024f),
regex_range(0x0253, 0x0254),
regex_range(0x0256, 0x0257),
regex_range(0x0259),
regex_range(0x025b),
regex_range(0x0263),
regex_range(0x0268),
regex_range(0x026f),
regex_range(0x0272),
regex_range(0x0289),
regex_range(0x028b),
regex_range(0x02bb),
regex_range(0x1e00, 0x1eff)
].join('').freeze

NON_LATIN_HASHTAG_CHARS = [
Expand Down Expand Up @@ -110,12 +122,12 @@ def self.regex_range(from, to = nil) # :nodoc:

REGEXEN[:at_signs] = /[@@]/
REGEXEN[:extract_mentions] = /(^|[^a-zA-Z0-9_!#\$%&*@@])#{REGEXEN[:at_signs]}([a-zA-Z0-9_]{1,20})/o
REGEXEN[:extract_mentions_or_lists] = /(^|[^a-zA-Z0-9_])#{REGEXEN[:at_signs]}([a-zA-Z0-9_]{1,20})(\/[a-zA-Z][a-zA-Z0-9_\-]{0,24})?/o
REGEXEN[:extract_mentions_or_lists] = /(^|[^a-zA-Z0-9_!#\$%&*@@])#{REGEXEN[:at_signs]}([a-zA-Z0-9_]{1,20})(\/[a-zA-Z][a-zA-Z0-9_\-]{0,24})?/o
REGEXEN[:extract_reply] = /^(?:#{REGEXEN[:spaces]})*#{REGEXEN[:at_signs]}([a-zA-Z0-9_]{1,20})/o
# Used in Extractor and Rewriter for final filtering
REGEXEN[:end_screen_name_match] = /\A(?:#{REGEXEN[:at_signs]}|#{REGEXEN[:latin_accents]}|:\/\/)/o

REGEXEN[:auto_link_usernames_or_lists] = /([^a-zA-Z0-9_]|^|RT:?)([@@]+)([a-zA-Z0-9_]{1,20})(\/[a-zA-Z][a-zA-Z0-9_\-]{0,24})?/o
REGEXEN[:auto_link_usernames_or_lists] = /([^a-zA-Z0-9_!#\$%&*@@]|^|RT:?)([@@]+)([a-zA-Z0-9_]{1,20})(\/[a-zA-Z][a-zA-Z0-9_\-]{0,24})?/o
REGEXEN[:auto_link_emoticon] = /(8\-\#|8\-E|\+\-\(|\`\@|\`O|\<\|:~\(|\}:o\{|:\-\[|\>o\<|X\-\/|\[:-\]\-I\-|\/\/\/\/Ö\\\\\\\\|\(\|:\|\/\)|∑:\*\)|\( \| \))/

# URL related hash regex collection
Expand Down
2 changes: 1 addition & 1 deletion twitter-text.gemspec
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = "twitter-text"
s.version = "1.4.15"
s.version = "1.4.16"
s.authors = ["Matt Sanford", "Patrick Ewing", "Ben Cherry", "Britt Selvitelle",
"Raffi Krikorian", "J.P. Cummins", "Yoshimasa Niwa", "Keita Fujii"]
s.email = ["matt@twitter.com", "patrick.henry.ewing@gmail.com", "bcherry@gmail.com", "bs@brittspace.com",
Expand Down

0 comments on commit d91a9ff

Please sign in to comment.