Jump to content

How to change the way code tags # work?


Simon Lloyd

Recommended Posts

Hi all,

I'm new here, i have very little php or html experience (i have owned a vbulletin forum since August) but i am learning fast and can perform whatever i am instructed to.

 

What i would like to do is change keywords found in the # code tags box, so instead of this:

 

Sub change()
for each r in range
if r = 0 then
msgbox "hello"
if r = 1 then
msgbox "goodbye"
end if
end if
next
end sub

i would like it to look like this:

 

Sub change()
For Each r In Range
>>>If r = 0 Then
>>>>>Msgbox "hello"
>>>>>>If r = 1 Then
>>>>>>'Show a message to the user
>>>>>>>>Msgbox "goodbye"
>>>>>>End If
>>>End If
Next
End Sub

Of course the above would be without the chevrons, i had to use them to indent the code.

 

Here are my lists:

$bodykeywords=array("Application","AddressOf","Alias","And","An y","As","Binary","Boolean","ByRef",

"Byte","ByVal","Call","Case","CBool","CByte","CCur ","CDate","CDbl","CInt","CLng","Close","Const" ,

"CSng","CStr","Currency","CVar","CVErr","Date","De bug","Declare","DefBool","DefByte","DefCur",

"DefDate","DefDbl","DefInt","DefLng","DefObj","Def Sng","DefStr","DefVar","Dim","Do","Double"

,"Each","Else","End","Enum","Eqv","Erase","Error", "Event","Exit","For","Friend","Function","Get" ,

"Global","GoSub","GoTo","If","Imp","Implements","I n","Input","Integer","Is","LBound","Len","Let",

"Lib","Like","Line","Lock","Long","Loop","LSet","M od","Msgbox","Name","New","Next","Not","Nothing" ,

"Null","Object","On","On Error Resume Next","Open","Option Base 1","Option Compare Binary",

"Option Compare Database","Option Compare Text","Option Explicit","Option Private Module","Optional","Or","Output","ParamArray","Pre serve","Print","Private","Property","Public","Put" ,

"RaiseEvent","Random","Read","ReDim","Resume","Ret urn","RSet","Seek","Select","Set","Single","Spc",

"Static","Step","Stop","String","Sub","Tab","Then" ,"To","Type","UBound","Unlock","Variant","Wend","W hile"

"With","WithEvents","Write","Xor");

 

$indentkeywords = array("If","Then","Do","For Each","For","Else" "ElseIf","Do","Select Case","Case","With");

 

$unindentkeywords=array("End","Next","Else","ElseIf","End If","End Select","End Sub","Wend","Loop","Case Else","Case","End With");

 

Delimiters = .(),-+=|\/{}[]:;"'< >

 

I'm assuming we need to use RegEx for the above but i dont know much about it.

 

All the above keywords when found inside the code tags should be blue, any text found on any line after ' should be green.

 

The indent keywords should indent like my second example only returning to the begining of a line if an unindent keyword is found or only indenting another line when another indent keyword is found.

 

If any keywords are found between quotes " then that text should remain black.

 

I have installed GeSHi (and Advanced Syntax Highlighting from vB.org) which highlights the code if i use a custom tag (i have created one and coded it in the Editor_on template) but it doesn't indent or replace the words for the words in the list (proper case).

 

Is this possible with php, Ajax, as a pluggin or CSS?

 

Any suggestions/help would be great!

 

Kind regards,

Simon

http://www.thecodecage.com

Link to comment
Share on other sites

It's certainly possible to make a syntax highlighter using PHP and Regular Expressions. But if I'm honest your not going to have much luck if you don't know much about Regular Expressions, it will be a complex task. For example you would need alot of lookahead/behind assertions to check that your keywords aren't actually part of a string. In theory without that issue finding and replacing the keywords with the keyword and some tags shouldn't be that difficult. Nor will detecting things such as strings.

Link to comment
Share on other sites

It's certainly possible to make a syntax highlighter using PHP and Regular Expressions. But if I'm honest your not going to have much luck if you don't know much about Regular Expressions, it will be a complex task. For example you would need alot of lookahead/behind assertions to check that your keywords aren't actually part of a string. In theory without that issue finding and replacing the keywords with the keyword and some tags shouldn't be that difficult. Nor will detecting things such as strings.

 

Geshi already does the syntax highlighting. I think the op wants to indent the code to some standard. This IMO would be allot more difficult, the only online editor I've seen come close to this is bespin.

 

This board for instance formats code how users enter it. If users don't bother indenting, most people simply don't bother reading.

Link to comment
Share on other sites

Hi guys thanks for the replies, in VBA the keywords shouldn't be present in a string so no need to search strings, the keywords however may appear between quotes " and should remain black and as typed.

 

The modification i have on my board at the moment strips all the line breaks so although it looks ok on screen if a user copies and pastes it, it becomes a very long one liner that makes no sense at all.

 

You are correct in assuming i want the indenting and outdenting when the relevant keywords are found, i also need to have any keyword found replaced for the exact keyword in my list, so i guess there's an issue checking the case of the text, i also need the keywords to be BLUE and any text found after ' to be green but doesn't need indenting...etc

 

Its a convention for VBA to indent it for easy reading and comprehension, there is an indenter out there for use with VB6 and VBA but they can only be used in the applications themselves or a windows based machine but my server isn't.

 

Any futher help is much appreciated.

 

Regards,

SImon

Link to comment
Share on other sites

Did you look at the link I provided to bespin?

I didn't see it as a link as the colouration here kind of obscures it, or at leasst it does on my monitor, i'm just checking it out now, thanks, will post back!

I can't even register for Bespin via IE as its not supported (pop up message at bespin as IE does not support Canvas), so i guess that means that my users will not benefit from it if using IE to browse or post to my site, so i guess i need another way :(
Link to comment
Share on other sites

Did you look at the link I provided to bespin?

I didn't see it as a link as the colouration here kind of obscures it, or at leasst it does on my monitor, i'm just checking it out now, thanks, will post back!

I can't even register for Bespin via IE as its not supported (pop up message at bespin as IE does not support Canvas), so i guess that means that my users will not benefit from it if using IE to browse or post to my site, so i guess i need another way :(

 

I'm not saying you need to use all of bespin, but there might be parts of it you can hack at. This really isn't something that is going to be easily done.

 

Realistically, your users should be posting well formatted code in the first place. What happens here if people post unformatted code is they usually just get ignored.

Link to comment
Share on other sites

Did you look at the link I provided to bespin?

I didn't see it as a link as the colouration here kind of obscures it, or at leasst it does on my monitor, i'm just checking it out now, thanks, will post back!

I can't even register for Bespin via IE as its not supported (pop up message at bespin as IE does not support Canvas), so i guess that means that my users will not benefit from it if using IE to browse or post to my site, so i guess i need another way :(

 

I'm not saying you need to use all of bespin, but there might be parts of it you can hack at. This really isn't something that is going to be easily done.

 

Realistically, your users should be posting well formatted code in the first place. What happens here if people post unformatted code is they usually just get ignored.

Thanks again for the replies, i'm not a coder by any stretch of the imagination so hacking would be more like decimating :)

 

I understand what you say about unformatted code, but we accept code posted from both newbies and old hands, not everyone was taught the same way, many have never been taught and are feeling their way, so, one of the great ways to teach them is for them to always see the code "beautified", i have to say thats how i started and now indent my code as i should.

 

Again, thanks for the reply.

 

Regards,

Simon

Link to comment
Share on other sites

Thanks again for the replies, i'm not a coder by any stretch of the imagination so hacking would be more like decimating

 

Well, to be honest, Ive not heard of anything that does this out of the box. Bespin is probably about a close to it as I've seen on the web, so if your not a programmer you'll likely be out of luck unless you fancy paying someone. Its really not as simple a task as you make out (but I understand now knowing your not a programmer).

Link to comment
Share on other sites

Well, to be honest, Ive not heard of anything that does this out of the box. Bespin is probably about a close to it as I've seen on the web, so if your not a programmer you'll likely be out of luck unless you fancy paying someone. Its really not as simple a task as you make out (but I understand now knowing your not a programmer).

There's nothing out of the box, it is a custom thing and i don't suppose i will get it done for $50.

 

Anyway, thanks for your help and advice :)

 

regards,

Simon

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.