Skip to content

Commit

Permalink
let Gollum::Markup handle code blocks instead of RedCarpet
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Sep 29, 2011
1 parent 6887c89 commit 8c1f82d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/gollum/markup.rb
Expand Up @@ -449,6 +449,7 @@ def render(no_follow = false)
@wiki.sanitizer

data = extract_tex(@data.dup)
data = extract_code(data)
data = extract_tags(data)

flags = [
Expand All @@ -457,11 +458,11 @@ def render(no_follow = false)
:tables,
:strikethrough,
:lax_htmlblock,
:gh_blockcode,
:no_intraemphasis
]
data = Redcarpet.new(data, *flags).to_html
data = process_tags(data)
data = process_code(data)

doc = Nokogiri::HTML::DocumentFragment.parse(data)

Expand Down
34 changes: 32 additions & 2 deletions test/test_markup.rb
Expand Up @@ -421,6 +421,31 @@
"</span> <span class=\"mi\">2</span>\n</pre>\n</div>\n\n\n<p>b</p>"
compare(content, output)
end

test "code with wiki links" do
content = <<-END
booya
``` python
np.array([[2,2],[1,3]],np.float)
```
END

# rendered with Gollum::Markup
page, rendered = render_page(content)
assert_markup_highlights_code Gollum::Markup, rendered

if Gollum.const_defined?(:MarkupGFM)
rendered_gfm = Gollum::MarkupGFM.new(page).render
assert_markup_highlights_code Gollum::MarkupGFM, rendered_gfm
end
end

def assert_markup_highlights_code(markup_class, rendered)
assert_match /div class="highlight"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
assert_match /span class="n"/, rendered, "#{markup_class} doesn't highlight code\n #{rendered}"
assert_match /\(\[\[/, rendered, "#{markup_class} parses out wiki links\n#{rendered}"
end

#########################################################################
#
Expand Down Expand Up @@ -515,13 +540,18 @@
#
#########################################################################

def compare(content, output, ext = "md", regexes = [])
def render_page(content, ext = "md")
index = @wiki.repo.index
index.add("Bilbo-Baggins.#{ext}", content)
index.commit("Add baggins")

page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
[page, Gollum::Markup.new(page).render]
end

def compare(content, output, ext = "md", regexes = [])
page, rendered = render_page(content, ext)

if regexes.empty?
assert_equal normal(output), normal(rendered)
else
Expand Down

0 comments on commit 8c1f82d

Please sign in to comment.