TRvHTMLImporter and Style Attributes

General TRichView support forum. Please post your questions here
Post Reply
martindk
Posts: 2
Joined: Thu Apr 27, 2006 2:08 pm

TRvHTMLImporter and Style Attributes

Post 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;
Post Reply