hanhphuc Posted September 24, 2018 Share Posted September 24, 2018 (edited) Hi guys, Quote Since CADTutor transitioned from vBulletin to the new Invision forum software, BBCode (e.g. color tags) are no longer permitted within code blocks and are consequently now displayed as part of the code itself i.e: previous codes with formatted BBcode tags became messy & erroneous! example: erroneous code copied from forum (setq [b] [color="blue"] pl [/color][/b]'((10. 50.)(20. 50.)(30. 50.)(40. 50.)(50. 50.))[color="green"]; point list[/color] ss ([color="blue"] ssget [/color] (append ([color="blue"] [b]vl-list*[/b] [/color] '(0 . [color="purple"] "CIRCLE,TEXT,INSERT" [/color] ) [color="green"]; filter [/color] '(-4 . "<OR")(apply 'append (mapcar ''((x) (list '(-4 . [color="purple"] "=,=,*" [/color] ) (cons 10 x))) [b] pl [/b])) ) '((-4 . "OR>")) ) ) ) ) After BB codes removed which contents within the brackets "[" "]". (setq pl '((10. 50.)(20. 50.)(30. 50.)(40. 50.)(50. 50.)); point list ss ( ssget (append ( vl-list* '(0 . "CIRCLE,TEXT,INSERT" ) ; filter '(-4 . "<OR")(apply 'append (mapcar ''((x) (list '(-4 . "=,=,*" ) (cons 10 x))) pl )) ) '((-4 . "OR>")) ) ) ) ) ATM i could only edit for single post using this simple code merely remove contents within the brackets "[" "]". Hope this help? here's is very basic idea with minimal error handling. you can put addition ideas in cond etc.. (defun c:forum (/ cbdata *error* $ fn fi fo l) ; example: [B] hanhphuc [/B] [Color=blue] defun [/color] ;; command: forum or command: BBCU (abbreviation of BBCode Unformat) - hanhphuc ;; babe see you (defun *error* (msg) (if fi (close fi))) ;;;http://www.theswamp.org/index.php?topic=21764.msg263322#msg263322 (defun cbdata (/ cb html) ;optimized hp (setq cb (vl-catch-all-apply 'vlax-invoke (list ((lambda (doc) (foreach x '(parentwindow clipboarddata) (setq doc (vlax-get doc x)) ) ) (setq html (vlax-create-object "htmlfile")) ) 'getdata "text" ) ) ) (vlax-release-object html) (if (not (vl-catch-all-error-p cb) ) cb ) ) (and (setq fn (strcat (getvar 'tempprefix) "tmp.txt") fi (open fn "w") ) (setq $ (cbdata)) (write-line $ fi) (progn (close fi) (setq fi (open fn "r"))) (while (setq $ (read-char fi)) (setq l (cons $ l))) (progn (if fi (close fi) ) (setq fn (strcat (getvar 'tempprefix) "cadtutor.lsp")) (setq fo (open fn "w")) ) (foreach x (vl-remove-if '(lambda ( x )(or (listp x) (> x 191 ))) (read (strcat "(" (apply 'strcat (mapcar '(lambda (x) (strcat (if (numberp x) (cond ((= 91 x) "(") ((= 93 x) ")") (t (itoa x)) ) x ) " " ) ) (reverse l) ) ) ")" ) ) ) (write-char x fo) ) (progn (if fo (close fo) ) (findfile fn) ) (vl-cmdf "_.SHELL" (strcat "CLIP < " fn )) (alert "[BBCode Tags] removed! Try [Ctrl^C] in the forum!") ) (princ) ) (defun c:BBCU () (c:forum)(princ)) Step 1.save the above lisp, save in your valid path. APPLOAD in ACAD active drawing. 2.copy any 'infected' codes from forum 3.load this "forum.lsp" invoke --> command: BBCU or command: forum 4. simply paste it back to forum active editor (for coders - if you wanna to modify your previous code) for user - paste it to notepad etc.. save your file as '*.lsp' extension. e.g: 'cadtutor.lsp' Any ideas for multiple editing? RegEx ? Here's another alternative removing color tags using Notepad++ by Lee Mac Edited December 16, 2019 by hanhphuc Code updated with clipboard function, lambda new comments 1 1 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 24, 2018 Share Posted September 24, 2018 Hi hanhphuc Here is my program to reform the AutoLISP codes regardless of the file format if it is .lsp or .txt reform.LSP 1 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted September 24, 2018 Author Share Posted September 24, 2018 4 hours ago, Tharwat said: Hi hanhphuc Here is my program to reform the AutoLISP codes regardless of the file format if it is .lsp or .txt reform.LSP as usual Tharwat another way to skin the cat It maybe difficult for them (novice or anyone knows nothing/little about Lisp) to debug or unformat these old forum codes. Hope this thread helps members who maybe have copied 'formated' codes from this forum. since my simple methodology is just to remove brackets "[ ]" , the hiccup if brackets in the prompt string example: (getkword "Enter [Yes/No] ? <Y> : ") i follow your idea to save output as lisp Quote Link to comment Share on other sites More sharing options...
Grrr Posted September 25, 2018 Share Posted September 25, 2018 (edited) I had the same thought as hanhphuc since the forum updates, about the "old" forum code tags. However didn't had enough time to practice, but now managed to get some. So this is a variation of Lee's stripcomments that uses regex (I had a hard time to figure out the regex pattern) : ; (StripForumCodeTags (getfiled "Specify LISP file" (strcat (getenv "userprofile") "\\Desktop\\") "lsp" 16)) ; StripForumCodeTags is a variation routine of the "stripcomments" one by Lee Mac https://www.theswamp.org/index.php?topic=53746.30 (Get rid of comments) (defun StripForumCodeTags ( lsp / des rgx rtn str tmp ) (if (and (eq 'STR (type lsp)) (setq des (open lsp "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 (vlax-put-property rgx 'pattern (strcat ; \[\s*\w*\s*=\s*"\s*\w*\s*"\s*\]|\[\s*/*\s*[a-z]\s*\]|\[\s*/*\s*\w*\s*\] "\\[\\s*\\w*\\s*=\\s*\"\\s*\\w*\\s*\"\\s*\\]" "|" "\\[\\s*\/*\\s*[a-z]\\s*\\]" "|" "\\[\\s*\/*\\s*\\w*\\s*\\]" ); strcat ); vlax-put-property (vlax-invoke rgx 'replace (apply 'strcat (reverse tmp)) "") ) ) ) ) ) (prompt (strcat "\nError: " (vl-catch-all-error-message rtn))) ) ( (princ 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 StripForumCodeTags And a sample code that I tested: (defun [b][i][u]C:SampleCode[/b][/i][/u] ( / str SS i e o ) ; unformat forum code tags, example ; [I][u][B] Grrr [/B][/u][ / I ] [ color = " blue " ] sample defun [ / color ] ([ color = " blue " ]cond[ / color ] ( (not (setq str (getstring [ color = " purple " ]"\nSpecify a string: "[ / color ]))) (prompt "\nBye") ) ( (= "" str) (prompt "\nBYE!") ) ( (setq SS (ssget [color="purple"]"_:L-I"[/color] '(0 . "*TEXT"))) (repeat (setq i (sslength SS)) (and (setq e (ssname SS (setq i (1- i)))) (setq o (vlax-ename->vla-object e)) (if (vlax-property-available-p o 'TextString) (vlax-put-property o 'TextString str)) )[color="green"]; and [/color] )[color="green"]; repeat [/color] )[ color = "green" ]; setq SS [/color] )[ color = "green" ]; cond [/ color ] )[ color = "green" ]; defun [B][I][U]C:SampleCode[/B][/I][/U] [ / color ] [ color = " blue " ] [color="green"] [ attribute = " value " ] ; something [attribute="value"] [ font = " arial " ] [font="arial"] [ color = " blue " ] [color="green"] [/color] [ / color ] [/whatever] [ / whatever ] [b][i][u] [ / i ] [ / u ] [ / b ] [a] [ a ] [k] [ k ] [ / a ] [ / k ] [ ] [ / ] that will yield result of: (defun C:SampleCode ( / str SS i e o ) ; unformat forum code tags, example ; Grrr sample defun (cond ( (not (setq str (getstring "\nSpecify a string: "))) (prompt "\nBye") ) ( (= "" str) (prompt "\nBYE!") ) ( (setq SS (ssget "_:L-I" '(0 . "*TEXT"))) (repeat (setq i (sslength SS)) (and (setq e (ssname SS (setq i (1- i)))) (setq o (vlax-ename->vla-object e)) (if (vlax-property-available-p o 'TextString) (vlax-put-property o 'TextString str)) ); and ); repeat ); setq SS ); cond ); defun C:SampleCode ; something So you can get an idea of what "stuff" it gets rid off.. NOTE that one must be careful with the square brackets in his .lsp code, that are usually used within ssget/wcmatch patterns or regex (inception). Cheers! Edited September 25, 2018 by Grrr 2 Quote Link to comment Share on other sites More sharing options...
CADTutor Posted September 25, 2018 Share Posted September 25, 2018 Thanks for the work guys. We have noticed a few problems with code in moving to the new forum. It didn't help that there was a bug in the code translation programme But there has also been a character set translation from Latin1 to UTF-8. As you may know, UTF-8 is the new (actually not so new) universal character set standard on the Web. So at least we are now operating with a modern, universal character set. It's difficult to predict what sort of issues this may have thrown up so it's a good policy always to check any old scripts before you use them or recommend them to novices. I've pinned this topic as it will be useful in the future. 3 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted September 27, 2018 Author Share Posted September 27, 2018 (edited) On 9/25/2018 at 10:14 PM, Grrr said: NOTE that one must be careful with the square brackets in his .lsp code, that are usually used within ssget/wcmatch patterns or regex (inception). 1+ (defun StripForumCodeTags ... [/Code] My 'listp' fix limitation brackets must be 'paired' otherwise error missing or extra parentheses. @Grrr thanks, RegEx literally fixes regardless brackets not paired. another issue is to fix missing fuzz '1e-8)' due to the new code tags do not support smiley '8)' or '8 )' ? Append '1e' with '-7)' or '-9)' Cheers Edited September 27, 2018 by hanhphuc Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 2, 2018 Share Posted October 2, 2018 (edited) [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! += Edited October 2, 2018 by Grrr 2 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 12, 2018 Author Share Posted October 12, 2018 Nice idea html idea not sure if work with unicode file? i tried another forum powered by Invision has independent color schema like: [code=lisp] your code here [/code] - avoid comment ,i.e: semi-colon ';' - missing bracket if 8 is present - display weird function name 1 Quote Link to comment Share on other sites More sharing options...
CADTutor Posted October 14, 2018 Share Posted October 14, 2018 On 12/10/2018 at 05:36, hanhphuc said: i tried another forum powered by Invision has independent color schema like: [code=lisp] your code here [/code] Interesting. Can you give me a link to that forum? I'd like to take a look and see how they've implemented that. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 15, 2018 Author Share Posted October 15, 2018 (edited) p/s: i recall there was discussions regarding LISP code tags schema at theswamp.org but i couldn't find it now Edited July 21, 2020 by hanhphuc link removed as formated code too buggy, not recommended 1 Quote Link to comment Share on other sites More sharing options...
JRL5735 Posted October 30, 2018 Share Posted October 30, 2018 Well done guys. I've been looking for something like this for a while. J. Logan ACAD 2018 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted November 1, 2018 Author Share Posted November 1, 2018 (edited) In fact my intention was simple, in order to clean up the [BBcodes] within the new code tags in this forum. Therefore, IMO optimized with CLIPBOARD without using 'getfiled' is much more convenient, isn't it? code updated - post#1 Copy text (from forum) -> run 'FORUM' (in ACAD) -> [Ctrl+V] Paste (in forum active editor) Done! Edited November 1, 2018 by hanhphuc 3 1 Quote Link to comment Share on other sites More sharing options...
Grrr Posted November 26, 2018 Share Posted November 26, 2018 (edited) Written for fun and practice - a windows form project (the .rar contains the .exe file of the program). Now you don't have to need to run ACAD for just to strip the code with LISP. EDIT: Updated the program (included a vertical bar, so one could scroll through the code) - I've forgot that they can get quite lengthy Also modified a bit the default regex pattern, so it would strip also patterns like [color=#87d6ee] or ( previous pattern was looking just for ) ForumCodeTags.rar Edited November 27, 2018 by Grrr 3 1 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted November 26, 2018 Share Posted November 26, 2018 Nice work 1 Quote Link to comment Share on other sites More sharing options...
Nikon Posted December 16, 2023 Share Posted December 16, 2023 (edited) Deleted Edited February 2 by Nikon Quote Link to comment Share on other sites More sharing options...
ymg3 Posted April 20 Share Posted April 20 (edited) To remove those pesky legacy color tags in forum code I use this regex in Notepad++ : \[.*?\] The "Find what" box should contain \[.*?\] The "Replace with" box should be kept empty. The "Wrap around" option should be selected The "Search Mode" should be set to "Regular Expression". Hitting the "Replace All" button will remove everything within Square Brackets including the brackets. Edited April 20 by ymg3 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.