diff --git a/lib/redmine/wiki_formatting/markdown/formatter.rb b/lib/redmine/wiki_formatting/markdown/formatter.rb index 82e3b6c..8d0503d 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) @@ -34,6 +42,17 @@ module Redmine content_tag('a', content.to_s.html_safe, :href => link, :title => title, :class => css) end + def replace_wiki_links(full_document, pattern, replacement) + full_document.gsub(/(\[\[(((?![\]\n]|#{pattern}).)+)(#{pattern})(((?![\]\n]|#{pattern}).)+)\]\])/) do |m| + all, page, separater, title = $1, $2, $4, $5 + if page && separater && title + "[[#{page}#{replacement}#{title}]]" + else + all + end + end + end + def block_code(code, language) if language.present? && Redmine::SyntaxHighlighting.language_supported?(language) "
" +