diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-11-18 16:25:00 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-11-18 16:25:00 +0000 |
commit | 6fc245327ce5bb4bb75f1378424635e347dfcd02 (patch) | |
tree | fd9d00eab0e444da2f6ecb58842cb973c37540a5 /lib/redmine/wiki_formatting | |
parent | b38dc9a301c3ab0fafc5dd824ad57059ec58fc91 (diff) | |
download | redmine-6fc245327ce5bb4bb75f1378424635e347dfcd02.tar.gz redmine-6fc245327ce5bb4bb75f1378424635e347dfcd02.zip |
Wiki: allows single section edit (#2222).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7829 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/wiki_formatting')
-rw-r--r-- | lib/redmine/wiki_formatting/textile/formatter.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/redmine/wiki_formatting/textile/formatter.rb b/lib/redmine/wiki_formatting/textile/formatter.rb index 520e3f9ad..1beb9563c 100644 --- a/lib/redmine/wiki_formatting/textile/formatter.rb +++ b/lib/redmine/wiki_formatting/textile/formatter.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require 'redcloth3' +require 'digest/md5' module Redmine module WikiFormatting @@ -38,6 +39,68 @@ module Redmine super(*RULES).to_s end + def get_section(index) + section = extract_sections(index)[1] + hash = Digest::MD5.hexdigest(section) + return section, hash + end + + def update_section(index, update, hash=nil) + t = extract_sections(index) + if hash.present? && hash != Digest::MD5.hexdigest(t[1]) + raise Redmine::WikiFormatting::StaleSectionError + end + t[1] = update unless t[1].blank? + t.reject(&:blank?).join "\n\n" + end + + def extract_sections(index) + @pre_list = [] + text = self.dup + rip_offtags text + before = '' + s = '' + after = '' + i = 0 + l = 1 + started = false + ended = false + text.scan(/(((?:.*?)(\A|\r?\n\r?\n))(h(\d+)(#{A}#{C})\.(?::(\S+))? (.*?)$)|.*)/m).each do |all, content, lf, heading, level| + if heading.nil? + if ended + after << all + elsif started + s << all + else + before << all + end + break + end + i += 1 + if ended + after << all + elsif i == index + l = level.to_i + before << content + s << heading + started = true + elsif i > index + s << content + if level.to_i > l + s << heading + else + after << heading + ended = true + end + else + before << all + end + end + sections = [before.strip, s.strip, after.strip] + sections.each {|section| smooth_offtags section} + sections + end + private # Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet. |