VFP's Editor Code RTF2HTML (Intro)

Version: 3.00.0 - last Update: Monday, September 21, 2009, 19:57:00

Previous EntryToolbox Home (TOC)Next Chapter 


This thread is all about how to get VFP’s syntax coloured code to a HTML-formatted Blog like this is.

Introduction

We all know that since VFP 7 (am I right?) we are able to copy & paste our code to the Windows clipboard without loosing the syntax colouring attributes. FoxPro does it by adding an additional clipboard format to the Windows clipboard called “Rich Text Format” while stuffing the source code to it.
However, RTF formatted text is not the thing we need in our Blogs, because we need HTML formatted content there. Thus, we are looking for some lightweight implementation, which enables us to translate RTF based content to the appropriate HTML based one.
There are many tools out there to accommodate this – generally. However, none of them is able to deal with VFP’s RTF output out of the box correctly because of the following:

  • VFP’s RTF output is poor!
  • VFP’s RTF output is buggy!
  • VFP's internal RTF writer has some bugs!
  • It's not easy to get VFP's RTF encoded clipboard data (using native FoxPro code)!

Other ways are pretty hard to go:

  • VFP's Class Browser's conversion capabilities are very limited
  • Word is adding an incredible overhead to the HTML outcome
  • Other commercial tools are expensive and are failing sometimes with VFP's RTF "slang"!

Well, IMOH, VFP’s developer crew tested their RTF output against WinWord only! In addition, WinWord is very forgivingly – at least when it comes to interpret RTF formatted text! The (final 9.0) VFP state we are in toady is that we are able to copy & paste everything from our VFP source code editor to any Microsoft text-processor, but we might fail when our pasting target is another WEB-based HTML application (even Microsoft’s own “Windows Live Writer” gets problems with VFP generated RTF sources!). Therefore, we need a tool that allows us to copy & paste our VFP’s syntax coloured RTF sources out to our Blogs or any other HTML based platform!

In other words: what we need is a home grown native VFP solution to solve this dilemma!

Table of Content

vfp-editor-code-rtf2html-part-2 Firstly, we need some good source of information about the RTF format. We will talk about the Rich Text Format version 1.5 specification in part 2 of this thread. Do not get lost while exploring the document referenced there because of its huge content. Let me tell you that we do not need most of the things that are listed there – luckily! Of course there are a lot more sites one can find searching the web for information about RTF tags, but for now let us agree on referencing the one linked in part 2
vfp-editor-code-rtf2html-part-3

Secondly, we need a way to access the RTF formatted content written by VFP to the clipboard when copying some selected source code from a VFP editor window using the “Ctrl-C” shortcut (or the VFP context menu).

vfp-editor-code-rtf2html-part-4 Thirdly, we need some kind of a minimalist RTF reader, which enables us to parse the RTF formatted VFP clipboard data and to decode the RTF header and the inline text attribute information.
vfp-editor-code-rtf2html-part-5 Next, we have to translate those RTF encoded information into HTML tags and replace all RTF tags with the appropriate HTML ones. Of course, we need some knowledge about HTML formatting, too. Again, you do not have to be a HTML specialist to achieve this, because there are not that much HTML tags needed.
vfp-editor-code-rtf2html-part-6 Finally, we have to write back the generated HTML formatted VFP source code into the clipboard, from where we can paste it into our Blog editor (or wherever else we want). Read more about the final implementation here.
Doc_Full_7 Additionally it is a good idea to complete this little tool by adding a configuration form that lets us add some setup information to make the produced outcome even more flexible (more on that later in the game). Read more about the GUI and extensions in the final part 7

Keep on rolling
as usual!


Previous EntryToolbox Home (TOC)Next Chapter

2 comments:

  1. Hi
    I quote :
    "Next, we have to translate those RTF encoded information into HTML tags and replace all RTF tags with the appropriate HTML ones..."
    I was (and still am) considering about such a transportation, but the work amount needed seems, er, how should I say, unbalanced, if the next sentence does not let any possibility to go further than ...

    "because there are not that much HTML tags needed. "

    IMHO, your steps are clear and neat, but the goal appears to be "copy&paste" RFT. This looks a bit restrictive, no?

    How about using "rules" in a chain of responsibility for translations ?

    Christian - Bordeaux - France

    ReplyDelete
  2. Hi Christian,
    the goal is:
    Copy&Paste >>TO>> HTML as the final destination format; either into the Windows clipboard, or into a file (like VFP does it within the class browser) - There will be different sources to choose from: RTF-formatted clipboard content definitely is one of them :-)
    I'm just rewriting part 6 of this thread - so be prepared: End of next week (until 11th of May) I will come up with a first stable beta version which will show all basic concepts more clearly :-)

    ReplyDelete