Lexing of element attributes without values.

This commit is contained in:
Yorick Peterse 2014-03-12 22:41:17 +01:00
parent ed9d8c05a2
commit 98b3443e7f
2 changed files with 21 additions and 2 deletions

View File

@ -302,9 +302,17 @@ module Oga
element_name
%{
t(:T_ATTR, @ts, p)
advance_column
}
'=' (dquote @string_dquote | squote @string_squote);
# The value of the attribute. Attribute values are not required. e.g.
# in <p data-foo></p> data-foo would be a boolean attribute.
(
'=' >{ advance_column }
# The value of the attribute, wrapped in either single or double
# quotes.
(dquote @string_dquote | squote @string_squote)
)*;
# Non self-closing elements.
'</' => {

View File

@ -25,6 +25,17 @@ describe Oga::Lexer do
[:T_ELEM_CLOSE, nil, 1, 9]
]
end
end
context 'elements with attributes' do
example 'lex an element with an attribute without a value' do
lex('<p foo></p>').should == [
[:T_ELEM_OPEN, nil, 1, 1],
[:T_ELEM_NAME, 'p', 1, 2],
[:T_ATTR, 'foo', 1, 4],
[:T_ELEM_CLOSE, nil, 1, 8]
]
end
example 'lex a paragraph element with attributes' do
lex('<p class="foo">Hello</p>').should == [