Commit edd19b5886d88b87ffa233a3196ca399c5b4268f
- Diff rendering mode:
- inline
- side by side
coefficient.rb
(5 / 2)
|   | |||
| 65 | 65 | # XXX: + also breaks it | |
| 66 | 66 | ||
| 67 | 67 | # maybe laconica-0.7.3/lib/util.php:common_replace_urls_callback() ? | |
| 68 | new.gsub!(/(https?:\/\/([a-zA-Z0-9_%\-+?#\/]|\.(?!\z|\W))+)/, '<a href=" | ||
| 68 | new.gsub!(/(https?:\/\/([a-zA-Z0-9_%\-+?#\/]|\.(?!\z|\s))+)/, '<a href=" | ||
| 69 | 69 | new.gsub!(/@([0-9a-zA-Z_]+)/, '@<a href="http://twitter.com/\1">\1</a>') | |
| 70 | 70 | return new | |
| 71 | 71 | end | |
| … | … | ||
| 82 | 82 | # turns #whatever: into #<link>whatever:</link> | |
| 83 | 83 | ||
| 84 | 84 | # hashtag regexp in laconica is /(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/ | |
| 85 | new.gsub!(/#((?!39;)\S+)/, '#<a href="http://identi.ca/tag/"> | ||
| 85 | # #YouTwitFace." breaks it. | ||
| 86 | # text is: Conan's #Tonight_Show: "In the year 3000 #Facebook, #Twitter, and #YouTube merge to form the largest time-wasting site ever: #YouTwitFace." | ||
| 87 | |||
| 88 | new.gsub!(/(^|\s)#(?:(?!39;)([A-Za-z0-9_\-]+|\.(?!\z|\s)))/, '\1#<a href="http://identi.ca/tag/\2">\2</a>') | ||
| 86 | 89 | ||
| 87 | 90 | # group regexp in laconica is /(?:^|\s)!([A-Za-z0-9]{1,64}) | |
| 88 | 91 | new.gsub!(/(?:!(\S+))/, '!<a href="http://identi.ca/group/\1">\1</a>') |
tests/unit.rb
(45 / 0)
|   | |||
| 88 | 88 | make_user_link(@identica) | |
| 89 | 89 | end | |
| 90 | 90 | end | |
| 91 | |||
| 92 | context "when parsing text from identica" do | ||
| 93 | |||
| 94 | should "correctly parse hashtags" do | ||
| 95 | assert_equal %q(#<a href="http://identi.ca/tag/hashtag">hashtag</a>), | ||
| 96 | identicaify("#hashtag") | ||
| 97 | end | ||
| 98 | |||
| 99 | should "correctly parse hashtags with leading words" do | ||
| 100 | assert_equal %q(whatever #<a href="http://identi.ca/tag/hashtag">hashtag</a>), | ||
| 101 | identicaify("whatever #hashtag") | ||
| 102 | end | ||
| 103 | |||
| 104 | should "correctly parse hashtags with trailing words" do | ||
| 105 | assert_equal %q(#<a href="http://identi.ca/tag/hashtag">hashtag</a> whatever), | ||
| 106 | identicaify("#hashtag whatever") | ||
| 107 | end | ||
| 108 | |||
| 109 | should "correctly parse hashtags with leading and trailing words" do | ||
| 110 | assert_equal %q(leading #<a href="http://identi.ca/tag/hashtag">hashtag</a> whatever), | ||
| 111 | identicaify("leading #hashtag whatever") | ||
| 112 | end | ||
| 113 | |||
| 114 | ['.', ',', '#', '?'].each do |char| | ||
| 115 | should "correctly parse hashtags with the character #{char} at the end of the message." do | ||
| 116 | assert_equal %Q(leading #<a href="http://identi.ca/tag/hashtag">hashtag</a>#{char}), | ||
| 117 | identicaify("leading #hashtag#{char}") | ||
| 118 | end | ||
| 119 | |||
| 120 | should "correctly parse hashtags with the character #{char} with leading and trailing words" do | ||
| 121 | assert_equal %Q(leading #<a href="http://identi.ca/tag/hashtag">hashtag</a>#{char} trailing), | ||
| 122 | identicaify("leading #hashtag#{char} trailing") | ||
| 123 | end | ||
| 124 | end | ||
| 125 | |||
| 126 | should "not turn ' into a link" do | ||
| 127 | assert_equal %q(' #<a href="http://identi.ca/tag/stuff">stuff</a>), | ||
| 128 | identicaify("' #stuff") | ||
| 129 | end | ||
| 130 | |||
| 131 | should "parse regression 1 correctly" do | ||
| 132 | assert_equal %q(Conan's #<a href="http://identi.ca/tag/Tonight_Show">Tonight_Show</a>: "In the year 3000 #<a href="http://identi.ca/tag/Facebook">Facebook</a>, #<a href="http://identi.ca/tag/Twitter">Twitter</a>, and #<a href="http://identi.ca/tag/YouTube">YouTube</a> merge to form the largest time-wasting site ever: #<a href="http://identi.ca/tag/YouTwitFace">YouTwitFace</a>."), #' | ||
| 133 | identicaify("Conan\'s #Tonight_Show: \"In the year 3000 #Facebook, #Twitter, and #YouTube merge to form the largest time-wasting site ever: #YouTwitFace.\"") | ||
| 134 | end | ||
| 135 | end | ||
| 91 | 136 | end |

