Home > Mobile >  How can i format HTML document (some tags are breaked into two lines)
How can i format HTML document (some tags are breaked into two lines)

Time:12-02

  Cli:=THTTPClient.Create;
  Result:=Cli.Get(URL).ContentAsString;
  Cli.Free;
  Memo1.Text:=Result;

it worked ok, but some tags are breaked. I get it:

</div></div><div class="masthead_main container row"><div class="masthead_logo_search"><di
v class="masthead_logo"><a href="/">FAQs</a></div><div class="masthead_search"><form class="search" method="get" action="/search"

I need something like this:

...
</div>
</div>
<div class="masthead_main container row">
<div class="masthead_logo_search">
<div class="masthead_logo">
<a href="/">FAQs</a>
</div>
<div class="masthead_search">
<form class="search" method="get" action="/search">
...

I need not breaked tags. How can I get formated HTML?

CodePudding user response:

i created function! it's working for me:

function RestoreTags(Source:String):String;
var
 TagString:String;
 I:Integer;
 PosS:Integer;
 Opened:Boolean;
begin
 Opened:=False;
 Result:='';

 for I:=1 to Length(Source)-1 do
   begin
    if Source[I]='<' then
    begin
     Opened:=True;
     PosS:=I;
    end
    else if Source[I]='>' then
    begin
     Opened:=False;
     TagString:=Copy(Source,PosS,I-PosS 1);
     TagString:=StripChars(TagString,[#9, #10, #13]);
     Result:=Result TagString;
    end
    else if Opened=False then
    begin
     Result:=Result Source[I];
    end
   end;


end;
  • Related