Skip to content

Commit

Permalink
Updared code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitrij Denissenko committed Aug 2, 2009
1 parent 338b326 commit fd3ac80
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
8 changes: 4 additions & 4 deletions vendor/plugins/wiki_engine/lib/wiki_engine/retro.rb
Expand Up @@ -2,7 +2,7 @@
module WikiEngine

class Retro < RedCloth::TextileDoc
CODE_PATTERN = /\{{3}\n*(.+?)\n*\}{3}/m
CODE_PATTERN = /(\s+)\{{3}\n*(.+?)\n*\}{3}/m
HEADER_PATTERN = /^(={1,6})[ ]*(.+?)[ ]*=*$/

module Formatter
Expand All @@ -28,9 +28,9 @@ def initialize(string)
# Extract {{{CODE}}}
@code_blocks = {}
gsub! CODE_PATTERN do |match|
placeholder = "[#{ActiveSupport::SecureRandom.hex(20)}]"
@code_blocks[placeholder] = CGI::escapeHTML($1.to_s.strip)
"\nbc. #{placeholder}\n"
placeholder = "((#{ActiveSupport::SecureRandom.hex(20)}))"
@code_blocks[placeholder] = ERB::Util.h($2.to_s.strip)
"\n\nbc. #{placeholder}\n"
end

# Remove evil tags (with content)
Expand Down
37 changes: 30 additions & 7 deletions vendor/plugins/wiki_engine/test/wiki_engine_test.rb
@@ -1,8 +1,10 @@
# encoding:utf-8
#--
# Copyright (C) 2009 Dimitrij Denissenko
# Please read LICENSE document for more information.
#++


$: << File.dirname(__FILE__) + '/../lib'

require 'rubygems'
Expand Down Expand Up @@ -97,6 +99,33 @@ def test_code_parts
assert_equal(html, markup)
end

def test_spacing_in_code_parts
text = %Q(Some introduction:
{{{
ruby script/server -e production
}}}
)
html = "<p>Some introduction:</p>
<pre><code>ruby script/server -e production</code></pre>"

markup = WikiEngine.markup(text, 'retro')
assert_equal(html, markup)
end

def test_inline_code_parts
text = %Q(Some introduction and then {{{
inline:
code
}}}
)
html = "<p>Some introduction and then</p>
<pre><code>inline:
code</code></pre>"

markup = WikiEngine.markup(text, 'retro')
assert_equal(html, markup)
end


def test_code_escaping
Expand Down Expand Up @@ -232,7 +261,7 @@ def test_security

html = "<p style=\"text-align:right;\">Right aligned line</p>
<p style=\"padding-left:3em;text-align:left;\">Left aligned and indented line</p>
<p style=\"padding-left:1em;padding-right:1em;text-align:left;\">IF A &lt; B <span>THEN</span> B &gt; A</p>
<p style=\"padding-left:1em;padding-right:1em;text-align:left;\">IF A &lt; B THEN B &gt; A</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
Expand Down Expand Up @@ -264,10 +293,4 @@ def test_extracting_text_parts
assert_equal(original, source)
end


def test_general_markup


end

end

0 comments on commit fd3ac80

Please sign in to comment.