Browse files

added support for inline code blocks. added support for reference sty…

…le links. added flash version checking for when websockets arent available. updated readme
  • Loading branch information...
1 parent 5842f10 commit d665c414f49c4e9543388b16d6a29126cf5baec6 Andrew Havens committed Feb 13, 2012
Showing with 26 additions and 20 deletions.
  1. +1 −1 Gemfile.lock
  2. +1 −5 README.md
  3. +11 −5 lib/mad_chatter/message_listeners/markdown.rb
  4. +11 −6 spec/message_listeners/markdown_spec.rb
  5. +2 −3 templates/web/index.html
View
2 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- mad_chatter (0.3.0)
+ mad_chatter (0.3.2)
daemons (= 1.1.4)
em-websocket
eventmachine
View
6 README.md
@@ -77,18 +77,14 @@ Once you've got your chat server running and being used by other people, you mig
## Getting Help / Providing Feedback
-Feel free to submit a GitHub issue, or post to the [Google Group](https://groups.google.com/group/mad-chatter), or send me a message on GitHub.
+Feel free to submit bug reports and feature requests to our [GitHub Issues page](https://github.com/andrewhavens/mad_chatter/issues), or post to the [Google Group](https://groups.google.com/group/mad-chatter), or send me a message on GitHub.
You can also vote on upcoming features: https://madchatter.uservoice.com
## Contributing
Please fork and send pull requests! Or submit issues if you have suggestions on how to improve.
-## TODO
-
- - Maybe add support for alternative web socket servers like Juggernaut, Socket.io, or Cramp and web-socket-js
-
##Copyright
Copyright (c) 2011-2012 Andrew Havens. MIT license. See LICENSE.txt for further details.
View
16 lib/mad_chatter/message_listeners/markdown.rb
@@ -14,6 +14,9 @@ def apply_markdown(text)
text.gsub!(/^[\w\<][^\n]*\n+/) do |x|
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
end
+
+ # inline code (backticks)
+ text.gsub!(%r{(^|\s)(\`)(.+?)\2(\s|$)}, %{\\1<code>\\3</code>\\4})
# autolink email addresses
text.gsub!(/([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})/i) do |x|
@@ -24,18 +27,21 @@ def apply_markdown(text)
text.gsub!(/(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/(\S)+)?/i) do |x|
href = $&
# check if we're in a markdown link
- if $` =~ /[(]/
+ if $` =~ /[(]/
x = href
- else
+ else
x = %Q{<a target="_blank" href="#{href}">#{href}</a>}
- end
+ end
end
+ # reference style links: [link text](http://link.url)
+ text.gsub!(%r{\[([^\]]+)\]\((\S+(?=\)))\)}, %{<a target="_blank" href="\\2">\\1</a>})
+
# bold (must come before italic)
- text.gsub!(%r{(^|\s)(\*\*|__)(.+?)\2(\s|$)}x, %{\\1<strong>\\3</strong>\\4})
+ text.gsub!(%r{(^|\s)(\*\*|__)(.+?)\2(\s|$)}, %{\\1<strong>\\3</strong>\\4})
# italic
- text.gsub!(%r{(^|\s)([*_])(.+?)\2(\s|$)}x, %{\\1<em>\\3</em>\\4})
+ text.gsub!(%r{(^|\s)([*_])(.+?)\2(\s|$)}, %{\\1<em>\\3</em>\\4})
return text
end
View
17 spec/message_listeners/markdown_spec.rb
@@ -37,11 +37,16 @@
message.html.should == 'here is a <strong>strong</strong> statement'
end
- # TODO
- # it 'should interpret markdown style links' do
- # message = MadChatter::Message.new('message', "[link me up](http://www.example.com)")
- # listener.handle(message)
- # message.html.should == '<a target="_blank" href="http://www.example.com">link me up</a>'
- # end
+ it 'should parse backticks as inline code' do
+ message = MadChatter::Message.new('message', "this has `some code` in it")
+ listener.handle(message)
+ message.html.should == 'this has <code>some code</code> in it'
+ end
+
+ it 'should parse markdown style links' do
+ message = MadChatter::Message.new('message', "[link me up](http://www.example.com)")
+ listener.handle(message)
+ message.html.should == '<a target="_blank" href="http://www.example.com">link me up</a>'
+ end
end
View
5 templates/web/index.html
@@ -179,10 +179,9 @@
<script src='js/mad_chatter_actions.js'></script>
<script src='js/mad_chatter_config.js'></script>
<script>
- WEB_SOCKET_DEBUG = true;
- if (!window.WebSocket && !window.MozWebSocket && swfobject.getFlashPlayerVersion().major < 10) {
- $('#upgrade_flash').show();
+ if (!window.WebSocket && swfobject.getFlashPlayerVersion().major < 10) {
$('#login_screen').hide();
+ $('#upgrade_flash').show();
} else {
MadChatter.init(mad_chatter_config);
}

0 comments on commit d665c41

Please sign in to comment.