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