[BBC] 2 <HTML>
Hey guys,
I had fun today, while assembling this:
(defun C:BBC2HTML nil
(BBC2HTML (getfiled "Specify LISP file" (strcat (getenv "userprofile") "\\Desktop\\TestFolder\\") "bbc;lsp;txt" 16))
(princ)
); defun C:BBC2HTML
; https://www.cadtutor.net/forum/topic/66065-new-forum-code-tags/
; <!-- BBC 2 HTML, assembled by Grrr, credits to Lee Mac -->
; Substitutes [color="???"][/color] [b][i][u] BBC tags with html ones
; and then it creates an unique .html file and opens it
; NOTE: one still has to be careful and must check where he did used square brackets for his lisp code [] ! - are usually used within ssget/wcmatch patterns or regex
; 'src' - filepath that contains a BBC-formatted code
(defun BBC2HTML ( src / des rgx rtn str tmp r )
(if (and (eq 'STR (type src)) (setq des (open src "r")))
(progn
(while (setq str (read-line des)) (setq tmp (vl-list* "\n" str tmp))) (close des)
(cond
( (null (setq rgx (vlax-create-object "vbscript.regexp"))) (prompt "\nUnable to interface with RegEx object.") )
(
(vl-catch-all-error-p
(setq rtn
(vl-catch-all-apply
(function
(lambda ( )
(foreach x '(Global Multiline Ignorecase)
(vlax-put-property rgx x acTrue)
); foreach
(setq tmp (apply 'strcat (reverse tmp)))
(foreach x
'(
("<" . "<")
(">" . ">")
("\\[\\s*\/*\\s*(color)\\s*\\]" . "<\/font>")
("\\[\\s*(color)\\s*=\\s*\"" . "<font color=\"")
("\"\\s*\\]" . "\">")
("\\[\\s*b\\s*\\]" . "<b>")
("\\[\\s*i\\s*\\]" . "<i>")
("\\[\\s*u\\s*\\]" . "<u>")
("\\[\\s*\/\\s*b\\s*\\]" . "<\/b>")
("\\[\\s*\/\\s*i\\s*\\]" . "<\/i>")
("\\[\\s*\/\\s*u\\s*\\]" . "<\/u>")
("\\[\\s*\/*(code)\\s*\\]" . "")("\\[\\s*(color)\\s*=\\s*" . "<font color=") ("\\s*\\]" . ">") ; for David Bethel's lsp2bbc
)
(vlax-put-property rgx 'Pattern (car x))
(setq tmp (vlax-invoke-method rgx 'Replace tmp (cdr x)))
); foreach
tmp
); lambda
)
)
)
)
(prompt (strcat "\nError: " (vl-catch-all-error-message rtn)))
)
(rtn
(princ
(setq rtn
(strcat
"\n<!-- Open this resulted 'html' file with IE/Chrome/Mozilla -->"
"\n<!-- BBC 2 HTML, assembled by Grrr, credits to Lee Mac -->"
"\n<html>"
"\n<head><title>" (cadr (fnsplitl src)) "</title></head>"
"\n<body>"
"\n<div style=\"white-space: pre;\">"
rtn
"\n</div>"
"\n</body>"
"\n</html>"
); strcat
); setq rtn
(setq des
(open
(setq tmp
; (vl-filename-mktemp ; << not required, (I didn't knew this lol)
( ; unique filename sub
(lambda (s / i tmp)
(setq i 0)
(while (findfile (setq tmp (strcat s "_" (itoa i) ".html"))) (setq i (1+ i))) tmp
); lambda
(apply (function (lambda (a b c) (vl-string-translate "/" "\\" (strcat a b)))) (fnsplitl src))
)
; ); vl-filename-mktemp
); setq tmp
"W"
); open
); setq des
); princ
(close des)
(princ (strcat "\nTemporary html file created at \"" tmp "\", don't forget to erase it."))
(
(lambda ( fpath / shell ) ; ShellOpen
(if fpath
(vl-catch-all-apply
(function
(lambda nil
(setq shell (vlax-get-or-create-object "Shell.Application"))
(vlax-invoke-method shell 'Open fpath)
)
)
)
)
(vl-catch-all-apply 'vlax-release-object (list shell))
); lambda
tmp
)
(setq r rtn)
); rtn
)
)
(princ "\nUnable to read the file.")
)
(and (eq 'VLA-OBJECT (type rgx)) (vl-catch-all-apply (function vlax-release-object) (list rgx)))
(princ)
); defun BBC2HTML
Basically it will attempt to replace the bold/underline/italic/color BBC tags with HTML ones (I'm not so familiar with bbc formatting, so I couldn't figure out any other tags).
Then it will create an unique .html file and open it with your browser to display the colored code.
Demo:
I tested it with
• David Bethel's LSP2BBC,
• Lee Mac's LM:Lispstyler (BBC conversion),
• aswell some manual BBC modifications that you saw in the above posts
and it seems to work fine! Although still be careful with your square brackets [ ] in your lisp code!
Hm, now I see that the admins work on that issue!
+=