Support for spaces around attribute equal signs
This also takes care of making sure line numbers are incremented properly. Fixes #112
This commit is contained in:
parent
6f115bd8e0
commit
a76286b973
|
@ -426,6 +426,32 @@
|
|||
squote | dquote | '`' | '=' | '<' | '>' | whitespace_or_newline
|
||||
)+;
|
||||
|
||||
# Machine used after matching the "=" of an attribute and just before moving
|
||||
# into the actual attribute value.
|
||||
attribute_pre := |*
|
||||
whitespace_or_newline $count_newlines;
|
||||
|
||||
any => {
|
||||
fhold;
|
||||
|
||||
if ( lines > 0 )
|
||||
{
|
||||
advance_line(lines);
|
||||
|
||||
lines = 0;
|
||||
}
|
||||
|
||||
if ( html_p )
|
||||
{
|
||||
fnext html_attribute_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
fnext xml_attribute_value;
|
||||
}
|
||||
};
|
||||
*|;
|
||||
|
||||
# Machine used for processing HTML attribute values.
|
||||
html_attribute_value := |*
|
||||
squote | dquote => {
|
||||
|
@ -482,14 +508,7 @@
|
|||
|
||||
# Attribute values.
|
||||
'=' => {
|
||||
if ( html_p )
|
||||
{
|
||||
fcall html_attribute_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
fcall xml_attribute_value;
|
||||
}
|
||||
fcall attribute_pre;
|
||||
};
|
||||
|
||||
# We're done with the open tag of the element.
|
||||
|
|
|
@ -57,5 +57,38 @@ describe Oga::XML::Lexer do
|
|||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes an element with spaces around the attribute equal sign' do
|
||||
lex_html('<p foo = "bar"></p>').should == [
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
[:T_STRING_BODY, 'bar', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes an element with a newline following the equals sign' do
|
||||
lex_html(%Q{<p foo =\n"bar"></p>}).should == [
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_STRING_BODY, 'bar', 2],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_ELEM_END, nil, 2]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes an element with a newline following the equals sign using an IO as input' do
|
||||
lex_stringio(%Q{<p foo =\n"bar"></p>}, :html => true).should == [
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_STRING_BODY, 'bar', 2],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_ELEM_END, nil, 2]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -192,6 +192,39 @@ describe Oga::XML::Lexer do
|
|||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes an element with spaces around the attribute equal sign' do
|
||||
lex('<p foo = "bar"></p>').should == [
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
[:T_STRING_BODY, 'bar', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes an element with a newline following the equals sign' do
|
||||
lex(%Q{<p foo =\n"bar"></p>}).should == [
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_STRING_BODY, 'bar', 2],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_ELEM_END, nil, 2]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes an element with a newline following the equals sign using an IO as input' do
|
||||
lex_stringio(%Q{<p foo =\n"bar"></p>}).should == [
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_STRING_BODY, 'bar', 2],
|
||||
[:T_STRING_DQUOTE, nil, 2],
|
||||
[:T_ELEM_END, nil, 2]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'nested elements' do
|
||||
|
|
Loading…
Reference in New Issue