Page 1 of 1

TRvHTMLImporter and Style Attributes

Posted: Fri Apr 28, 2006 7:22 pm
by martindk
There is a bug in TRvHTMLImporter's parsing of stylesheet attributes. This causes a search for the 'color' attribute to match the 'background-color' attribute and return its value. The following code fixes the problem:

function StyleValue(StyleParam, StyleType: string): string;

var
RetVal: string;
Position: integer;

begin
RetVal := '';
Position := 0;

while True do begin
Position := PosEx(StyleType, StyleParam, Position + 1);

if Position = 0
then break;

if (Position > 1) and (StyleParam[Position - 1] in ['a'..'z', '0'..'9', '-'])
then continue;

if StyleParam[Position + Length(StyleType)] in ['a'..'z', '0'..'9', '-']
then continue
else break;
end;

if Position > 0
then
begin
StyleParam := Copy(StyleParam, Position + Length(StyleType), 100);
while StyleParam[1] in [' ', ':'] do Delete(StyleParam, 1, 1);
Position := 1;
if (StyleParam[1] = '''') or (StyleParam[1] = '"')
then
begin
Position := 2;
while not (StyleParam[Position] in ['''', '"']) do
begin
RetVal := RetVal + StyleParam[Position];
Inc(Position);
end;
end
else
while not (StyleParam[Position] in [';', ')', '>', ']', '}']) do
begin
RetVal := RetVal + StyleParam[Position];
Inc(Position);
end;
end;
StyleValue := RetVal;
end;