ScriptBoxquote
From 40tude Dialog Wiki
Contents |
Boxquotes
Boxquotes are a cool way of emphasizing text in your posts/e-mails.
Marcus Mönnig made a script to automagically insert Boxquotes into a message before being sent. Thomas Barghahn has changed the script, so that you are able to decide inside the editor window what kind of Boxquotes (closed or open) you want to use.
Using Boxquotes
- Please note, that you will see the result not inside the editor-window but only in the transmitted article!
Closed Boxquotes
To use closed Boxquotes, you have to insert the following tags inside the editor window (into your text):
box: Example - aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl asdlkja lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak -
You will get this kind of Boxquote:
,---- [ Example] ------------------------------------------------. | aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd | | lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl | | asdlkja lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak | '----------------------------------------------------------------'
Open Boxquotes
And if you don't want closed Boxquotes, just use box_o instead of box:
box_o: Example - aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak -
And now you will get this open Boxquote.
,---- [Example] | aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd | lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl | lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak '----
Install & Setup the script
Of course the tags alone won't do much. You have to insert the following script into the OnBeforeSendingMessage event of your scripting window.
Setup in the script:
If you want to change the tags for the Boxquotes and the seperator, you have to edit the three lines below inside the script.
StartLine_close_box = 'box:'; StartLine_open_box = 'box_o:'; Separator = '-';
program OnBeforeSendingMessage;
const
//
// configure your settings here:
//
StartLine_close_box = 'box:';
StartLine_open_box = 'box_o:';
Separator = '-';
// --------------------------------------------------------------- //
// ---- No user maintainable parts below this line -------------- //
// --------------------------------------------------------------- //
MaxInt = 2147483647;
bq1a = ',';
bq1b = '-';
bq1c = '.';
bq2a = '|';
bq2c = '|';
bq3a = ''+#39+'';
bq3b = '-';
bq3c = ''+#39+'';
LineWidthTop = 4;
LineWidthBottom = 4;
s_no_bq = 0;
s_bq_title = 1;
s_bq_content = 2;
//
// program BoxQuote - Date: 2004/11/05
//
function StringReplaceM(
S : String;
OldPattern : String;
NewPattern : String;
replaceall : Boolean;
ignorecase : Boolean
) : String;
var
SearchStr : String;
Patt : String;
NewStr : String;
Offset : Integer;
begin
if IgnoreCase then begin
SearchStr := AnsiUpperCase( S );
Patt := AnsiUpperCase( OldPattern );
end
else begin
SearchStr := S;
Patt := OldPattern;
end;
NewStr := S;
Result := '';
while SearchStr <> '' do begin
Offset := AnsiPos(Patt, SearchStr);
if Offset = 0 then begin
result := result + NewStr;
break;
end;
result := result + Copy( NewStr, 1, Offset - 1 ) + NewPattern;
NewStr := Copy( NewStr, Offset + Length(OldPattern), MaxInt );
if not ReplaceAll then begin
Result := Result + NewStr;
break;
end;
SearchStr := Copy( SearchStr, Offset + Length(Patt), MaxInt );
end;
end; // function StringReplaceM()
function RepeatChar(
c : Char;
count : Integer
) : String;
var
i : Integer;
begin
if count < 0 then count := 0;
SetLength( result, count );
for i:=1 to count do result[i] := c;
end; // function RepeatChar()
function CountChars(
s : String;
c : Char
) : Integer;
var
i : Integer;
begin
result := 0;
for i := 1 to Length( s ) do if s[i] = c then result := result + 1;
end; // function CountChars()
procedure BoxQuote(
var Message : TStringlist
);
var
i, j, k : Integer;
state : Word;
bq_startline : Integer;
bq_title : String;
bq_content : String;
maxwidth : Integer;
sl : Tstringlist;
CloseBox : Boolean;
begin
state := s_no_bq;
i := 0;
bq_startline := -1;
while i <= message.count-1 do begin
case state of
s_no_bq: begin
if (message.strings[i] = StartLine_close_box)
or (message.strings[i] = StartLine_open_box)
then begin
if message.strings[i] = StartLine_close_box
then CloseBox := true
else CloseBox := false;
bq_startline := i;
bq_title := '';
bq_content := '';
maxwidth := 1;
state := s_bq_title;
end
end;
s_bq_title: begin
if message.strings[i] = Separator
then state := s_bq_content
else bq_title := trim( bq_title + ' ' + message.strings[i] );
end;
s_bq_content: begin
if message.strings[i]=Separator then begin
state:=s_no_bq;
if Length( '[' + bq_title + ']' ) > maxwidth
then maxwidth := Length( '[' + bq_title + ']' ) + 6;
//
// delete the raw BoxQuote
//
for j := bq_startline to i do message.delete( bq_startline );
//
// middle part
//
bq_content := stringreplacem( #13#10 + bq_content,
#13#10, #13#10 + bq2a + ' ',
true, false );
delete( bq_content, 1, 2 );
//
// first line
//
if bq_title <> ''
then bq_content := bq1a
+ RepeatChar( bq1b, LineWidthTop )
+ ' [' + bq_title + '] '
+ #13#10
+ bq_content
else bq_content := bq1a
+ RepeatChar( bq1b, LineWidthTop )
+ #13#10
+ bq_content;
//
// last line
//
bq_content := bq_content + #13#10 + bq3a + RepeatChar( bq3b, LineWidthBottom );
sl := Tstringlist.create;
try
sl.text := bq_content;
//
// close the box
//
if CloseBox then begin
for j:=0 to sl.count-1 do begin
k := maxwidth - length( sl.strings[j] );
if j=0
then sl.strings[j] := sl.strings[j] + repeatchar( bq1b,k + 3 ) + bq1c
else if j = sl.count-1
then sl.strings[j] := sl.strings[j] + repeatchar( bq3b,k + 3 ) + bq3c
else sl.strings[j] := sl.strings[j] + repeatchar(' ', k + 3) + bq2c;
end;
end;
message.insert( bq_startline, trim(sl.text) );
i := bq_startline;
finally
sl.free;
end;
end
else begin
if bq_content = ''
then bq_content := message.strings[i]
else bq_content := bq_content + #13#10 + message.strings[i];
if Length( message.strings[i] ) > maxwidth
then maxwidth := length( message.strings[i] );
end;
end;
end; // case
i := i + 1;
end;
end; // procedure BoxQuote()
function OnBeforeSendingMessage(
var Message : TStringlist;
const Servername : String;
const IsEmail : Boolean
) : Boolean;
begin
//
// if result is set to false, sending messages will *always* fail;
// use this for debugging along with the messagebox.
//
result := true;
if Message.count < 500 then BoxQuote( Message );
end; // function OnBeforeSendingMessage()
begin
end.
J. Cifer