Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
497 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Exporting Syntax Highlighted text to HTMLFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Others
Skill Level:
Scoring:
Last Update:
03/16/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Syntax Highlighter HTML Export
Times Scored:
2
Visits:
2707
Uploader: Danilo Vieira
Company:
Reference: http://synedit.sourceforge.net
 
Question/Problem/Abstract:
In the past there have been requests on this already... now there
is a new one. I really thing for this topic there should be a
sourcecode available for all the folks in the DELPHI COMMUNITY.

The job is simple... take a delphi-, java, C#, VB, C++ (to name the
most wanted ones) sourcefile and create a HTML file where the
syntax is highlighted.
Answer:



There is an easy way to make a Syntax Highlighter that exports HTML: Using SynEdit (a free component colection with full sourcecode). SynEdit comes with many highlighters for many languages: Delphi, VB, C++, Perl, Sql, Java and many more. And it also includes a class named TSynExporterHTML, that exports any highlighted text to HTML. Get SynEdit in its WebSite: http://synedit.sourceforge.net.

Here is an example of how to use TSynExporterHTML:


{$APPTYPE CONSOLE}

program pas2html;

{$I SynEdit.inc}

uses
  
Windows, Classes, Clipbrd, SynHighlighterPas, SynExportHTML;

var
  
ALines: TStringList;
  Syn: TSynPasSyn;
  Exp: TSynExporterHTML;
begin
  if
Clipboard.HasFormat(CF_TEXT) then begin
    
ALines := TStringList.Create;
    try
      
Syn := TSynPasSyn.Create(nil);
      try
        
// get syntax highlighter settings
        
Syn.EnumUserSettings(ALines);
        if ALines.Count > 0 then
          
Syn.UseUserSettings(ALines.Count - 1);
        // load text from clipboard
        
ALines.Text := Clipboard.AsText;  
        // export ALines to HTML, as HTML fragment in text format
        
Exp := TSynExporterHTML.Create(nil);
        try
          
Exp.Highlighter := Syn;
          Exp.ExportAsText := TRUE;
          Exp.CreateHTMLFragment := TRUE;
          Exp.ExportAll(ALines);
          Exp.CopyToClipboard;
        finally
          
Exp.Free;
        end;
      finally
        
Syn.Free;
      end;
    finally
      
ALines.Free;
    end;
  end;
end.



This example just get some source code from the clipboard, highlight it (as
Object Pascal source) and copy it into the clipboard as HTML (then you can
paste it on a HTML editor). As you can see the source uses a TStringList,
so if you want to use a file just use:
ALines.LoadFromFile('C:\Somefile.pas').

The syntax highlighted text above was created with SynEdit...





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
R. Lefter
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)