Forum > LCL

Basic HTML Generation...

<< < (2/4) > >>

GordonShumway:
I think we're making this more complicated then it has to be. The below will do what you're looking for if the text paragraphs are separated by a single blank line.

First paragraph.
                                      <- Blank line :D
Second paragraph.
                                      <- Blank line :D
Third paragraph.


--- Code: ---procedure TForm1.btnTransferClick(Sender: TObject);
var
 I: Integer;
begin
  // We add the opening '<p>' tag.
  Memo2.Lines.Add('<p>');
  // Now we start going through the lines of your original text.
  for I := 0 to (Memo1.Lines.Count - 1) do
  begin
    // If the line is blank (e.g. from CR/LF) then we add a closing '</p>' and
    // start a new one.
    if Memo1.Lines[i] = '' then
      Memo2.Lines.Add('</p><p>')
    else
      Memo2.Lines.Add(Memo1.Lines[i]); // If the line wasn't blank copy it over.
  end;
  Memo2.Lines.Add('</p>'); // Put out final closing tag.
end;

--- End code ---

Comes out to:

<p>
First paragraph.
</p><p>
Second paragraph.
</p><p>
Third paragraph.
</p>

eny:
Interesting concept.
If you really want to make things simple  ;)

--- Code: ---  Memo2.lines.Text  := format('<p>%s</p>', [
                         StringReplace(memo1.Lines.Text,
                                       #13#10#13#10,
                                       #13#10'</p><p>'#13#10,
                                       [rfReplaceAll]) ] );

--- End code ---

<<edit>>
And my 100th post  8-)

GordonShumway:
LOL Yep! That would do it it's just hard on the eyes  %)

Edit: Congrats!  ;D

commodianus:
Oh wow yeah that's much simpler eny. I'll try implementing that. Thanks everyone who's helped.

commodianus:

--- Quote from: eny on March 24, 2010, 04:25:28 pm ---Interesting concept.
If you really want to make things simple  ;)

--- Code: ---  Memo2.lines.Text  := format('<p>%s</p>', [
                         StringReplace(memo1.Lines.Text,
                                       #13#10#13#10,
                                       #13#10'</p><p>'#13#10,
                                       [rfReplaceAll]) ] );

--- End code ---

<<edit>>
And my 100th post  8-)

--- End quote ---

The only thing I can think of is, how will this address putting the first <p> in before the first paragraph? Testing...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version