; AHK BBCodeWriter - An offline BBCode editor
; Copyright (C) 2006 AGermanUser
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
CreatePreview:
; Initialise MaxCodeTags variable to reset previous code findings
MaxCodeTags = 0
; Add signature if CheckBox is checked
If ChkSig = 1
{
If DDLSig is not space
{
FileRead, SigText, %A_ScriptDir%\signatures\%DDLSig%
bbcode = %bbcode%`n%SigText%
}
}
; Convert HTML sensitive chars ###############################################
StringReplace, bbcode, bbcode, &, &`;, All
StringReplace, bbcode, bbcode, <, <`;, All
StringReplace, bbcode, bbcode, >, >`;, All
; Save content of all [code] Tags ############################################
; Find positions of all [code] Tags und save their position
Loop,
{
StringGetPos, Position, bbcode, [code], L%A_Index%
If (ErrorLevel = 0)
{
CodeStartPos%A_Index% = %Position%
MaxCodeTags = %A_Index%
Continue
}
Else
Break
}
; Find positions of all [/code] Tags und save their position
Loop,
{
StringGetPos, Position, bbcode, [/code], L%A_Index%
If (ErrorLevel = 0)
{
CodeEndPos%A_Index% = %Position%
Continue
}
Else
Break
}
; Save content of [code] Tags
Loop, %MaxCodeTags%
{
NumberOfCodeCharsToCopy := CodeEndPos%A_Index% - CodeStartPos%A_Index% - 6
StringMid, CodeTag%A_Index%, bbcode, CodeStartPos%A_Index%+7, NumberOfCodeCharsToCopy
; Replace Space chars with
StringReplace, CodeTag%A_Index%, CodeTag%A_Index%, % A_Space, , All
}
; Convert Bold formatting ####################################################
StringReplace, bbcode, bbcode, [b], , All
StringReplace, bbcode, bbcode, [/b], , All
; Convert Italic formatting ##################################################
StringReplace, bbcode, bbcode, [i], , All
StringReplace, bbcode, bbcode, [/i], , All
; Convert Underline formatting ###############################################
StringReplace, bbcode, bbcode, [u], , All
StringReplace, bbcode, bbcode, [/u], , All
; Convert Image formatting ###################################################
StringReplace, bbcode, bbcode, [img], , All
; Convert Quote formatting ###################################################
; Case 1: [quote]Text[/quote]
StringReplace, bbcode, bbcode, [quote],
, All
}
Else
Break
}
StringReplace, bbcode, bbcode, [/quote],
, All
; Convert URL formatting #####################################################
; Case 1: [url]Domain[/url]
Loop,
{
StringGetPos, URLStartPos, bbcode, [url]
If ErrorLevel = 0
{
; Retrieve complete '[url]domain[/url]' string and assign to URLWithTags variable
StringGetPos, URLEndPos, bbcode, [/url], L1, URLStartPos
NumberOfURLCharsToCopy := URLEndPos - URLStartPos + 6
StringMid, URLWithTags, bbcode, URLStartPos+1, NumberOfURLCharsToCopy
; Remove [url] and [/url] tags from left and right side of string
StringTrimLeft, URLWithoutTags, URLWithTags, 5
StringTrimRight, URLWithoutTags, URLWithoutTags, 6
; In case tags have been noted within [ur][/url] (e.g. [url][b]domain[/b][/url])
; leave [url] Tags untouched - not allowed
TagsFound = 0
Loop, Parse, URLWithoutTags
{
If A_LoopField = <
TagsFound += 1
}
If TagsFound > 0
{
StringReplace, bbcode, bbcode, % URLWithTags, ~url]%URLWithoutTags%~/url]
Continue
}
; Replace BBCode with HTML code
StringReplace, bbcode, bbcode, % URLWithTags
, %URLWithoutTags%
Continue
}
Else
Break
}
StringReplace, bbcode, bbcode, ~url], [url], All
StringReplace, bbcode, bbcode, ~/url], [/url], All
; Case 2: [url=Domain]Linktext[/url]
Loop,
{
StringGetPos, URLStartPos, bbcode, [url=
If ErrorLevel = 0
{
; Make variables blank
URLWithTags =
URLWithoutTags =
StringGetPos, URLEndPos, bbcode, [/url], L1, URLStartPos
NumberOfURLCharsToCopy := URLEndPos - URLStartPos + 6
StringMid, URLWithTags, bbcode, URLStartPos+1, NumberOfURLCharsToCopy
StringSplit, ArrayOfURL, URLWithTags, ] ;, [url= [/url
StringTrimLeft, ArrayOfURL1, ArrayOfURL1, 5
StringTrimRight, ArrayOfURL2, ArrayOfURL2, 5
StringReplace, bbcode, bbcode, % URLWithTags
, %ArrayOfURL2%
Continue
}
Else
Break
}
; Convert E-Mail formatting ##################################################
Loop,
{
StringGetPos, EmailStartPos, bbcode, [email]
If ErrorLevel = 0
{
StringGetPos, EmailEndPos, bbcode, [/email]
NumberOfEmailCharsToCopy := EmailEndPos - EmailStartPos + 8
StringMid, EmailWithTags, bbcode, EmailStartPos+1, NumberOfEmailCharsToCopy
StringSplit, ArrayOfEmail, EmailWithTags, ]
StringTrimRight, ArrayOfEmail2, ArrayOfEmail2, 7
StringReplace, bbcode, bbcode, % EmailWithTags
, %ArrayOfEmail2%
Continue
}
Else
Break
}
; Convert FontColor formatting ###############################################
; Case 1: [color="colorname"][/color]
StringReplace, bbcode, bbcode, [color=darkred], , All
StringReplace, bbcode, bbcode, [color=red], , All
StringReplace, bbcode, bbcode, [color=orange], , All
StringReplace, bbcode, bbcode, [color=brown], , All
StringReplace, bbcode, bbcode, [color=yellow], , All
StringReplace, bbcode, bbcode, [color=green], , All
StringReplace, bbcode, bbcode, [color=olive], , All
StringReplace, bbcode, bbcode, [color=cyan], , All
StringReplace, bbcode, bbcode, [color=blue], , All
StringReplace, bbcode, bbcode, [color=darkblue], , All
StringReplace, bbcode, bbcode, [color=indigo], , All
StringReplace, bbcode, bbcode, [color=violet], , All
StringReplace, bbcode, bbcode, [color=white], , All
StringReplace, bbcode, bbcode, [color=black], , All
; Case 2: [color=#hexvalue][/color]
Loop,
{
StringGetPos, ColorStartPos, bbcode, [color=
If ErrorLevel = 0
{
StringGetPos, ColorEndPos, bbcode, ], L1, ColorStartPos
NumberOfColorCharsToCopy := ColorEndPos - ColorStartPos + 1
StringMid, ColorWithTags, bbcode, ColorStartPos+1, NumberOfColorCharsToCopy
StringTrimLeft, ColorWithoutTags, ColorWithTags, 7
StringTrimRight, ColorWithoutTags, ColorWithoutTags, 1
StringReplace, bbcode, bbcode, % ColorWithTags, , All
}
Else
Break
}
StringReplace, bbcode, bbcode, [/color], , All
; Convert FontSize formatting ################################################
Loop, %MaxFontSize%
{
StringReplace, bbcode, bbcode, [size=%A_Index%]
, , All
}
StringReplace, bbcode, bbcode, [/size], , All
; Convert Numbered List formatting ###########################################
NumListTag =
Loop,
{
; Position of List Tag
StringGetPos, ListStartPos, bbcode, [list=1]
If Errorlevel = 0
{
; Position of first ending tag
StringGetPos, ListEndPos, bbcode, [/list],, %ListStartPos%
CountLists := ListStartPos + 1
; Counting variable for List Tag between first List Tag
; and first ending List Tag
i = 1
Loop,
{
; Find position of next List Tag
StringGetPos, NextListStart, bbcode, [list,, CountLists
If ErrorLevel = 0
{
; If next List Tag is between first List Tag and first ending List Tag
If (NextListStart < ListEndPos)
{
i++
CountLists := ListStartPos + 1 + NextListStart
Continue
}
Else
Break
}
Else
Break
}
If i > 1
StringGetPos, ListEndPos, bbcode, [/list], L%i%, %ListStartPos%
bbcode := StringReplaceWord(bbcode, ListEndPos, 7, "")
bbcode := StringReplaceWord(bbcode, ListStartPos, 8, NumListTag)
}
Else
Break
}
; Convert Alphabetical List formatting #######################################
CharListTag =
Loop,
{
; Position of List Tag
StringGetPos, ListStartPos, bbcode, [list=a]
If Errorlevel = 0
{
; Position of first ending tag
StringGetPos, ListEndPos, bbcode, [/list],, %ListStartPos%
CountLists := ListStartPos + 1
; Counting variable for List Tag between first List Tag
; and first ending List Tag
i = 1
Loop,
{
; Find position of next List Tag
StringGetPos, NextListStart, bbcode, [list,, CountLists
If ErrorLevel = 0
{
; If next List Tag is between first List Tag and first ending List Tag
If (NextListStart < ListEndPos)
{
i++
CountLists := ListStartPos + 1 + NextListStart
Continue
}
Else
Break
}
Else
Break
}
StringGetPos, ListEndPos, bbcode, [/list], L%i%, %ListStartPos%
bbcode := StringReplaceWord(bbcode, ListEndPos, 7, "")
bbcode := StringReplaceWord(bbcode, ListStartPos, 8, CharListTag)
}
Else
Break
}
; Convert Unordered List formatting ##########################################
Loop,
{
; Position of List Tag
StringGetPos, ListStartPos, bbcode, [list]
If Errorlevel = 0
{
; Position of first ending tag
StringGetPos, ListEndPos, bbcode, [/list],, %ListStartPos%
CountLists := ListStartPos + 1
; Counting variable for List Tag between first List Tag
; and first ending List Tag
i = 1
Loop,
{
; Find position of next List Tag
StringGetPos, NextListStart, bbcode, [list,, CountLists
If ErrorLevel = 0
{
; If next List Tag is between first List Tag and first ending List Tag
If (NextListStart < ListEndPos)
{
i++
CountLists := ListStartPos + 1 + NextListStart
Continue
}
Else
Break
}
Else
Break
}
StringGetPos, ListEndPos, bbcode, [/list], L%i%, %ListStartPos%
bbcode := StringReplaceWord(bbcode, ListEndPos, 7, "")
bbcode := StringReplaceWord(bbcode, ListStartPos, 6, "
")
}
Else
Break
}
; Convert List Style Type formatting #########################################
StringReplace, bbcode, bbcode, [*],
, All
; Convert Smileys ###########################################################
StringReplace, bbcode, bbcode, :arrow:, , All
StringReplace, bbcode, bbcode, :idea:, , All
StringReplace, bbcode, bbcode, :wink:, , All
StringReplace, bbcode, bbcode, :cry:, , All
StringReplace, bbcode, bbcode, :evil:, , All
StringReplace, bbcode, bbcode, :twisted:, , All
StringReplace, bbcode, bbcode, :roll:, , All
StringReplace, bbcode, bbcode, :lol:, , All
StringReplace, bbcode, bbcode, :oops:, , All
StringReplace, bbcode, bbcode, :shock:, , All
StringReplace, bbcode, bbcode, :mrgreen:, , All
StringReplace, bbcode, bbcode, :?:, , All
StringReplace, bbcode, bbcode, :!:, , All
StringReplace, bbcode, bbcode, :D, , All
StringReplace, bbcode, bbcode, :), , All
StringReplace, bbcode, bbcode, :(, , All
StringReplace, bbcode, bbcode, :o, , All
StringReplace, bbcode, bbcode, :?, , All
StringReplace, bbcode, bbcode, 8), , All
StringReplace, bbcode, bbcode, :x, , All
StringReplace, bbcode, bbcode, :P, , All
StringReplace, bbcode, bbcode, `;), , All
StringReplace, bbcode, bbcode, :|, , All
; Convert Code Tags formatting ###############################################
; Find positions of all accidentally formatted [code] Tags und save their positions
Loop,
{
StringGetPos, Position, bbcode, [code], L%A_Index%
If (ErrorLevel = 0)
{
CodeStartPos%A_Index% = %Position%
MaxCodeTags = %A_Index%
Continue
}
Else
Break
}
; Find positions of all accidentally formatted [/code] Tags und save their positions
Loop, %MaxCodeTags%
{
StringGetPos, Position, bbcode, [/code], L%A_Index%
If (ErrorLevel = 0)
{
CodeEndPos%A_Index% = %Position%
Continue
}
Else
Break
}
; Find content of formatted [code] Tags and replace them with the original code
Loop, %MaxCodeTags%
{
GoSub, FindCodePositions
NumberOfCodeCharsToCopy := CodeEndPos%A_Index% - CodeStartPos%A_Index% - 6
StringMid, ChangedCodeTag%A_Index%, bbcode, CodeStartPos%A_Index%+7, NumberOfCodeCharsToCopy
StringReplace, bbcode, bbcode, % ChangedCodeTag%A_Index%, % CodeTag%A_Index%
}
StringReplace, bbcode, bbcode, [code],
Code:
, All
StringReplace, bbcode, bbcode, [/code],
, All
; Convert Linebreaks #########################################################
StringReplace, bbcode, bbcode, `n, `n, All
; Create Head of HTML page
FileAppend,
(LTrim
BBCodeWriter Preview
version %Version%
Message
), preview.html
; Paste postingtext in HTML page
FileAppend, %bbcode%, preview.html
; Create end of HTML page
FileAppend,
(LTrim
), preview.html
; Check whether BBCodeWriter already created a browser window
IfWinExist, BBCodeWriter Preview
{
WinActivate, BBCodeWriter Preview
Send, {F5}
}
Else
{
; Run defined browser with preview page
Run, %BrowserExe% "%A_WorkingDir%\preview.html"
WinWait, BBCodeWriter Preview
WinActivate, BBCodeWriter Preview
}
Return
;##############################################################################
;####### General Subroutines ##################################################
;##############################################################################
FindCodePositions:
; Find positions of all accidentally formatted [code] Tags und save their positions
Loop,
{
StringGetPos, Position, bbcode, [code], L%A_Index%
If (ErrorLevel = 0)
{
CodeStartPos%A_Index% = %Position%
MaxCodeTags = %A_Index%
Continue
}
Else
Break
}
; Find positions of all accidentally formatted [/code] Tags und save their positions
Loop, %MaxCodeTags%
{
StringGetPos, Position, bbcode, [/code], L%A_Index%
If (ErrorLevel = 0)
{
CodeEndPos%A_Index% = %Position%
Continue
}
Else
Break
}
Return
;##############################################################################
;####### End of General Subroutines ###########################################
;##############################################################################