Save HTML

General TRichView support forum. Please post your questions here
Post Reply
cychia
Posts: 104
Joined: Mon Jan 16, 2006 1:52 am

Save HTML

Post by cychia »

I need my rv content to be save into non css html. But for those which can only be achieved by using css style like text highlight, an inline css style will be added.
e.g:
font style="background-color: #99ccff" highlighted text</font>

If there is no direct solution, do you have any suggestion for this ?
Yernar Shambayev
Posts: 57
Joined: Wed Aug 31, 2005 6:46 pm

Re: Save HTML

Post by Yernar Shambayev »

cychia wrote:I need my rv content to be save into non css html.

SaveHTMLEx exports contents of RichView to HTML file, using CSS.

SaveHTML exports contents of RichView to HTML file, using HTML tags like <FONT>, <B>, <DIV>, etc.
cychia
Posts: 104
Joined: Mon Jan 16, 2006 1:52 am

Post by cychia »

I am sorry for not giving a clear question.

I totally understand the usage of these two functions, SaveHTML and SaveHTMLEx.

My question is I would like to save rv as non css html (so i will call SaveHTML), but then since some of the function provided in the editor like text highlighting does not supported by non css html. Therefore, i need this particular style only to be exported as inline css for my html.

I've tried to search around for possible ways that rv could provide, but I failed to find one.

There is an event in rv named "OnSaveParaToHTML"
TRVSaveParaToHTMLEvent =
procedure (Sender: TCustomRichView;
RVData: TCustomRVData; ItemNo: Integer;
ParaStart, CSSVersion: Boolean;
var HTMLCode: String) of object;

but it is not suitable for my purpose because i need to write the style to tag like <font>

"<font style="background-color: #99ccff"> highlighted text</font> "

Therefore, I would like to ask:
1. if it is possible for rv to achieve this need?
2. if not possible, any other suggestions or workaround?
3. is there any event like OnSaveItemStyleToHTML, in which the ItemNo is provided, so that i can add extra html code to the tag as mentioned above?
Yernar Shambayev
Posts: 57
Joined: Wed Aug 31, 2005 6:46 pm

Post by Yernar Shambayev »

I am not able to test it, but please try it (OnSaveItemToFile event), something like this:

if (SaveFormat = rvsfHTML) and (RVData.GetItemStyle(ItemNo) >= 0) and
(Trim(RVData.GetItemText(ItemNo)) <> '') then begin
ItemStyle := RVData.GetItemStyle(ItemNo);

Style := rvs.TextStyles[ItemStyle];

(analyse the style and change OutStr)

DoDefault := False;
end;
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

No, modifying tags for text item attributes is not supported.
Yes, you can try to use OnSaveItemToFile to add new tags for text items.
But this is a low-level event, please read the help file very carefully.
cychia
Posts: 104
Joined: Mon Jan 16, 2006 1:52 am

Post by cychia »

I have tried out the event you have mentioned, it seems like working. So I would like to confirm with you something before I can 100% sure it is worked.

Below is my code:


if ((SaveFormat in [rvsfHTML]) and (RVData.GetItemStyle(ItemNo) >= 0)) then
begin
if Sender.Style.TextStyles[RVData.GetItemStyle(ItemNo)].BackColor <> clNone then
begin
OutStr := Format('<font style="background-color: %s">%s</font>',
[ColorToHex(Sender.Style.TextStyles[RVData.GetItemStyle(ItemNo)].BackColor),
OutStr]);
DoDefault := False;
end;
end;


In my application when I will only call SaveHTML with rvsoUTF8 is add into SaveOptions. From the code above, do i need to do any conversion to make sure the output is in utf8?
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

var s1, s2: String;
if ((SaveFormat in [rvsfHTML]) and (RVData.GetItemStyle(ItemNo) >= 0)) then 
begin 
  if Sender.Style.TextStyles[RVData.GetItemStyle(ItemNo)].BackColor <> clNone then 
  begin 
    s1 := Format('<font style="background-color: %s">', [ColorToHex(Sender.Style.TextStyles[RVData.GetItemStyle(ItemNo)].BackColor)]); 
    s2 := </font>;
    if Unicode then
    begin
      s1 := RVU_GetRawUnicode(s1);
      s2 := RVU_GetRawUnicode(s2);
    end;
    OutStr := s1+OutStr+s2; 
    DoDefault := False; 
  end; 
end; 
Post Reply