Page 1 of 1

Save HTML

Posted: Wed Sep 12, 2007 11:15 am
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 ?

Re: Save HTML

Posted: Thu Sep 13, 2007 4:36 am
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.

Posted: Fri Sep 14, 2007 1:06 am
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?

Posted: Fri Sep 14, 2007 6:13 am
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;

Posted: Fri Sep 14, 2007 4:29 pm
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.

Posted: Tue Sep 18, 2007 11:25 am
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?

Posted: Thu Sep 20, 2007 6:23 pm
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;