Permalink
Browse files

More bugfixes. Regex kills me

  • Loading branch information...
1 parent 07e4a63 commit 6e5c6725f992fcc93ba8d069f555f92a31ce5ba4 @txus txus committed Feb 15, 2011
Showing with 31 additions and 3 deletions.
  1. +1 −1 Gemfile.lock
  2. +6 −0 lib/markdownizer.rb
  3. +1 −1 lib/markdownizer/version.rb
  4. +23 −1 spec/markdownizer_spec.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- markdownizer (0.3.2)
+ markdownizer (0.3.3)
activerecord (>= 3.0.3)
coderay
rdiscount
View
@@ -89,6 +89,7 @@ def markdown(text, hierarchy = 0)
text.gsub! %r[^(\s*)(#+)([\w\s]+)$] do
$1 << ('#' * hierarchy) << $2 << $3
end
+ text.gsub!('\#','#')
RDiscount.new(text).to_html
end
@@ -116,6 +117,11 @@ def coderay(text, options = {})
code, language = $2.strip, $1.strip
+ # Mark comments to avoid conflicts with Header parsing
+ code.gsub!(/(#+)/) do
+ '\\' + $1
+ end
+
code, options, caption = extract_caption_from(code, options)
code, options = extract_highlights_from(code, options)
@@ -1,3 +1,3 @@
module Markdownizer
- VERSION = "0.3.3"
+ VERSION = "0.3.4"
end
View
@@ -110,8 +110,21 @@ def function(*args)
"""
}
+ let(:text_with_comments) { """
+ #My markdown text
- it 'calls CodeRay to parse the code inside {% highlight ruby %} blocks' do
+ {% code ruby %}
+ #My comment
+ # My other comment
+ def function(*args)
+ puts 'result'
+ end
+ {% endcode %}
+
+ """
+ }
+
+ it 'calls CodeRay to parse the code inside {% code ruby %} blocks' do
scanned_code, html_code = double(:scanned_code), double(:html_code)
CodeRay.should_receive(:scan).with("""def function(*args)
@@ -128,6 +141,15 @@ def function(*args)
it 'accepts a caption with weird chars inside the code' do
subject.coderay(text_with_weird_caption).should match('<h5>This will become an h5, with some/strange.characters\yo</h5>')
end
+ it 'marks ruby comments to avoid conflicts with Markdown headers' do
+ code = ''
+ code.stub(:div).and_return ''
+ CodeRay.should_receive(:scan).with do |string|
+ string.should match(/\\#My comment/)
+ string.should match(/\\# My other comment/)
+ end.and_return code
+ subject.coderay(text_with_comments)
+ end
it 'passes the caption to the div' do
parsed = double :parsed
CodeRay.should_receive(:scan).and_return parsed

0 comments on commit 6e5c672

Please sign in to comment.