diff --git a/lib/redmine/wiki_formatting/markdown/formatter.rb b/lib/redmine/wiki_formatting/markdown/formatter.rb index 4bfd00c79..c27f61875 100644 --- a/lib/redmine/wiki_formatting/markdown/formatter.rb +++ b/lib/redmine/wiki_formatting/markdown/formatter.rb @@ -24,6 +24,14 @@ module Redmine include ActionView::Helpers::TagHelper include Redmine::Helpers::URL + def preprocess(full_document) + replace_wiki_links(full_document, '\|', '|') + end + + def postprocess(full_document) + replace_wiki_links(full_document, '|', '|') + end + def link(link, title, content) return nil unless uri_with_safe_scheme?(link) @@ -49,6 +57,19 @@ module Redmine tag('img', :src => link, :alt => alt_text || "", :title => title) end + + private + + def replace_wiki_links(full_document, pattern, replacement) + full_document.gsub(/(\[\[([^\]\n#{pattern}]+)(#{pattern})(([^\]\n#{pattern}]+))?\]\])/) do |m| + all, page, separater, title = $1, $2, $3, $4 + if page && separater && title + "[[#{page}#{replacement}#{title}]]" + else + all + end + end + end end class Formatter