Wordpress Xojo syntax highlighter?

I’ve looked at a few from links posted on the forums or found in google but they seem either years old or have broken documentation.

Has anyone got a wordpress xojo syntax highlighter recommendation that they are using at the moment that I can use on my blog without much hacking/tweaking required?

Cheers

Maybe @Thom McGrath can offer something or some help?

this is a subclass of textedit:

#tag Class
Protected Class KeyWordField
Inherits textarea
	#tag Event
		Sub TextChange()
		  Me.UpdateHighlighting(LastLineCount=LineNumAtCharPos(Me.Text.Len))
		  
		  LastLineCount=LineNumAtCharPos(Me.Text.Len)
		  
		  RaiseEvent TextChange
		  
		End Sub
	#tag EndEvent


	#tag Method, Flags = &h0
		Sub UpdateHighlighting(currentLineOnly as Boolean=false)
		  dim r as RegEx
		  dim st As StyledText=me.StyledText
		  dim theText as string=st.text.ConvertEncoding(Encodings.UTF8)
		  
		  if theText.Len=0 then Return
		  
		  dim startChar as integer=0
		  if currentLineOnly then
		    dim lineNum as integer=me.LineNumAtCharPos(me.SelStart)
		    startChar=me.CharPosAtLineNum(lineNum)
		    theText=theText.left(CharPosAtLineNum(lineNum+1))
		    st.TextColor(startChar,CharPosAtLineNum(lineNum+1)-startChar-1)=me.TextColor
		  else
		    st.TextColor(0,me.Text.Len)=me.TextColor
		  end if
		  
		  for each group as KeyWordGroup in KeyWordGroups
		    try
		      if group.Words.Ubound=-1 then Continue
		      r= new RegEx
		      r.Options.TreatTargetAsOneLine=true
		      r.Options.CaseSensitive=false
		      r.Options.MatchEmpty=true
		      r.SearchPattern="(?<!\\B)("+join(group.Words,"|")+")\\b"
		      
		      dim m As RegExMatch=r.Search(theText,startChar)
		      
		      while m<>nil
		        dim characterPosition as integer = st.text.LeftB(m.SubExpressionStartB(1)).Len
		        st.TextColor(characterPosition,m.SubExpressionString(1).Len)=group.HighLightColor
		        m=r.Search
		      wend
		      
		    Catch
		      System.DebugLog("exception occurred. match string:"+r.SearchPattern)
		    end try
		  next
		  
		  r= new RegEx
		  r.Options.TreatTargetAsOneLine=true
		  r.Options.CaseSensitive=false
		  r.Options.Greedy=false
		  r.SearchPattern="\""(\""\""|.)+\"""
		  
		  dim m As RegExMatch=r.Search(theText,startChar)
		  
		  While m<>nil
		    dim characterPosition as integer = st.text.LeftB(m.SubExpressionStartB(0)).Len
		    st.TextColor(characterPosition,m.SubExpressionString(0).Len)=QuotedTextColor
		    m=r.Search
		  wend
		  
		End Sub
	#tag EndMethod


	#tag Hook, Flags = &h0
		Event TextChange()
	#tag EndHook


	#tag Property, Flags = &h0
		KeyWordGroups() As KeyWordGroup
	#tag EndProperty

	#tag Property, Flags = &h0
		LastLineCount As Integer
	#tag EndProperty

	#tag Property, Flags = &h0
		QuotedTextColor As Color = &cff00ff
	#tag EndProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="AcceptTabs"
			Visible=true
			Group="Behavior"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Alignment"
			Visible=true
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
			EditorType="Enum"
			#tag EnumValues
				"0 - Default"
				"1 - Left"
				"2 - Center"
				"3 - Right"
			#tag EndEnumValues
		#tag EndViewProperty
		#tag ViewProperty
			Name="AutoDeactivate"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="AutomaticallyCheckSpelling"
			Visible=true
			Group="Behavior"
			InitialValue="True"
			Type="boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="BackColor"
			Visible=true
			Group="Appearance"
			InitialValue="&hFFFFFF"
			Type="Color"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Bold"
			Visible=true
			Group="Font"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Border"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="DataField"
			Visible=true
			Group="Database Binding"
			Type="String"
			EditorType="DataField"
		#tag EndViewProperty
		#tag ViewProperty
			Name="DataSource"
			Visible=true
			Group="Database Binding"
			Type="String"
			EditorType="DataSource"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Enabled"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Format"
			Visible=true
			Group="Appearance"
			Type="String"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Height"
			Visible=true
			Group="Position"
			InitialValue="100"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="HelpTag"
			Visible=true
			Group="Appearance"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="HideSelection"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			Type="Integer"
			EditorType="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Italic"
			Visible=true
			Group="Font"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LastLineCount"
			Group="Behavior"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LimitText"
			Visible=true
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LineHeight"
			Visible=true
			Group="Appearance"
			InitialValue="0"
			Type="Double"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LineSpacing"
			Visible=true
			Group="Appearance"
			InitialValue="1"
			Type="Double"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LockBottom"
			Visible=true
			Group="Position"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LockLeft"
			Visible=true
			Group="Position"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LockRight"
			Visible=true
			Group="Position"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="LockTop"
			Visible=true
			Group="Position"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Mask"
			Visible=true
			Group="Behavior"
			Type="String"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Multiline"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			Type="String"
			EditorType="String"
		#tag EndViewProperty
		#tag ViewProperty
			Name="QuotedTextColor"
			Visible=true
			Group="Appearance"
			InitialValue="&caa00aa"
			Type="Color"
		#tag EndViewProperty
		#tag ViewProperty
			Name="ReadOnly"
			Visible=true
			Group="Behavior"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="ScrollbarHorizontal"
			Visible=true
			Group="Appearance"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="ScrollbarVertical"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Styled"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			Type="String"
			EditorType="String"
		#tag EndViewProperty
		#tag ViewProperty
			Name="TabIndex"
			Visible=true
			Group="Position"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="TabPanelIndex"
			Group="Position"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="TabStop"
			Visible=true
			Group="Position"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Text"
			Visible=true
			Group="Initial State"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="TextColor"
			Visible=true
			Group="Appearance"
			InitialValue="&h000000"
			Type="Color"
		#tag EndViewProperty
		#tag ViewProperty
			Name="TextFont"
			Visible=true
			Group="Font"
			InitialValue="System"
			Type="String"
		#tag EndViewProperty
		#tag ViewProperty
			Name="TextSize"
			Visible=true
			Group="Font"
			InitialValue="0"
			Type="Single"
		#tag EndViewProperty
		#tag ViewProperty
			Name="TextUnit"
			Visible=true
			Group="Font"
			InitialValue="0"
			Type="FontUnits"
			EditorType="Enum"
			#tag EnumValues
				"0 - Default"
				"1 - Pixel"
				"2 - Point"
				"3 - Inch"
				"4 - Millimeter"
			#tag EndEnumValues
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Underline"
			Visible=true
			Group="Font"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="UseFocusRing"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Visible"
			Visible=true
			Group="Appearance"
			InitialValue="True"
			Type="Boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Width"
			Visible=true
			Group="Position"
			InitialValue="100"
			Type="Integer"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass

this is a needed class:

#tag Class
Protected Class KeyWordGroup
	#tag Property, Flags = &h0
		HighLightColor As color
	#tag EndProperty

	#tag Property, Flags = &h0
		Words() As string
	#tag EndProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="HighLightColor"
			Group="Behavior"
			InitialValue="&c000000"
			Type="color"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			Type="String"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			Type="String"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass

to use it, make a new keywordgroup in the open event of the textedit subclass, choose the colors and the words to colorize.

Dim orange As New KeyWordGroup
orange.HighlightColor=&cFF800000
orange.Words = (get array of strings with the words to color in orange)
Dim red As New KeyWordGroup
red.HighlightColor=&cFF000000
red.Words = (get array of strings with the words to color in red)
...
Me.KeyWordGroups=Array(orange,red)
Me.UpdateHighlighting

and in the textchange event :

Me.UpdateHighlighting

don’t remember where I found this snippet, may be an old RB code ?
but it works nice for my sql editor.

I don’t write Wordpress plugins, but the syntax highlighter php code is available on GitHub. Wordpress uses php, so in theory, it could be adapted without much work.

Actually that reminds me, I got a request to add some keywords to the class a while back which I totally forgot about.

Edit: Here’s the link: GitHub - thommcgrath/XojoSyntaxColorizer: PHP library for converting Xojo code into colored HTML

I’m using RBCode from Gary Pettit on BKeeney Briefs. Works fine on the most current version of WordPress https://wordpress.org/plugins/rbcode/

Thanks all! I went with Bob’s recommendation and tweaked it a little so line numbers aren’t copied. Thanks Gary if you stumble across this post.