diff --git a/Gemfile b/Gemfile index 2beacc4..75c6be3 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,8 @@ gem "uglifier" gem "nokogiri" gem "htmlentities" +gem "rdiscount" + group :test, :development do gem "rspec-rails", "~> 2.6" gem "machinist" diff --git a/Gemfile.lock b/Gemfile.lock index 1c92a00..f24e5b7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,7 @@ GEM thor (~> 0.14.6) raindrops (0.9.0) rake (0.9.2.2) + rdiscount (1.6.8) rdoc (3.12) json (~> 1.4) rspec (2.9.0) @@ -128,6 +129,7 @@ DEPENDENCIES mysql2 nokogiri rails (= 3.2.2) + rdiscount rspec-rails (~> 2.6) sqlite3 uglifier diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index a2cffbf..6cdbf53 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -441,10 +441,9 @@ div.story_text p { margin: 0.75em 0; } blockquote { - display: inline; font-style: italic; - margin: 0px; - padding: 0px 0px 0px 0.5em; + margin: 0 0 0 1em; + padding: 0 0 0 0.5em; border-left: 2px solid gray; } diff --git a/app/models/comment.rb b/app/models/comment.rb index 115c2db..e3898eb 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -81,7 +81,8 @@ class Comment < ActiveRecord::Base end def linkified_comment - Markdowner.markdown(self.comment) + RDiscount.new(self.comment, :smart, :autolink, :safelink, + :filter_html).to_html end def flag! diff --git a/app/models/keystore.rb b/app/models/keystore.rb index 5ab5d43..a06e0da 100644 --- a/app/models/keystore.rb +++ b/app/models/keystore.rb @@ -8,9 +8,9 @@ class Keystore < ActiveRecord::Base end def self.put(key, value) - Keystore.connection.execute("INSERT INTO #{Keystore.table_name} (" + - "`key`, `value`) VALUES (#{q(key)}, #{q(value)}) ON DUPLICATE KEY " + - "UPDATE `value` = #{q(value)}") + Keystore.connection.execute("INSERT OR REPLACE INTO " << + "#{Keystore.table_name} (`key`, `value`) VALUES " << + "(#{q(key)}, #{q(value)})") true end @@ -21,9 +21,9 @@ class Keystore < ActiveRecord::Base def self.incremented_value_for(key, amount = 1) new_value = nil - Keystore.connection.execute("INSERT INTO #{Keystore.table_name} (" + - "`key`, `value`) VALUES (#{q(key)}, #{q(amount)}) ON DUPLICATE KEY " + - "UPDATE `value` = `value` + #{q(amount)}") + Keystore.connection.execute("INSERT OR REPLACE INTO " << + "#{Keystore.table_name} (`key`, `value`) VALUES " << + "(#{q(key)}, #{q(amount)})") return self.value_for(key) end diff --git a/app/models/story.rb b/app/models/story.rb index e8d6c4c..519c3fb 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -138,7 +138,8 @@ class Story < ActiveRecord::Base end def linkified_text - Markdowner.markdown(self.description) + RDiscount.new(self.description, :smart, :autolink, :safelink, + :filter_html).to_html end def tags_a diff --git a/app/views/comments/_commentbox.html.erb b/app/views/comments/_commentbox.html.erb index 1d0a119..59764d0 100644 --- a/app/views/comments/_commentbox.html.erb +++ b/app/views/comments/_commentbox.html.erb @@ -13,7 +13,7 @@
" - inpre = false - lines.each do |line| - # [ ][ ]blah ->
blah- if line.match(/^( |\t)/) - if !inpre - out << "
" - end - - out << ERB::Util.h(line) << "\n" - inpre = true - next - elsif inpre - out << "\n
" - inpre = false - end - - line = self.h(line) - - # lines starting with > are quoted - if m = line.match(/^>(.*)/) - line = "
" << m[1] << "" - end - - lead = '\A|\s|[><]' - trail = '[<>]|\z|\s' - - # *text* -> text - line.gsub!(/(#{lead}|_|~)\*([^\* \t][^\*]*)\*(#{trail}|_|~)/) do |m| - "#{$1}" << self.h($2) << "#{$3}" - end - - # _text_ -> text - line.gsub!(/(#{lead}|~)_([^_ \t][^_]*)_(#{trail}|~)/) do |m| - "#{$1}" << self.h($2) << "#{$3}" - end - - # ~~text~~ ->
")
-
- # collapse things
- out.gsub!(/
\n?<\/p>/, "
\n?
\n?/, "
") - out.gsub!(/
\n?<\/p>/, "\n") - out.gsub!(/
\n?
/, "\n
") - out.gsub!(/<\/p>
/, "
\n") - - out.strip.force_encoding("utf-8") - end - - def self._linkify_text(chunk) - chunk.gsub(/ - (\A|\s|[:,]) - (http(s?):\/\/|www\.) - ([^\s]+)/ix) do |m| - pre = $1 - host_and_path = "#{$2 == "www." ? $2 : ""}#{$4}" - post = $5 - - # remove some chars that might be with a url at the end but aren't - # actually part of the url - if m = host_and_path.match(/(.*)([,\?;\!\.]+)\z/) - host_and_path = m[1] - post = "#{m[2]}#{post}" - end - - url = "http#{$3}://#{host_and_path}" - url_text = host_and_path - - if url_text.length > 50 - url_text = url_text[0 ... 50] << "..." - end - - "#{pre}#{url_text}#{post}" - end - end -end diff --git a/spec/models/markdowner_spec.rb b/spec/models/markdowner_spec.rb deleted file mode 100644 index efdede9..0000000 --- a/spec/models/markdowner_spec.rb +++ /dev/null @@ -1,104 +0,0 @@ -require "spec_helper" - -def m(inp, out) - Markdowner::markdown(inp).should == out -end - -describe Markdowner do - it "converts indented text into
" do - m " This is some\n text.\n", - "This is some\n text.\n" - - m " blah ", - "blah <script>alert('hi');</script>\n" - end - - it "converts text surrounded by * to " do - m "oh hullo *there*", - "oh hullo there
" - - m "*hi*", - "hi
" - - m "* hi hello*zap zap*", - "* hi hello*zap zap*
" - - m "oh hullo * there*", - "oh hullo * there*
" - - m " oh hullo *there*", - "oh hullo *there*\n" - - m "oh hullo*there*", - "oh hullo*there*
" - end - - it "converts text surrounded by _ to " do - m "oh hullo _there_", - "oh hullo there
" - - m "oh hullo _ there_", - "oh hullo _ there_
" - - m "oh hullo _there_ and *yes* i see", - "oh hullo there and yes i see
" - end - - it "combines conversions" do - m "oh _*hullo*_ there_", - "oh hullo there_
" - - m "oh *_hullo_* there_", - "oh hullo there_
" - - m "oh *[hello](http://jcs.org/)* there_", - "oh hello" << - " there_
" - end - - it "converts domain names to links" do - m "oh hullo www.google.com", - "oh hullo " << - "www.google.com
" - end - - it "converts urls to links" do - # no trailing question mark - m "do you mean http://jcs.org? or", - "do you mean " << - "jcs.org? or
" - - m "do you mean http://jcs.org?a", - "do you mean " << - "jcs.org?a
" - - # no trailing dot in url - m "i like http://jcs.org.", - "i like " << - "jcs.org.
" - - m "i like http://jcs.org/goose_blah_here", - "i like jcs.org/goose_blah_here
" - end - - it "truncates long url titles" do - m "a long http://www.example.com/goes/here/and/this/is/a/long/" << - "url/which/should.get.shortened.html?because=this+will+cause+" << - "the+page+to+wrap&such+ok", - "a long " << - "www.example.com/goes/here/and/this/is/a/long/url/w...
" - end - - it "converts markdown url format to links" do - m "this is a *[link](http://example.com/)*", - "this is a " << - "link
" - - m "this is a [link](http://example.com/)", - "this is a " << - "link
" - end -end