Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Bump commonmarker from 0.23.9 to 1.0.3 Bumps [commonmarker](https://github.com/gjtorikian/commonmarker) from 0.23.9 to 1.0.3. - [Release notes](https://github.com/gjtorikian/commonmarker/releases) - [Changelog](https://github.com/gjtorikian/commonmarker/blob/v1.0.3/CHANGELOG.md) - [Commits](gjtorikian/[email protected])

as-op95a9cdbe1550
diff --git a/Gemfile b/Gemfile
index 48dfdb5b2ef..8b5136b7ece 100644
--- a/Gemfile
+++ b/Gemfile
@@ -79,7 +79,7 @@ gem 'htmldiff'
gem 'stringex', '~> 2.8.5'
# CommonMark markdown parser with GFM extension
-gem 'commonmarker', '~> 0.23.9'
+gem 'commonmarker', '~> 1.0.3'
# HTML pipeline for transformations on text formatter output
# such as sanitization or additional features
diff --git a/Gemfile.lock b/Gemfile.lock
index 337aaaa7a0a..953475f1eac 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -399,7 +399,8 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
colored2 (4.0.0)
- commonmarker (0.23.10)
+ commonmarker (1.0.3)
+ rb_sys (~> 0.9)
compare-xml (0.66)
nokogiri (~> 1.8)
concurrent-ruby (1.2.2)
@@ -859,6 +860,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
+ rb_sys (0.9.85)
rbtree3 (0.7.1)
rdoc (6.6.2)
psych (>= 4.0.0)
@@ -1107,7 +1109,7 @@ DEPENDENCIES
climate_control
closure_tree (~> 7.4.0)
colored2
- commonmarker (~> 0.23.9)
+ commonmarker (~> 1.0.3)
compare-xml (~> 0.66)
costs!
cuprite (~> 0.15.0)
diff --git a/lib/open_project/text_formatting/filters/markdown_filter.rb b/lib/open_project/text_formatting/filters/markdown_filter.rb
index 847248fd63a..61d031f3792 100644
--- a/lib/open_project/text_formatting/filters/markdown_filter.rb
+++ b/lib/open_project/text_formatting/filters/markdown_filter.rb
@@ -31,35 +31,31 @@ module OpenProject::TextFormatting
class MarkdownFilter < HTML::Pipeline::MarkdownFilter
# Convert Markdown to HTML using CommonMarker
def call
- render_html parse
+ render_html
end
private
##
- # Get initial CommonMarker AST for further processing
- #
- def parse
- parse_options = %i[LIBERAL_HTML_TAG STRIKETHROUGH_DOUBLE_TILDE UNSAFE]
-
- # We need liberal html tags thus parsing and rendering are several steps
- # Check: We may be able to reuse the ast instead of rendering to html and then parsing with nokogiri again.
- CommonMarker.render_doc(
- text,
- parse_options,
- commonmark_extensions
- )
+ # Render markdown to html
+ def render_html
+ Commonmarker.to_html(text, options: commonmarker_options)
+ .tap(&:rstrip!)
end
##
- # Render the transformed AST
- def render_html(ast)
- render_options = %i[GITHUB_PRE_LANG UNSAFE]
- render_options << :HARDBREAKS if context[:gfm] != false
-
- ast
- .to_html(render_options, commonmark_extensions)
- .tap(&:rstrip!)
+ # CommonMarker Options
+ # https://github.com/gjtorikian/commonmarker#options
+ def commonmarker_options
+ {
+ parse: { smart: false },
+ extension: commonmark_extensions.map { |k| [k, true] }.to_h,
+ render: {
+ unsafe_: true, # option is called unsafe_ not unsafe
+ github_pre_lang: true,
+ hardbreaks: context[:gfm] != false
+ }
+ }
end
##