From 582ccd2ecf282a819b247db6946351a6fddb63cc Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 13 Aug 2014 14:45:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0wiki=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE=E8=AE=A8=E8=AE=BA?= =?UTF-8?q?=E5=8C=BA=E6=A8=A1=E5=9D=97=E5=9B=9E=E5=8E=BB=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 44 ++++++++++++++++++++++- app/helpers/wiki_helper.rb | 10 ++++++ app/views/messages/_project_show.html.erb | 4 +-- app/views/wiki/_content.html.erb | 2 +- db/schema.rb | 7 ++-- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b1006d239..23f6b6994 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -685,7 +685,7 @@ module ApplicationHelper when 2 obj = args.shift attr = args.shift - text = obj.send(attr).to_s + text = obj.send(attr).html_safe.to_s else raise ArgumentError, 'invalid arguments to textilizable' end @@ -716,6 +716,48 @@ module ApplicationHelper text.html_safe end + # + #格式化字符串,不转义html代码 + def textAreailizable(*args) + options = args.last.is_a?(Hash) ? args.pop : {} + case args.size + when 1 + obj = options[:object] + text = args.shift + when 2 + obj = args.shift + attr = args.shift + text = obj.send(attr).html_safe.to_s + else + raise ArgumentError, 'invalid arguments to textilizable' + end + return '' if text.blank? + project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) + only_path = options.delete(:only_path) == false ? false : true + + text = text.dup + macros = catch_macros(text) + text = Redmine::WikiFormatting.to_html("CKEditor", text, :object => obj, :attribute => attr) + + @parsed_headings = [] + @heading_anchors = {} + @current_section = 0 if options[:edit_section_links] + + parse_sections(text, project, obj, attr, only_path, options) + text = parse_non_pre_blocks(text, obj, macros) do |text| + [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name| + send method_name, text, project, obj, attr, only_path, options + end + end + parse_headings(text, project, obj, attr, only_path, options) + + if @parsed_headings.any? + replace_toc(text, @parsed_headings) + end + + text.html_safe + end + def parse_non_pre_blocks(text, obj, macros) s = StringScanner.new(text) tags = [] diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index c6cb3b39d..8278ce035 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -40,4 +40,14 @@ module WikiHelper link_to(h(parent.pretty_title), {:controller => 'wiki', :action => 'show', :id => parent.title, :project_id => parent.project, :version => nil}) }) end + + def wiki_content_format wiki + text = wiki.text.html_safe + text = parse_non_pre_blocks(text, wiki, text) do |text| + [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name| + send method_name, text, project, wiki, attr, only_path, options + end + end + text + end end diff --git a/app/views/messages/_project_show.html.erb b/app/views/messages/_project_show.html.erb index 66027e6ec..0bae1a761 100644 --- a/app/views/messages/_project_show.html.erb +++ b/app/views/messages/_project_show.html.erb @@ -161,8 +161,8 @@