Skip to content

Commit 160cace

Browse files
committed
Upgrade to commonmarker version 1.x
- Update commonmarker dependency to ~> 1.0 - Adjust code to changes in commonmarker's API - Avoid using nil.to_s since that returns an String with ASCII encoding which commonmarker doesn't accept
1 parent 7fbd069 commit 160cace

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

app/models/content_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def html(field = :all)
3333
# Generate HTML for a specific field using the text_filter in use for this
3434
# object.
3535
def generate_html(field, text = nil)
36-
text ||= self[field].to_s
36+
text ||= self[field] || ""
3737
html = (text_filter || default_text_filter).filter_text(text) || text
3838
html_postprocess(field, html).to_s
3939
end

app/models/text_filter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def help
4444
if f.help_text.blank?
4545
""
4646
else
47-
"<h3>#{f.display_name}</h3>\n#{CommonMarker.render_html(f.help_text, :DEFAULT)}"
47+
"<h3>#{f.display_name}</h3>\n#{Commonmarker.to_html(f.help_text)}"
4848
end
4949
end
5050

@@ -56,7 +56,7 @@ def commenthelp
5656
.expand_filter_list([markup, filters].flatten)
5757

5858
help_filters.map do |f|
59-
f.help_text.blank? ? "" : CommonMarker.render_html(f.help_text)
59+
f.help_text.blank? ? "" : Commonmarker.to_html(f.help_text)
6060
end.join("\n")
6161
end
6262

lib/publify_core/text_filter/markdown.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def self.help_text
4646
def self.filtertext(text)
4747
# FIXME: Workaround for <publify:foo> not being interpreted as an HTML tag.
4848
escaped_macros = text.gsub(%r{(</?publify):}, '\1X')
49-
html = CommonMarker.render_html(escaped_macros, :UNSAFE)
49+
html = Commonmarker.to_html(escaped_macros, options: {
50+
render: { unsafe: true }
51+
})
5052
html.gsub(%r{(</?publify)X}, '\1:').strip
5153
end
5254
end

lib/publify_core/text_filter/markdown_smartquotes.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class MarkdownSmartquotes < PublifyCore::TextFilter::Markdown
1313
def self.filtertext(text)
1414
# FIXME: Workaround for <publify:foo> not being interpreted as an HTML tag.
1515
escaped_macros = text.gsub(%r{(</?publify):}, '\1X')
16-
html = CommonMarker.render_doc(escaped_macros, :SMART).to_html(:UNSAFE)
16+
html = Commonmarker.to_html(escaped_macros, options: {
17+
parse: { smart: true },
18+
render: { unsafe: true }
19+
})
1720
html.gsub(%r{(</?publify)X}, '\1:').strip
1821
end
1922
end

publify_core.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
2424
s.add_dependency "bootstrap", "~> 4.6.2"
2525
s.add_dependency "cancancan", "~> 3.0"
2626
s.add_dependency "carrierwave", "~> 3.0"
27-
s.add_dependency "commonmarker", "~> 0.23.2"
27+
s.add_dependency "commonmarker", "~> 1.0"
2828
s.add_dependency "devise", ">= 4.8", "< 4.10"
2929
s.add_dependency "devise-i18n", "~> 1.2"
3030
s.add_dependency "devise_zxcvbn", "~> 6.0"

0 commit comments

Comments
 (0)