Renamed parse_html() to parse().
This commit is contained in:
parent
cb75edc30d
commit
8d3f3f15d7
|
@ -3,18 +3,18 @@ require 'spec_helper'
|
||||||
describe Oga::Parser do
|
describe Oga::Parser do
|
||||||
context 'cdata tags' do
|
context 'cdata tags' do
|
||||||
example 'parse a cdata tag' 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
|
end
|
||||||
|
|
||||||
example 'parse an element inside a cdata tag' do
|
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,
|
:document,
|
||||||
s(:cdata, '<p>foo</p>')
|
s(:cdata, '<p>foo</p>')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse double brackets inside a cdata tag' do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,11 +3,11 @@ require 'spec_helper'
|
||||||
describe Oga::Parser do
|
describe Oga::Parser do
|
||||||
context 'comments' do
|
context 'comments' do
|
||||||
example 'parse an empty comment' do
|
example 'parse an empty comment' do
|
||||||
parse_html('<!---->').should == s(:document, s(:comment))
|
parse('<!---->').should == s(:document, s(:comment))
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a comment' do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,25 +3,25 @@ require 'spec_helper'
|
||||||
describe Oga::Parser do
|
describe Oga::Parser do
|
||||||
context 'doctypes' do
|
context 'doctypes' do
|
||||||
example 'parse a doctype' do
|
example 'parse a doctype' do
|
||||||
parse_html('<!DOCTYPE html>').should == s(:document, s(:doctype))
|
parse('<!DOCTYPE html>').should == s(:document, s(:doctype))
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a doctype with the doctype type' do
|
example 'parse a doctype with the doctype type' do
|
||||||
parse_html('<!DOCTYPE html PUBLIC>').should == s(
|
parse('<!DOCTYPE html PUBLIC>').should == s(
|
||||||
:document,
|
:document,
|
||||||
s(:doctype, 'PUBLIC')
|
s(:doctype, 'PUBLIC')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a doctype with a public ID' do
|
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,
|
:document,
|
||||||
s(:doctype, 'PUBLIC', 'foo')
|
s(:doctype, 'PUBLIC', 'foo')
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a doctype with a public and private ID' do
|
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,
|
:document,
|
||||||
s(:doctype, 'PUBLIC', 'foo', 'bar')
|
s(:doctype, 'PUBLIC', 'foo', 'bar')
|
||||||
)
|
)
|
||||||
|
@ -31,7 +31,7 @@ describe Oga::Parser do
|
||||||
doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ' \
|
doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ' \
|
||||||
'"http://www.w3.org/TR/html4/strict.dtd">'
|
'"http://www.w3.org/TR/html4/strict.dtd">'
|
||||||
|
|
||||||
parse_html(doctype).should == s(
|
parse(doctype).should == s(
|
||||||
:document,
|
:document,
|
||||||
s(
|
s(
|
||||||
:doctype,
|
:doctype,
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe Oga::Parser do
|
||||||
</html>
|
</html>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
parse_html(html).should == s(
|
parse(html).should == s(
|
||||||
:document,
|
:document,
|
||||||
s(:doctype),
|
s(:doctype),
|
||||||
s(:text, "\n"),
|
s(:text, "\n"),
|
||||||
|
|
|
@ -3,35 +3,35 @@ require 'spec_helper'
|
||||||
describe Oga::Parser do
|
describe Oga::Parser do
|
||||||
context 'elements' do
|
context 'elements' do
|
||||||
example 'parse an empty element' do
|
example 'parse an empty element' do
|
||||||
parse_html('<p></p>').should == s(
|
parse('<p></p>').should == s(
|
||||||
:document,
|
:document,
|
||||||
s(:element, nil, 'p', nil, nil)
|
s(:element, nil, 'p', nil, nil)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with text' do
|
example 'parse an element with text' do
|
||||||
parse_html('<p>foo</p>').should == s(
|
parse('<p>foo</p>').should == s(
|
||||||
:document,
|
:document,
|
||||||
s(:element, nil, 'p', nil, s(:text, 'foo'))
|
s(:element, nil, 'p', nil, s(:text, 'foo'))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with a single attribute' do
|
example 'parse an element with a single attribute' do
|
||||||
parse_html('<p foo></p>').should == s(
|
parse('<p foo></p>').should == s(
|
||||||
:document,
|
:document,
|
||||||
s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo')), nil)
|
s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo')), nil)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with a single attribute with a value' do
|
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,
|
:document,
|
||||||
s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo', 'bar')), nil)
|
s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo', 'bar')), nil)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with multiple attributes' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
@ -48,7 +48,7 @@ describe Oga::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with text and attributes' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
@ -61,14 +61,14 @@ describe Oga::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with a namespace' do
|
example 'parse an element with a namespace' do
|
||||||
parse_html('<foo:p></p>').should == s(
|
parse('<foo:p></p>').should == s(
|
||||||
:document,
|
:document,
|
||||||
s(:element, 'foo', 'p', nil, nil)
|
s(:element, 'foo', 'p', nil, nil)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with a namespace and an attribute' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
@ -81,14 +81,14 @@ describe Oga::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element nested inside another element' do
|
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,
|
:document,
|
||||||
s(:element, nil, 'p', nil, s(:element, nil, 'a', nil, nil))
|
s(:element, nil, 'p', nil, s(:element, nil, 'a', nil, nil))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with children text, element' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
@ -102,7 +102,7 @@ describe Oga::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with children text, element, text' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
@ -117,7 +117,7 @@ describe Oga::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with children element, text' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
@ -131,7 +131,7 @@ describe Oga::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse an element with children element, text, element' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
|
|
@ -2,10 +2,10 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::Parser do
|
describe Oga::Parser do
|
||||||
example 'parse regular text' do
|
example 'parse regular text' do
|
||||||
parse_html('foo').should == s(:document, s(:text, 'foo'))
|
parse('foo').should == s(:document, s(:text, 'foo'))
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a newline' do
|
example 'parse a newline' do
|
||||||
parse_html("\n").should == s(:document, s(:text, "\n"))
|
parse("\n").should == s(:document, s(:text, "\n"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,21 +3,21 @@ require 'spec_helper'
|
||||||
describe Oga::Parser do
|
describe Oga::Parser do
|
||||||
context 'HTML void elements' do
|
context 'HTML void elements' do
|
||||||
example 'parse a void element that omits the closing /' do
|
example 'parse a void element that omits the closing /' do
|
||||||
parse_html('<link>').should == s(
|
parse('<link>', :html => true).should == s(
|
||||||
:document,
|
:document,
|
||||||
s(:element, nil, 'link', nil, nil)
|
s(:element, nil, 'link', nil, nil)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a void element inside another element' do
|
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,
|
:document,
|
||||||
s(:element, nil, 'head', nil, s(:element, nil, 'link', nil, nil))
|
s(:element, nil, 'head', nil, s(:element, nil, 'link', nil, nil))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a void element with attributes inside another element' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
@ -36,7 +36,7 @@ describe Oga::Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'parse a void element and a non void element in the same parent' do
|
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,
|
:document,
|
||||||
s(
|
s(
|
||||||
:element,
|
:element,
|
||||||
|
|
|
@ -26,10 +26,11 @@ module Oga
|
||||||
# Parses the given HTML and returns an AST.
|
# Parses the given HTML and returns an AST.
|
||||||
#
|
#
|
||||||
# @param [String] input
|
# @param [String] input
|
||||||
|
# @param [Hash] options
|
||||||
# @return [Oga::AST::Node]
|
# @return [Oga::AST::Node]
|
||||||
#
|
#
|
||||||
def parse_html(input)
|
def parse(input, options = {})
|
||||||
return Oga::Parser.new(:html => true).parse(input)
|
return Oga::Parser.new(options).parse(input)
|
||||||
end
|
end
|
||||||
end # ParsingHelpers
|
end # ParsingHelpers
|
||||||
end # Oga
|
end # Oga
|
||||||
|
|
Loading…
Reference in New Issue