diff options
author | Go MAEDA <maeda@farend.jp> | 2024-10-21 05:45:37 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2024-10-21 05:45:37 +0000 |
commit | 90f34d9d47e9c4df12e567bb04111cd856c8dc5c (patch) | |
tree | 25b26d6f9130cd05ca84e696457b91f06c21716c /lib/redmine/wiki_formatting | |
parent | 5407fea87338e2de3fb4bbd8edcd671eed910a52 (diff) | |
download | redmine-90f34d9d47e9c4df12e567bb04111cd856c8dc5c.tar.gz redmine-90f34d9d47e9c4df12e567bb04111cd856c8dc5c.zip |
Fix reference to the deleted Redcarpet-based Redmine::WikiFormatting::Markdown::HtmlParser class by porting the HtmlParser class for the CommonMark formatter (#40149, #41513).
git-svn-id: https://svn.redmine.org/redmine/trunk@23154 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/wiki_formatting')
-rw-r--r-- | lib/redmine/wiki_formatting/common_mark/html_parser.rb | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/redmine/wiki_formatting/common_mark/html_parser.rb b/lib/redmine/wiki_formatting/common_mark/html_parser.rb index ba79dfc14..3e8cf6671 100644 --- a/lib/redmine/wiki_formatting/common_mark/html_parser.rb +++ b/lib/redmine/wiki_formatting/common_mark/html_parser.rb @@ -20,7 +20,33 @@ module Redmine module WikiFormatting module CommonMark - HtmlParser = Redmine::WikiFormatting::Markdown::HtmlParser + class HtmlParser < Redmine::WikiFormatting::HtmlParser + self.tags = tags.merge( + 'b' => {:pre => '**', :post => '**'}, + 'strong' => {:pre => '**', :post => '**'}, + 'i' => {:pre => '*', :post => '*'}, + 'em' => {:pre => '*', :post => '*'}, + 'u' => {:pre => '_', :post => '_'}, + 'strike' => {:pre => '~~', :post => '~~'}, + 'h1' => {:pre => "\n\n# ", :post => "\n\n"}, + 'h2' => {:pre => "\n\n## ", :post => "\n\n"}, + 'h3' => {:pre => "\n\n### ", :post => "\n\n"}, + 'h4' => {:pre => "\n\n#### ", :post => "\n\n"}, + 'h5' => {:pre => "\n\n##### ", :post => "\n\n"}, + 'h6' => {:pre => "\n\n###### ", :post => "\n\n"}, + 'th' => {:pre => '*', :post => "*\n"}, + 'td' => {:pre => '', :post => "\n"}, + 'a' => lambda do |node| + if node.content.present? && node.attributes.key?('href') + %| [#{node.content}](#{node.attributes['href'].value}) | + elsif node.attributes.key?('href') + %| #{node.attributes['href'].value} | + else + node.content + end + end + ) + end end end end |