ROSTAM2
پنج شنبه 12 مهر 1403, 21:38 عصر
سلام
من سعی دارم قوانین Markdown رو برای نوشتن مقاله در نرم افزار WindowsForms استفاده کنم....
156148
که متن همین صفحه این هست:
**Hello All!**
[vblover programmer AparatChannel](https://aparat.com/)

#Hello world....
##Hello world....
###Hello world....
####Hello world....
#####Hello world....
######Hello world....
Im good
```vb
Dim A as unteger
```
اولین و مهمترین سوالی که من دارم اینه که آیا ابزاری برای پیاده سازی Markdown در HTML بصورت رایگان وجود داره یا نه؟!
ROSTAM2
پنج شنبه 12 مهر 1403, 22:32 عصر
سورس کلاس Syntax که متن مقاله رو از Markdown به HTML تبدیل می کنه:
Public Class Syntax
Protected Friend Shared ContentList As New List(Of String)
Private Shared CodeMatch As New Regex("[\`]{3}(\w+|)\s(.*?)\n+[\`]{3}")
Protected Friend Shared Function Markdown2HTML(ByVal Expression As String) As String
Dim Output As String = Expression.Replace("<", "<").Replace(">", ">")
Dim Start As Integer = 0, Value, Language, Code As String
ContentList.Clear()
redoCode: With CodeMatch.Matches(Output, Start)
For I = 0 To .Count - 1
With .Item(I)
If .Success = False Then Continue For
If I = 0 Then
Value = Output.Substring(Start, .Index - Start)
If .Index > 0 And Value.Length > 0 Then
' As MarkdownText....
ContentList.Add(Value.Replace(Space(1), " ").HTMLMarkdown)
End If
End If
' As Code....
Dim Index As Integer = InStr(3, .Value, vbLf, CompareMethod.Binary)
If Index > 0 Then
Language = .Value.Substring(3, (Index - 3) - 1)
Code = .Value.Substring((3 + Language.Length) + 1, .Length - (6 + Language.Length + 1))
Select Case Language.ToLower
Case "vb", "vbnet", "vb.net", "visualbasic"
VisualBasic.Highlight(Code)
Case Else
End Select
Dim Expr As String = String.Format("<pre><code>{1}</code></pre>",
vbLf,
Code)
VisualBasic.HighlightComments(Expr)
SharedHighlight.HighLightStrings(Expr)
Expr = Expr.Replace(Space(1), " ")
Start = (.Index + .Length) + 1
ContentList.Add(Expr)
Else
Start = (.Index + .Length) + 1
End If
If Start >= Output.Length Then Exit For
GoTo redoCode
End With
Next
End With
If Start < Output.Length - 1 Then
'Remainded Markdown string...
ContentList.Add(Output.Substring(Start).Replace(Sp ace(1), " ").HTMLMarkdown)
End If
Return NewLinesReplacement(Join(ContentList.ToArray, ""))
End Function
Shared Function NewLinesReplacement(input As String) As String
Return input.Replace(vbNewLine, "<br>").
Replace(vbCrLf, "<br>").
Replace(vbCr, "<br>").
Replace(vbLf, "<br>")
End Function
End Class
برای دیدن سورس کد متود VisualBasic.Highlight(Code) به لینک ضمیمه شده مراجعه کنید:
سوال: ایجاد یک لیست از کلمات کلیدی و تشخیص آن در متن - برگه 4 (barnamenevis.org) (https://barnamenevis.org/showthread.php?571657-%D8%A7%DB%8C%D8%AC%D8%A7%D8%AF-%DB%8C%DA%A9-%D9%84%DB%8C%D8%B3%D8%AA-%D8%A7%D8%B2-%DA%A9%D9%84%D9%85%D8%A7%D8%AA-%DA%A9%D9%84%DB%8C%D8%AF%DB%8C-%D9%88-%D8%AA%D8%B4%D8%AE%DB%8C%D8%B5-%D8%A2%D9%86-%D8%AF%D8%B1-%D9%85%D8%AA%D9%86/page4)
ROSTAM2
پنج شنبه 12 مهر 1403, 22:39 عصر
سورس کد ماجول 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][\(](.*?)[\)]") ' 
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("<", "<").
''Replace(">", ">")
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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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(" ", 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
ROSTAM2
جمعه 13 مهر 1403, 00:53 صبح
Unordered HTML List
و
Ordered HTML List
اضافه کردم ....
Private OListMatch As New Regex("[\u005B](ULIST|ulist|UList|olist|OList|OLIST)(.*?)[\u005D](\n+|\s|)([\(](.*?)[\)])")
Dim ListInfo As String = "", ListItems As String = ""
Dim ListKind As String = ""
Dim ItemType As String = ""
Dim ItemStart As String = ""
redolist: With OListMatch.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, "]")
ListInfo = spl(0)
ListItems = spl(1).Trim.Substring(1, spl(1).Trim.Length - 1)
If ListInfo.Contains(";") Then
spl = ListInfo.Split(";")
ListKind = spl(0).ToLower
Select Case spl.Length
Case 2 : ItemType = spl(1)
Case 3 : ItemType = spl(1) : ItemStart = spl(2)
End Select
Else
ListKind = ListInfo.ToLower
End If
If ListKind = "olist" Then
value = String.Format("<ol type={2}{0}{2} start={2}{1}{2} >", ItemType, ItemStart, Chr(34))
spl = ListItems.Split(",")
For Each s As String In spl
value += String.Format("<li>{0}</li><br>", s.Trim, vbCr)
Next
value += "</ol>"
ElseIf ListKind = "ulist" Then
value = String.Format("<ul style={1}list-style-type:{0};{1} >", ItemType, Chr(34))
spl = ListItems.Split(",")
For Each s As String In spl
value += String.Format("<li>{0}</li><br>", s.Trim, vbCr)
Next
value += "</ul>"
End If
value = value.Replace(" ", Space(1))
expr = expr.Remove(.Index, .Length)
expr = expr.Insert(.Index, value)
Start = (.Index + value.Length)
GoTo redolist
End With
Next
End With
Start = 0
نوشتن متنش به این صورته:
[ULIST;DISC](Item1,Item2)
[olist;A;2](Item3, Item4)
156149
ROSTAM2
جمعه 13 مهر 1403, 01:00 صبح
نمونه متن نرم افزارو:
#Chapter1 ONE ''#''
vb_lover'_'programmer'_'1@gmail.com
* JHDSJF HSDJK* '*' *KSDHF JSDHF* JHJHHJHJ
*Hello*
_hello_ dd
<!-- Hello -->
```vb
Dim MyInt as integer = 10
```

تصویرش:
156150
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.