Skip to content
This repository
Newer
Older
100644 125 lines (79 sloc) 4.195 kb
537ce28b » bcherry
2010-10-22 readme
1 # twitter-text-js
2
2e53aff9 » ded
2011-07-11 make note on npm installation
3 A JavaScript utility that provides text processing routines for Tweets. This library conforms to a common test suite shared by many other implementations, particularly twitter-text.gem (Ruby). The library provides autolinking and extraction for URLs, usernames, lists, and hashtags.
4
5 ## NPM Users
6
7 Install it with: `npm install twitter-text`
8
9 The `twttr.txt` namespace is exported, making it available as such:
10
11 ``` js
12 var twitter = require('twitter-text')
13 twitter.autoLink(twitter.htmlEscape('#hello < @world >'))
14 ```
537ce28b » bcherry
2010-10-22 readme
15
16 ## Extraction Examples
17
18 // basic extraction
19 var usernames = twttr.txt.extract_mentioned_screen_names("Mentioning @twitter and @jack")
20 // usernames == ["twitter", "jack"]
21
22 ## Auto-linking Examples
23
24 twttr.txt.autoLink("link @user, please #request");
d5747208 » smerchek
2012-02-03 Cleaned up autolink example for urlEntities.
25
f31b48a4 » smerchek
2012-02-03 Added autolink example with urlEntities option.
26 twttr.txt.autoLink("link @user, and expand url... http://t.co/0JG5Mcq", {
27 urlEntities: [
28 {
29 "url": "http://t.co/0JG5Mcq",
30 "display_url": "blog.twitter.com/2011/05/twitte…",
31 "expanded_url": "http://blog.twitter.com/2011/05/twitter-for-mac-update.html",
32 "indices": [
33 30,
4cd54d28 » smerchek
2012-02-03 Update README.md
34 48
f31b48a4 » smerchek
2012-02-03 Added autolink example with urlEntities option.
35 ]
36 }
37 ]});
38
d5747208 » smerchek
2012-02-03 Cleaned up autolink example for urlEntities.
39 See [Tweet Entities](https://dev.twitter.com/docs/tweet-entities) for more info getting url entities from Twitter's API.
f31b48a4 » smerchek
2012-02-03 Added autolink example with urlEntities option.
40
537ce28b » bcherry
2010-10-22 readme
41
42 ## Usernames
43
44 Username extraction and linking matches all valid Twitter usernames but does
45 not verify that the username is a valid Twitter account.
46
47 ## Lists
48
49 Auto-link and extract list names when they are written in @user/list-name
50 format.
51
52 ## Hashtags
53
54 Auto-link and extract hashtags, where a hashtag contains any latin letter or
55 number but cannot be solely numbers.
56
57 ## URLs
58
e8b14565 » keitaf
2012-01-03 Update README with a detailed note about URL extraction/auto-link.
59 Asian languages like Chinese, Japanese or Korean may not use a delimiter such as
60 a space to separate normal text from URLs making it difficult to identify where
61 the URL ends and the text starts.
62
63 For this reason twitter-text currently does not support extracting or auto-linking
64 of URLs immediately followed by non-Latin characters.
65
66 Example: "http://twitter.com/は素晴らしい" .
67 The normal text is "は素晴らしい" and is not part of the URL even though
68 it isn't space separated.
537ce28b » bcherry
2010-10-22 readme
69
70 ## International
71
72 Special care has been taken to be sure that auto-linking and extraction work
73 in Tweets of all languages. This means that languages without spaces between
74 words should work equally well.
75
76 ## Hit Highlighting
77
78 Use to provide emphasis around the "hits" returned from the Search API, built
79 to work against text that has been auto-linked already.
80
81 ## Testing
82
83 ### Conformance
84
85 The main test suite is twitter-text-conformance. This is set up as a git submodule that is automatically updated at each run. Tests are run in your browser, using QUnit. To run the conformance suite, from the project root, run:
86
87 rake test:conformance
88
89 Your default browser will open the test suite. You should open the test suite in your other browsers as you see fit.
90
91 ### Other Tests
92
93 There are a few tests specific to twitter-text-js that are not part of the conformance suite. To run these, from the project root, run:
94
95 rake test
96
97 Your default browser will open the test suite.
98
99 ## Packaging
100
101 Official versions are kept in the `pkg/` directory. To roll a new version, (ex. v1.1.0), run the following from project root:
102
35b9eb66 » bcherry
2010-11-01 version 1.0.3
103 rake package[1.1.0]
537ce28b » bcherry
2010-10-22 readme
104
105 This will make a new file at `pkg/twitter-text-1.1.0.js`.
106
107 ## Reporting Bugs
108
27e2b44a » bcherry
2011-04-29 update license
109 Please direct bug reports to the [twitter-text-js issue tracker on GitHub](http://github.com/bcherry/twitter-text-js/issues)
110
111 ## Copyright and License
112
113 Copyright 2011 Twitter, Inc.
114
115 Licensed under the Apache License, Version 2.0 (the "License");
116 you may not use this work except in compliance with the License.
117 You may obtain a copy of the License in the LICENSE file, or at:
118
119 http://www.apache.org/licenses/LICENSE-2.0
120
121 Unless required by applicable law or agreed to in writing, software
122 distributed under the License is distributed on an "AS IS" BASIS,
123 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124 See the License for the specific language governing permissions and
e8b14565 » keitaf
2012-01-03 Update README with a detailed note about URL extraction/auto-link.
125 limitations under the License.
Something went wrong with that request. Please try again.