سورس کد ماجول Markdown:

Imports System.Runtime.CompilerServices
Module Markdown
Private BoldMatch0 As New Regex("\u002A{2}(.*?)\u002A{2}") ' **
Private BoldMatch1 As New Regex("[\u005f]{2}(.*?)[\u005f]{2}") ' __
Private ItalicMatch0 As New Regex("\u002A(.*?)\u002A") '*
Private ItalicMatch1 As New Regex("[\u005f](.*?)[\u005f]") ' _
Private ImageMatch As New Regex("[\u0021][\u005B](.*?)[\u005D][\(](.*?)[\)]") ' ![Text](imagePath)
Private ContentLinkMatch As New Regex("[\u002A](\w+|)[\u005B](.*?)[\u005D][\(](.*?)[\)]") ' * [Text](#imagePath)


Private LinkMatch As New Regex("[\u005B](.*?)[\u005D][\(](.*?)[\)]") ' [Text](url)
Private Header1Match As New Regex("[\#](.*?)\s")
Private Header2Match As New Regex("[\#]{2}(.*?)\s")
Private Header3Match As New Regex("[\#]{3}(.*?)\s")
Private Header4Match As New Regex("[\#]{4}(.*?)\s")
Private Header5Match As New Regex("[\#]{5}(.*?)\s")
Private Header6Match As New Regex("[\#]{6}(.*?)\s")
Sub MarkdownReplacement(ByRef Expression As String)
Expression = Expression.
Replace("'#'", "{u0023}").
Replace("'*'", "{u002A}").
Replace("'_'", "{u005f}") '.
'Replace("&lt;", "<").
''Replace("&gt;", ">")
End Sub
Sub MarkdownResetReplacement(ByRef Expression As String)
Expression = Expression.
Replace("{u0023}", "#").
Replace("{u002A}", "*").
Replace("{u005f}", "_")


End Sub
<Extension()>
Public Function HTMLMarkdown(ByVal Expression As String) As String
Dim expr As String = Expression
MarkdownReplacement(expr)
Dim value As String = ""
Dim Start As Integer = 0
Dim LinkText As String = "", LinkUrl As String, spl As String()
redoh6: With Header6Match.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(6)
value = String.Format("<h6>{0}</h6>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redoh6
End With
Next
End With
Start = 0
redoh5: With Header5Match.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(5)
value = String.Format("<h5>{0}</h5>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redoh5
End With
Next
End With
Start = 0
redoh4: With Header4Match.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(4)
value = String.Format("<h4>{0}</h4>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redoh4
End With
Next
End With
Start = 0
redoh3: With Header3Match.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(3)
value = String.Format("<h3>{0}</h3>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redoh3
End With
Next
End With
Start = 0
redoh2: With Header2Match.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(2)
value = String.Format("<h2>{0}</h2>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redoh2
End With
Next
End With
Start = 0
redoh1: With Header1Match.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(1)
value = String.Format("<h1>{0}</h1>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redoh1
End With
Next
End With
Start = 0
redo0: With BoldMatch0.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(2, .Value.Length - 4)
value = String.Format("<b>{0}</b>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redo0
End With
Next
End With
Start = 0
redo000: With BoldMatch1.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(2, .Value.Length - 4)
value = String.Format("<b>{0}</b>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redo000
End With
Next
End With
Start = 0
redo01: With ItalicMatch0.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(1, .Value.Length - 2)
value = String.Format("<i>{0}</i>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redo01
End With
Next
End With
Start = 0
redo02: With ItalicMatch1.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(1, .Value.Length - 2)
value = String.Format("<i>{0}</i>", value)
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redo02
End With
Next
End With
Start = 0


Dim width As String = ""
Dim height As String = ""
Dim align As String = ""
redo03: With ImageMatch.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(2, .Value.Length - 3)
value = value.Replace("&nbsp;", Space(1))
spl = Split(value, "]")
LinkText = spl(0)
LinkUrl = spl(1).Substring(1)
align = "" : width = "" : height = ""
If LinkText.Contains(";") = True Then
spl = LinkText.Split(";")
LinkText = spl(0)
If spl.Length >= 3 Then
align = spl(2)
End If
spl = spl(1).Split(":")
width = spl(0)
height = spl(1)
End If
value = ImageBox(LinkText, LinkUrl,
If(width.Length = 0, 300, width),
If(height.Length = 0, 200, height),
align)
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redo03
End With
Next
End With
Start = 0
redo04: With LinkMatch.Matches(expr, Start)
For i = 0 To .Count - 1
With .Item(i)
If .Success = False Then Continue For
value = .Value.Substring(1, .Value.Length - 2)
spl = Split(value, "]")
LinkText = spl(0)
LinkUrl = spl(1).Substring(1)
value = String.Format("<a href={2}{0}{2} >{1}</a>", LinkUrl, LinkText, Chr(34))
value = value.Replace("&nbsp;", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redo04
End With
Next
End With
MarkdownResetReplacement(expr)
Return expr


End Function
Private Function ImageBox(title As String, src As String,
width As String, height As String,
align As String)
Dim Expr As String = String.Format("<div align='{4}' class='imageBox'><div class='polaroid' >" +
"<img src='{1}' alt='{0}' width='{2}' height='{3}' >" +
"<div class='container'><label>{0}</label></div></div></div>", title, src, width, height, align)
Return Expr
End Function
End Module