Permalink
Browse files

a bit more nokogiri munging

  • Loading branch information...
1 parent e05edc0 commit 5d908c675fbf74f600782d2a7c682e2cff9430ce @nakajima committed Dec 17, 2008
Showing with 13 additions and 6 deletions.
  1. +3 −3 lib/syntaxily.rb
  2. +10 −3 spec/syntaxily_spec.rb
View
@@ -11,17 +11,17 @@ module Syntaxily
class LexerNotFound < StandardError; end
def self.parse(text)
- doc = Nokogiri::HTML.parse(text)
+ doc = Nokogiri::HTML.parse("<root>" + text + "</root>")
doc.search('pre.code').each do |node|
lexer = node['rel']
begin
lexed = node.text.syntaxify(lexer)
- node.replace Nokogiri::HTML.parse(lexed).at('body *')
+ node.replace Nokogiri::HTML.parse(lexed).at('html body *')
rescue LexerNotFound
next
end
end
- doc.to_html
+ doc.at('root').inner_html
end
def self.available_lexers
View
@@ -42,16 +42,23 @@ def render
describe "rendering from markup" do
def render
Syntaxily.parse <<-TEXT
- <h1>This is normal</h1>
- <pre class="code" rel="ruby">def foo; :bar end</pre>
- <h1>Good bye</h1>
+ <div>
+ <h1>This is normal</h1>
+ <pre class="code" rel="ruby">def foo; :bar end</pre>
+ <h1>Good bye</h1>
+ </div>
TEXT
end
it "retains old markup" do
result.should have(2).headers
end
+ it "does not include a bunch of dtd crap" do
+ result.doc.at('html').should be_nil
+ result.doc.at('body').should be_nil
+ end
+
it "syntax highlights within pre tag" do
result.should have(2).keywords
result.should have(1).keywords.with_text('def')

0 comments on commit 5d908c6

Please sign in to comment.