Renamed parse_html() to parse().

This commit is contained in:
Yorick Peterse 2014-03-16 23:46:20 +01:00
parent cb75edc30d
commit 8d3f3f15d7
8 changed files with 33 additions and 32 deletions

View File

@ -3,18 +3,18 @@ require 'spec_helper'
describe Oga::Parser do
context 'cdata tags' do
example 'parse a cdata tag' do
parse_html('<![CDATA[foo]]>').should == s(:document, s(:cdata, 'foo'))
parse('<![CDATA[foo]]>').should == s(:document, s(:cdata, 'foo'))
end
example 'parse an element inside a cdata tag' do
parse_html('<![CDATA[<p>foo</p>]]>').should == s(
parse('<![CDATA[<p>foo</p>]]>').should == s(
:document,
s(:cdata, '<p>foo</p>')
)
end
example 'parse double brackets inside a cdata tag' do
parse_html('<![CDATA[]]]]>').should == s(:document, s(:cdata, ']]'))
parse('<![CDATA[]]]]>').should == s(:document, s(:cdata, ']]'))
end
end
end

View File

@ -3,11 +3,11 @@ require 'spec_helper'
describe Oga::Parser do
context 'comments' do
example 'parse an empty comment' do
parse_html('<!---->').should == s(:document, s(:comment))
parse('<!---->').should == s(:document, s(:comment))
end
example 'parse a comment' do
parse_html('<!--foo-->').should == s(:document, s(:comment, 'foo'))
parse('<!--foo-->').should == s(:document, s(:comment, 'foo'))
end
end
end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::Parser do
context 'doctypes' do
example 'parse a doctype' do
parse_html('<!DOCTYPE html>').should == s(:document, s(:doctype))
parse('<!DOCTYPE html>').should == s(:document, s(:doctype))
end
example 'parse a doctype with the doctype type' do
parse_html('<!DOCTYPE html PUBLIC>').should == s(
parse('<!DOCTYPE html PUBLIC>').should == s(
:document,
s(:doctype, 'PUBLIC')
)
end
example 'parse a doctype with a public ID' do
parse_html('<!DOCTYPE html PUBLIC "foo">').should == s(
parse('<!DOCTYPE html PUBLIC "foo">').should == s(
:document,
s(:doctype, 'PUBLIC', 'foo')
)
end
example 'parse a doctype with a public and private ID' do
parse_html('<!DOCTYPE html PUBLIC "foo" "bar">').should == s(
parse('<!DOCTYPE html PUBLIC "foo" "bar">').should == s(
:document,
s(:doctype, 'PUBLIC', 'foo', 'bar')
)
@ -31,7 +31,7 @@ describe Oga::Parser do
doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ' \
'"http://www.w3.org/TR/html4/strict.dtd">'
parse_html(doctype).should == s(
parse(doctype).should == s(
:document,
s(
:doctype,

View File

@ -13,7 +13,7 @@ describe Oga::Parser do
</html>
EOF
parse_html(html).should == s(
parse(html).should == s(
:document,
s(:doctype),
s(:text, "\n"),

View File

@ -3,35 +3,35 @@ require 'spec_helper'
describe Oga::Parser do
context 'elements' do
example 'parse an empty element' do
parse_html('<p></p>').should == s(
parse('<p></p>').should == s(
:document,
s(:element, nil, 'p', nil, nil)
)
end
example 'parse an element with text' do
parse_html('<p>foo</p>').should == s(
parse('<p>foo</p>').should == s(
:document,
s(:element, nil, 'p', nil, s(:text, 'foo'))
)
end
example 'parse an element with a single attribute' do
parse_html('<p foo></p>').should == s(
parse('<p foo></p>').should == s(
:document,
s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo')), nil)
)
end
example 'parse an element with a single attribute with a value' do
parse_html('<p foo="bar"></p>').should == s(
parse('<p foo="bar"></p>').should == s(
:document,
s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo', 'bar')), nil)
)
end
example 'parse an element with multiple attributes' do
parse_html('<p foo="bar" baz="bad"></p>').should == s(
parse('<p foo="bar" baz="bad"></p>').should == s(
:document,
s(
:element,
@ -48,7 +48,7 @@ describe Oga::Parser do
end
example 'parse an element with text and attributes' do
parse_html('<p class="foo">Bar</p>').should == s(
parse('<p class="foo">Bar</p>').should == s(
:document,
s(
:element,
@ -61,14 +61,14 @@ describe Oga::Parser do
end
example 'parse an element with a namespace' do
parse_html('<foo:p></p>').should == s(
parse('<foo:p></p>').should == s(
:document,
s(:element, 'foo', 'p', nil, nil)
)
end
example 'parse an element with a namespace and an attribute' do
parse_html('<foo:p class="bar"></p>').should == s(
parse('<foo:p class="bar"></p>').should == s(
:document,
s(
:element,
@ -81,14 +81,14 @@ describe Oga::Parser do
end
example 'parse an element nested inside another element' do
parse_html('<p><a></a></p>').should == s(
parse('<p><a></a></p>').should == s(
:document,
s(:element, nil, 'p', nil, s(:element, nil, 'a', nil, nil))
)
end
example 'parse an element with children text, element' do
parse_html('<p>Foo<a>Bar</a></p>').should == s(
parse('<p>Foo<a>Bar</a></p>').should == s(
:document,
s(
:element,
@ -102,7 +102,7 @@ describe Oga::Parser do
end
example 'parse an element with children text, element, text' do
parse_html('<p>Foo<a>Bar</a>Baz</p>').should == s(
parse('<p>Foo<a>Bar</a>Baz</p>').should == s(
:document,
s(
:element,
@ -117,7 +117,7 @@ describe Oga::Parser do
end
example 'parse an element with children element, text' do
parse_html('<p><a>Bar</a>Baz</p>').should == s(
parse('<p><a>Bar</a>Baz</p>').should == s(
:document,
s(
:element,
@ -131,7 +131,7 @@ describe Oga::Parser do
end
example 'parse an element with children element, text, element' do
parse_html('<p><a>Bar</a>Baz<span>Da</span></p>').should == s(
parse('<p><a>Bar</a>Baz<span>Da</span></p>').should == s(
:document,
s(
:element,

View File

@ -2,10 +2,10 @@ require 'spec_helper'
describe Oga::Parser do
example 'parse regular text' do
parse_html('foo').should == s(:document, s(:text, 'foo'))
parse('foo').should == s(:document, s(:text, 'foo'))
end
example 'parse a newline' do
parse_html("\n").should == s(:document, s(:text, "\n"))
parse("\n").should == s(:document, s(:text, "\n"))
end
end

View File

@ -3,21 +3,21 @@ require 'spec_helper'
describe Oga::Parser do
context 'HTML void elements' do
example 'parse a void element that omits the closing /' do
parse_html('<link>').should == s(
parse('<link>', :html => true).should == s(
:document,
s(:element, nil, 'link', nil, nil)
)
end
example 'parse a void element inside another element' do
parse_html('<head><link></head>').should == s(
parse('<head><link></head>', :html => true).should == s(
:document,
s(:element, nil, 'head', nil, s(:element, nil, 'link', nil, nil))
)
end
example 'parse a void element with attributes inside another element' do
parse_html('<head><link href="foo.css"></head>').should == s(
parse('<head><link href="foo.css"></head>', :html => true).should == s(
:document,
s(
:element,
@ -36,7 +36,7 @@ describe Oga::Parser do
end
example 'parse a void element and a non void element in the same parent' do
parse_html('<head><link><title>Foo</title></head>').should == s(
parse('<head><link><title>Foo</title></head>', :html => true).should == s(
:document,
s(
:element,

View File

@ -26,10 +26,11 @@ module Oga
# Parses the given HTML and returns an AST.
#
# @param [String] input
# @param [Hash] options
# @return [Oga::AST::Node]
#
def parse_html(input)
return Oga::Parser.new(:html => true).parse(input)
def parse(input, options = {})
return Oga::Parser.new(options).parse(input)
end
end # ParsingHelpers
end # Oga