Lexing of element attributes without values.
This commit is contained in:
parent
ed9d8c05a2
commit
98b3443e7f
|
@ -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.
|
||||
'</' => {
|
||||
|
|
|
@ -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 == [
|
||||
|
|
Loading…
Reference in New Issue