PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
x:Light [BETA] - a BBCode Highlighter for Xaml/XML-VBForums
Results 1 to 5 of 5

Thread: x:Light [BETA] - a BBCode Highlighter for Xaml/XML

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,381

    x:Light [BETA] - a BBCode Highlighter for Xaml/XML

    Introduction:
    x:Light is a highlighting engine that takes source code and applies BB-Code to it so that vBulletin based forums can mark up this code with colour. Currently Xaml is only available. This engine only requires the 2.0 framework to run. I also opted to create a custom data type to make the engine cleaner to upgrade as I have plans to remove hard coded regex queries from the engine.

    Note:
    This engine is still very much in BETA. If you have any suggestions or find any bugs please reply to this thread. Thanks!

    Download:
    From My SkyDrive

    Code:

    BBEngine:
    VB Code:
    1. Imports xLightEngine.CustomTypes
    2. Imports System.Text.RegularExpressions
    3.  
    4. Public Class BBEngine
    5.  
    6.     Private mRegexQuery As RegexItem
    7.     Private Property RegexQuery() As RegexItem
    8.         Get
    9.             Return mRegexQuery
    10.         End Get
    11.         Set(ByVal value As RegexItem)
    12.             mRegexQuery = value
    13.         End Set
    14.     End Property
    15.  
    16.     Public Function Run(ByVal Text As String) As String
    17.  
    18.         Const SourceType As String = "XAML"
    19.         Return HighlightCode(Text, SourceType)
    20.  
    21.     End Function
    22.  
    23.     Private Function HighlightCode(ByVal Source As String, ByVal SourceType As String) As String
    24.         Dim QueryList As New List(Of RegexItem)
    25.         Dim Evaluate As New System.Text.RegularExpressions.MatchEvaluator(AddressOf ElementReplacement)
    26.         QueryList.AddRange(GetRegexList(SourceType))
    27.  
    28.         For Each item In QueryList
    29.             Me.RegexQuery = item
    30.             Source = Regex.Replace(Source, item.Query, Evaluate)
    31.         Next
    32.  
    33.         Return "[code]" & Source & "[/code]"
    34.  
    35.     End Function
    36.  
    37.     Private Function GetRegexList(ByVal SourceType As String) As List(Of RegexItem)
    38.  
    39.         Dim RegexList As New List(Of RegexItem)
    40.         If SourceType = "XAML" Then
    41.             'This is not how the final version of this statement will work, these values will be pulled
    42.             'from an XML file and not hard coded into the engine.
    43.             Dim GetTags As New RegexItem("</|<|>|/>", "[color=blue]", "[/color]")
    44.             Dim GetPropVal As New RegexItem("=""[\w#,. =:/-]+""|=""{|\w+.[\w:-]+(?=\}"")}""", "[color=blue]", "[/color]")
    45.             Dim GetPropName As New RegexItem("\b[\w:.]+(?=\="")", "[color=red]", "[/color]")
    46.             Dim GetObjName As New RegexItem("(?<=</|<|{)[\w:]+|\w+(?=>)", "[color=darkred]", "[/color]")
    47.             RegexList.Add(GetObjName)
    48.             RegexList.Add(GetTags)
    49.             RegexList.Add(GetPropName)
    50.             RegexList.Add(GetPropVal)
    51.  
    52.         End If
    53.  
    54.         Return RegexList
    55.     End Function
    56.  
    57.     Public Function ElementReplacement(ByVal m As Text.RegularExpressions.Match) As String
    58.         Return Me.RegexQuery.TagFront & m.Value & RegexQuery.TagBehind
    59.     End Function
    60.  
    61. End Class

    RegexItem:

    VB Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3. Namespace CustomTypes
    4.     Public Class RegexItem
    5.  
    6.         Private mQuery As Regex
    7.         ''' <summary>
    8.         ''' Gets or Sets a RegEx query as a string object
    9.         ''' </summary>
    10.         Public Property Query() As String
    11.             Get
    12.                 Return mQuery.ToString
    13.             End Get
    14.             Set(ByVal value As String)
    15.                 mQuery = New Regex(value)
    16.             End Set
    17.         End Property
    18.  
    19.         Private mTagFront As String
    20.         ''' <summary>
    21.         ''' Gets or Sets the BB-Code tag that preceeds a text element
    22.         ''' </summary>
    23.         Public Property TagFront() As String
    24.             Get
    25.                 Return mTagFront
    26.             End Get
    27.             Set(ByVal value As String)
    28.                 mTagFront = value
    29.             End Set
    30.         End Property
    31.  
    32.         Private mTagBehind As String
    33.         ''' <summary>
    34.         ''' Gets or Sets the BB-Code tag that preceeds a text element
    35.         ''' </summary>
    36.         Public Property TagBehind()
    37.             Get
    38.                 Return mTagBehind
    39.             End Get
    40.             Set(ByVal value)
    41.                 mTagBehind = value
    42.             End Set
    43.         End Property
    44.  
    45.         Public Sub New()
    46.  
    47.         End Sub
    48.  
    49.         Public Sub New(ByVal GetRegex As String, ByVal GetTagFront As String, ByVal GetTagBehind As String)
    50.             Me.Query = GetRegex
    51.             Me.TagFront = GetTagFront
    52.             Me.TagBehind = GetTagBehind
    53.         End Sub
    54.  
    55.     End Class
    56. End Namespace
    Last edited by DeanMc; Feb 17th, 2009 at 06:36 PM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,381

    Re: x:Light [BETA] - a BBCode Highlighter for Xaml/XML

    Thanks to Penegate for finding a missing /. That will teach me not to mess with my source code once it has been cleaned and tested!

  3. #3

    Re: x:Light [BETA] - a BBCode Highlighter for Xaml/XML

    The DLL file is missing from the download.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,381

    Re: x:Light [BETA] - a BBCode Highlighter for Xaml/XML

    Oops, sorry about that. I have got another copy of it but its in C# and of a slightly different make up. Your more than welcome to the code if you wish.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,381

    Re: x:Light [BETA] - a BBCode Highlighter for Xaml/XML

    In fact it would be a cleaner version with an XML datastore so you could technically add to it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width