Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 04:53:33
|
How about to beautify sql codes on sqlteam forums? Like this my attempt.Internally all stays intact. Except of a piece of VBS code added into topic.asp, right before Response.Write(): else'##########################################################ii=0rc=Reply_Contentdo while trueii=instr(ii+1,rc,"[co.de]",1)jj=instr(ii+1,rc,"[/co.de]",1)if (ii=0) or (jj=0) thenexit doend ifrz=mid(rc,ii+6,jj-ii-6)rz="<font face=""Courier New"" size=3><div style=""background-color:#FFFFEE""><pre>" & rz & "</pre></div></font>"left_blue_tag="<font color=blue>"right_blue_tag="</font>"for each kw_blue in array( _"select","insert","delete","update","create","table","from","where","union","order","by","group","distinct", _"top","inner","having","drop","truncate","desc","asc","case","when","then","else","end")rz=replace(rz,kw_blue,left_blue_tag & kw_blue & right_blue_tag,1,-1,1)nextrc=left(rc,ii-1) & rz & right(rc,len(rc)-jj-6)loopReply_Content=rc'########################################################## Response.Write formatStr(Reply_Content) end if Response.Write "</span id=""msg""></font></td>" & vbNewLine & _ " </tr>" & vbNewLine ======================Let me hug & kiss you... |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-07-10 : 05:03:24
|
uuuu... nice. have you thought about using css?and damn it stoad... go out and hug & kiss people Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 05:34:34
|
>have you thought about using css?No! PS How can css help in the matter?======================Let me hug & kiss you... |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-07-10 : 05:37:00
|
well you check for keywords and add a css class to each keyword you want to beutify.Then you can change the colors just with changing css and not the code.Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 05:37:37
|
Now as I added <pre></pre> tags my sample page looks even better.======================Let me hug & kiss you... |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 05:41:05
|
>Then you can change the colors...Why? I'm not going to change colors of keywords! Smth frivolic in your hasty presumption.======================Let me hug & kiss you... |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-07-10 : 06:47:06
|
whatever you you say mr. Freaky Yak Linguist Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 12:48:55
|
Not so easy thing, cybermaster, as it may seem at first view. Consider e.g. case: exec('select * from t')And here "select" should be highlighted in red!======================Let me hug & kiss you... |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-07-10 : 18:34:19
|
Very neat indeed!The keyword list pretty well reflects standard sql.However, I motion for the replacement of "top" with "join" ! |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 19:05:51
|
"join" goes in Grey not in Blue! See the nearest QA! And my latest version (the link above).======================Let me hug & kiss you... |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-07-10 : 19:14:43
|
|
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 20:13:26
|
Aha!PSI've also never noticed the difference... till yesterday. ======================Let me hug & kiss you... |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-07-10 : 21:10:24
|
Actually, I must admit, that looks very good! Your site takes forever to load (for me at least) but the code formatting looks very nice ... it might not be a bad idea to implement something like this ... it has my vote!Though, as you mention, this kind of thing often isn't easy to write ... my thought: leave the CODE tags as is, but allow for a new tag such as [TSQL]..[/TSQL] which will use your formatting! Actually, the more I think of that, the more I think it would be cool.....anyone else? Other thoughts? pros/cons ??Thanks for the good idea and the nice code, Stoad !- Jeff |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 21:25:38
|
Ah... Jeff... thank you! Glad you liked it!The ru site is just a free trash... for storing static pages of teens.(to be continued and see my sig :))======================Let me hug & kiss you... |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-10 : 22:58:44
|
>but allow for a new tag such as [TSQL]..[/TSQL] which...ah... Jeff, I'm afraid that our Crack Dealer In Chief has not enough spare time forexamining Snitz's implementation with aiming to add his own new feature to it.My idea is (technically):1.graz adds into the forums root folder file inc_beautifier.asp.2.in file topic.asp he adds one more inclusion:%><!--#INCLUDE FILE="inc_sha256.asp"--><!--#INCLUDE FILE="inc_header.asp" --><!--#INCLUDE FILE="inc_func_secure.asp" --><!--#INCLUDE FILE="inc_func_member.asp" --><!--#INCLUDE FILE="inc_subscription.asp" --><!--#INCLUDE FILE="inc_moderation.asp" --><!--#INCLUDE FILE="inc_beautifier.asp"-->3.I post a new topic with ID=***** (in Yak Corral), only for testing the beautifier and this topic will be the only place where the beautifying will work;graz finds this part of code in topic.asp and write into it (see the middle of it :)):strDefaultFontFace & """ size=""" & strDefaultFontSize & """ color=""" & strForumFontColor & """><span class=""spnMessageText"" id=""msg"">" if Request.QueryString("SearchTerms") <> "" then Response.Write SearchHiLite(formatStr(Reply_Content)) else'''''''''''''''' if Topic_ID=***** then Reply_Content=beautifier(Reply_Content) end if'''''''''''''''' Response.Write formatStr(Reply_Content) end if Response.Write "</span id=""msg""></font></td>" & vbNewLine & _ " </tr>" & vbNewLine if CanShowSignature = 1 and Reply_Sig = 1 and Reply_MemberSig <> "" then 4.And none of us lose anything!5.This is my version of inc_beautifier.asp:<%Private Function blue(rc)dim kw,kws_blue,kws_magentakws_blue=array("select","insert","delete","update","create","table","from","where","union","order","by","group","distinct","top", _"inner","having","drop","truncate","desc","asc","case","when","then","else","end","while","begin","if","exec","tran","rollback","set", _"on ","on" & chr(13) & chr(10))kws_magenta=array("patindex","stuff","charindex")for each kw in kws_bluerc=replace(rc,kw,"<font color=blue>" & kw & "</font>",1,-1,1)nextfor each kw in kws_magentarc=replace(rc,kw,"<font color=magenta>" & kw & "</font>",1,-1,1)nextblue=rcEnd FunctionPrivate Function red(rc)dim i,j,jj,rzj=0jj=0rz=""do while truei=instr(j+1,rc,"'",1)j=instr(i+1,rc,"'",1)if (i=0) or (j=0) thenexit doend ifrz=rz & blue(mid(rc,jj+1,i-jj-1)) & "<font color=red>" & mid(rc,i,j-i+1) & "</font>"jj=jloopred=rz & blue(right(rc,len(rc)-jj))End FunctionPublic Function beautifier(rc)dim i,j,rzj=0do while truei=instr(j+1,rc,"[co.de]",1) ''' < sorry for the dot between "co" and "de"j=instr(i+1,rc,"[/co.de]",1) ''' < and here...if (i=0) or (j=0) thenexit doend ifrz=mid(rc,i+6,j-i-6)rz=red(rz)rz="<font face=""Courier New"" size=3><div style=""background-color:#FFFFEE""><pre>" & rz & _"</pre></div></font>"rc=left(rc,i-1) & rz & right(rc,len(rc)-j-6)loopbeautifier=rcEnd Function%> ======================Let me hug & kiss you... |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-07-11 : 02:12:36
|
simply beautiful i like the idea, makes scanning a very long code easier--------------------keeping it simple... |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-11 : 02:58:24
|
In my turn I can swear: jen is the best woman in the Eastern hemisphere.No kidding (anymore)!======================Let me hug & kiss you... |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-11 : 14:36:13
|
Pfff... the implementation is not the point of the matter (at the time)!Plus it's a big difference when you write smth from the scratch and whenyou're going to tune (as gently as possible) someone's else code.======================Let me hug & kiss you... |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2006-07-11 : 14:47:32
|
Be I graz I'd add a column into forum_reply table - for storing beautified repliesand hook a trigger on the table (for insert/update) for formatting replies and puttingtheir formatted versions into the new column. ======================Let me hug & kiss you... |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2006-07-11 : 15:11:11
|
Unfortunately Graz really, really doesn't want to modify the forums.===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
|
|
Next Page
|
|
|
|
|