Feat: add MD render options when gitee import
Related issue: https://jihulab.com/gitlab-cn/gitlab/-/issues/1855
What does this MR do and why?
- Render Markdown with special option
- Add option when gitee importing
markdown filter
Gem 中默认的 markdown filter
html-pipeline-2.13.2/lib/html/pipeline/markdown_filter.rb
# require 'html/pipeline'
HTML::Pipeline::MarkdownFilter.new("start\nend.").call
# output
# "<p>start<br />\nend.</p>"
GitLab 定制的 markdown filter:
lib/banzai/filter/markdown_filter.rb
# in rails console
Banzai::Filter::MarkdownFilter.new("start\nend.", {markdown_engine: :common_mark}).call
# output
# "<p data-sourcepos=\"1:1-2:4\">start\nend.</p>"
commonmarker Gem
lib/banzai/filter/markdown_engines/common_mark.rb
# `CommonMark` markdown engine for GitLab's Banzai markdown filter.
# This module is used in Banzai::Filter::MarkdownFilter.
# Used gem is `commonmarker` which is a ruby wrapper for libcmark (CommonMark parser)
# including GitHub's GFM extensions.
# We now utilize the renderer built in `C`, rather than the ruby based renderer.
# Homepage: https://github.com/gjtorikian/commonmarker
# require 'commonmarker'
CommonMarker.render_html(text, :DEFAULT)
# output
# "<p>start\nend.</p>\n"
CommonMarker.render_html(text, [:HARDBREAKS])
# output
# "<p>start<br />\nend.</p>\n"
Import demo repo
Screenshots
original issue description in markdown
https://jihulab.com/gitlab-cn/gitlab/-/issues/1855
Line start;
line end.
We want to `keep \n in code block`.
| header A | header B|
| ------ | ------ |
| cell 1 | cell 2|
| cell 3 | cell 4|
```ruby
def self.html_pipeline
@html_pipeline ||= HTML::Pipeline.new(filters)
end
```
Issue imported from Gitee | Issue in local repo (Not from Gitee) |
---|---|
由 Baodong 编辑于