ガワを Delphi で作ってみました。
上にソースコード貼り付けて [Convert] ボタン押すとクリップボードに構文強調表示されたソースコードが入ります。

ソースコードはこんな感じです。アーカイブにプロジェクト一式が含まれていますので、気に入らないトコロがあったらご自由に改変してお使いください。
unit Unit1;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleCtrls, SHDocVw, System.NetEncoding;
type TForm1 = class(TForm) WebBrowser1: TWebBrowser; btnConvert: TButton; Memo1: TMemo; cbLanguage: TComboBox; procedure btnConvertClick(Sender: TObject); procedure Memo1KeyPress(Sender: TObject; var Key: Char); procedure WebBrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; const URL: OleVariant); private { Private 宣言 } public { Public 宣言 } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnConvertClick(Sender: TObject); // ドキュメントの生成&TWebBrowser へ読み込み var Document: TStringList; htmlFile: string; begin // Temporary html htmlFile := ChangeFileExt(Application.ExeName, '.html');
// Generate HTML Document := TStringList.Create; try Document.Add('<!DOCTYPE html>' ); Document.Add('<html lang="ja">' ); Document.Add(' <head>' ); Document.Add(' <meta http-equiv="content-type" content="text/css; charset=UTF-8">' ); Document.Add(' <link rel="stylesheet" href="./styles/radstudio.css">' ); Document.Add(' <script src="./highlight.pack.js"></script>' ); Document.Add(' </head>' ); Document.Add('<body>' ); Document.Add('<pre style="font-family: ''MS ゴシック''; font-size: 10pt; letter-spacing: 1px;">');
// Language Document.Add('<code class="' + LowerCase(cbLanguage.Text) + '">'); // Source Code Document.Add(TNetEncoding.HTML.Encode(Memo1.Lines.Text));
Document.Add('</code></pre>' ); Document.Add('<script type="text/javascript">hljs.initHighlightingOnLoad();</script>' ); Document.Add('</body>' ); Document.Add('</html>' );
// Save Document.SaveToFile(htmlFile, TEncoding.UTF8); finally Document.Free; end;
// TWebBrowser WebBrowser1.Navigate2(htmlFile); end;
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; const URL: OleVariant); // ドキュメントが読み込まれたらクリップボードへコピー var pvaIn, pvaOut: OleVariant; begin pvaIn := EmptyParam; pvaOut := EmptyParam; WebBrowser1.ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_PROMPTUSER, pvaIn, pvaOut); WebBrowser1.ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, pvaIn); end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char); // Ctrl+A で全選択 begin if Key = ^A then begin Key := #$00; Memo1.SelectAll; end; end;
end.
※ 詳しくは readme.txt をお読みください。
|