Simple replacement with CommonMarker
This commit is contained in:
parent
1691b589e0
commit
9288c83ef5
2
Gemfile
2
Gemfile
|
@ -26,7 +26,7 @@ gem "rqrcode"
|
||||||
|
|
||||||
gem "nokogiri", "= 1.6.1"
|
gem "nokogiri", "= 1.6.1"
|
||||||
gem "htmlentities"
|
gem "htmlentities"
|
||||||
gem "rdiscount"
|
gem "commonmarker", "~> 0.14"
|
||||||
|
|
||||||
gem "activerecord-typedstore"
|
gem "activerecord-typedstore"
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,19 @@ class Markdowner
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
args = [ :smart, :autolink, :safelink, :filter_styles, :filter_html,
|
exts = [:tagfilter, :autolink]
|
||||||
:strict ]
|
root = CommonMarker.render_doc(text.to_s, [:SMART], exts)
|
||||||
if !opts[:allow_images]
|
ng = Nokogiri::HTML(root.to_html([:SAFE], exts))
|
||||||
args.push :no_image
|
|
||||||
end
|
|
||||||
|
|
||||||
ng = Nokogiri::HTML(RDiscount.new(text.to_s, *args).to_html)
|
|
||||||
|
|
||||||
# change <h1>, <h2>, etc. headings to just bold tags
|
# change <h1>, <h2>, etc. headings to just bold tags
|
||||||
ng.css("h1, h2, h3, h4, h5, h6").each do |h|
|
ng.css("h1, h2, h3, h4, h5, h6").each do |h|
|
||||||
h.name = "strong"
|
h.name = "strong"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !opts[:allow_images]
|
||||||
|
ng.css("img").remove
|
||||||
|
end
|
||||||
|
|
||||||
# make links have rel=nofollow
|
# make links have rel=nofollow
|
||||||
ng.css("a").each do |h|
|
ng.css("a").each do |h|
|
||||||
h[:rel] = "nofollow"
|
h[:rel] = "nofollow"
|
||||||
|
|
Loading…
Reference in a new issue