Post by metro on Sept 3, 2023 18:07:04 GMT -5
This may be of interest
'** Bare Bones HTML Editor
'** Alyce Watson, 2004
global s$
s$ = ""
global filename$
nomainwin
q$=chr$(34)'double quotation mark
lf$ = chr$(13) + chr$(10)
nowPath$=DefaultDir$ 'current directory for file operations
WindowWidth = 550:WindowHeight = 410
menu #main, "&File","&New",[new],"&Open",[open],"&Save",[save],"Convert to &CGI", [cgi], _
"Save cgi file", [cgi_save], | ,"&View",[view],"&Print",[print],|,"E&xit",[quit]
menu #main, "Edit"
menu #main, "&Help","&Instructions",[help],"&About",[about]
button #main.new, "new", [new], UL, 0, 0, 24, 24
button #main.font, "<fnt>", [font], UL, 24, 0, 30, 24
button #main.para, "<p>", [para], UL, 54, 0, 24, 24
button #main.br, "<br>", br, UL, 78, 0, 24, 24
button #main.hr, "<hr>", [hr], UL, 102, 0, 24, 24
button #main.table, "<tble>", [table], UL, 126, 0, 34, 24
button #main.center, "<ctr>", [center],UL,160,0,30,24
button #main.div, "<div>",[div],UL,190,0,30,24
button #main.ul, "<ul>",[ul],UL,220,0,24,24
button #main.ol, "<ol>",[ol],UL,244,0,24,24
button #main.pre, "<pre>",[pre],UL,268,0,30,24
button #main.img, "<img>",[img],UL,298,0,30,24
button #main.href, "<a href>",[href],UL,328,0,44,24
texteditor #main.te, 2, 25, 537, 338
'hidden texteditor allows copy to clipboard so that
'text can be pasted into visible texteditor at current location
texteditor #main.h, -1000,0,600,300
open "Bare Bones HTML Editor" for window as #main
'trap the event of user closing window with X button
#main "trapclose [quit]"
'set font for all controls on window
#main "font ms_sans_serif 8"
'cause texteditor to resize when window size changes
#main.te "!autoresize"
'issue separate font command for texteditor
'courier_new is a monospaced font
#main.te "!font courier_new 10"
[new]
#main.te "!modified? ans$"
if ans$="true" then
confirm "Would you like to save the current file?";answer$
if answer$="yes" then
filedialog "Save As",nowPath$+"*.html",file$
if file$="" then wait
#main.te "!contents? t$"
open file$ for output as #f
print #f, t$
close #f
'separate the path from the newly opened filename
'so it can be used elsewhere
nowPath$=SeparatePath$(file$)
end if
end if
#main.te "!cls"
#main.te "<html>"
#main.te "<head>"
#main.te "<title>Title of Page</title>"
#main.te "</head>"
#main.te "<body>"
#main.te "<center><h2>Headline Goes Here</h2></center>"
#main.te ""
#main.te ""
#main.te ""
#main.te "</body></html>"
#main.te "!setfocus"
wait
[quit] close #main:end
[open]
'add a path to the extension to cause the filedialog
'to begin in the designated path
filedialog "Open",nowPath$+"*.htm;*.html",file$
if file$="" then wait
open file$ for input as #f
#main.te "!contents #f"
close #f
'separate the path from the newly opened filename
'so it can be used elsewhere
nowPath$=SeparatePath$(file$)
#main.te "!setfocus"
wait
[cgi]
#main.te "!contents? s$"
open "temp.txt" for output as #temp
print #temp, s$
close #temp
s$ = " html$ = " + q$ + "Content-type:text/html" + q$ + _
" + chr$(13)+chr$(10)+chr$(13)+chr$(10) " + chr$(13)+chr$(10)
open "temp.txt" for input as #temp
[loop]
if eof(#temp) <> 0 then [finish_read]
line input #temp, item$
t$ = ""
for x = 1 to len(item$)
if mid$(item$,x,1) = chr$(34) then
t$ = t$ + chr$(34) + " + chr$(34) + " + chr$(34)
else
t$ = t$ + mid$(item$,x,1)
end if
next x
s$ = s$ + " html$ = html$ + " + q$ + t$ + q$ + lf$
goto [loop]
[finish_read]
close #temp
WindowWidth=400
WindowHeight = 400
texteditor #cgibox.texted, 10, 10, 370, 350
open "cgi text" for dialog_modal as #cgibox
print #cgibox, "trapclose [cgiclose]"
print #cgibox.texted, "!contents s$"
wait
[cgiclose]
close #cgibox
#main.te "!setfocus"
wait
[cgi_save]
filedialog "Save As",nowPath$+"\*.cgilb",file$
if file$="" then wait
open file$ for output as #f
print #f, s$
close #f
'separate the path from the newly opened filename
'so it can be used elsewhere
'nowPath$=SeparatePath$(file$)
notice "File saved as ";file$
wait
[save]
'add a path to the extension to cause the filedialog
'to begin in the designated path
filedialog "Save As",nowPath$+"*.html",file$
if file$="" then wait
#main.te "!contents? t$"
open file$ for output as #f
print #f, t$
close #f
'separate the path from the newly opened filename
'so it can be used elsewhere
nowPath$=SeparatePath$(file$)
notice "File saved as ";file$
#main.te "!setfocus"
wait
[view]
#main.te "!contents? t$" 'get contents of texteditor into string variable
open nowPath$+"temp.html" for output as #f
print #f, t$ 'write to disk in temp file for viewing
close #f
'open user's default browser
run "explorer "+q$+nowPath$+"temp.html"+q$,RESTORE
wait
[print]
#main.te "!contents? t$" 'get contents of texteditor into string variable
lprint t$ 'send to printer
dump 'cause printing to start now
wait
[help]
m$="You may open an existing HTML file, or begin a new one. "
m$=m$+"Click the corresponding button to insert an HTML tag at the current caret location in the text. "
m$=m$+"You can save or print the file by selecting those options from the File Menu. "
m$=m$+"You can even preview a file in your default browser by selecting View from the File Menu. "
m$=m$+"There are many online references for HTML scripting. "
m$=m$+"This program does not attempt to document HTML tags. "
notice m$
#main.te "!setfocus"
wait
[about]
notice "Bare Bones HTML Editor "+chr$(169)+"2004, Alyce Watson"
#main.te "!setfocus"
wait
[font]
#main.h "<font size=3 face=verdana color=black>"
#main.h "</font>"
call PasteIt
wait
[para]
#main.h "<p>"
#main.h "</p>"
call PasteIt
wait
[hr]
#main.h "<hr>"
call PasteIt
wait
[table]
#main.h "<center>"
#main.h "<table border=2 cellspacing=2 cellpadding=2 bgcolor=#00ffff width=80%>"
#main.h "<th colspan=2>Table Header</th>"
#main.h "<tr>"
#main.h "<td align=center>First Row, First Column</td>"
#main.h "<td align=center>First Row, Second Column</td>"
#main.h "</tr>"
#main.h "<tr>"
#main.h "<td align=center>Second Row, First Column</td>"
#main.h "<td align=center>Second Row, Second Column</td>"
#main.h "</tr>"
#main.h "</table>"
#main.h "</center>"
call PasteIt
wait
[center]
#main.h "<center>"
#main.h "</center>"
call PasteIt
wait
[div]
#main.h "<div>"
#main.h "</div>"
call PasteIt
wait
[ul]
#main.h "<ul>Unordered List Title"
#main.h "<li>List Item"
#main.h "<li>List Item"
#main.h "<li>List Item"
#main.h "</ul>"
call PasteIt
wait
[ol]
#main.h "<ol>Ordered List Title"
#main.h "<li>List Item"
#main.h "<li>List Item"
#main.h "<li>List Item"
#main.h "</ol>"
call PasteIt
wait
[pre]
#main.h "<pre>"
#main.h "Preformatted text goes here."
#main.h "</pre>"
call PasteIt
wait
[img]
#main.h "<img src="+q$+"imagename.jpg"+q$+">"
call PasteIt
wait
[href]
#main.h "<a href="+q$+"url.html"+q$+">URL Name Here</a>"
call PasteIt
wait
'This sub copies text from hidden texteditor and puts it on clipboard,
'then pastes it to visible texteditor at current cursor position
Sub PasteIt
#main.h "!selectall"
#main.h "!copy"
#main.te "!paste"
#main.h "!cls"
#main.te "!setfocus"
end sub
Function SeparatePath$(f$)
fileindex=Len(f$)
filelength=Len(f$)
While Mid$(f$, fileindex,1)<>"\"
fileindex=fileindex-1
Wend
SeparatePath$=Left$(f$,fileindex)
End Function