1 |
#Region "Microsoft.VisualBasic::ef5a01dc3cd38ded81009fdd36c73551, Microsoft.VisualBasic.Core\ApplicationServices\VBDev\XmlDoc\Serialization\APIExtensions.vb"
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
#End Region
|
44 |
|
45 |
Imports System.Runtime.CompilerServices
|
46 |
Imports System.Text
|
47 |
Imports System.Text.RegularExpressions
|
48 |
Imports Microsoft.VisualBasic.CommandLine.Reflection
|
49 |
Imports Microsoft.VisualBasic.Scripting.MetaData
|
50 |
Imports Microsoft.VisualBasic.Text.HtmlParser
|
51 |
|
52 |
Namespace ApplicationServices.Development.XmlDoc.Serialization
|
53 |
|
54 |
<Package("Assembly.Doc.API")>
|
55 |
Public Module APIExtensions
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
> https://stackoverflow.com/questions/793210/xml-documentation-for-a-namespace
|
61 |
|
62 |
这个名字的对象类型主要是被用来标记命名空间的注释信息使用的
|
63 |
</summary>
|
64 |
Public Const NamespaceDoc$ = NameOf(NamespaceDoc)
|
65 |
|
66 |
Public ReadOnly Property Types As New Dictionary(Of Char, memberTypes) From {
|
67 |
_
|
68 |
{"T"c, memberTypes.Type},
|
69 |
{"F"c, memberTypes.Filed},
|
70 |
{"M"c, memberTypes.Method},
|
71 |
{"P"c, memberTypes.Property},
|
72 |
{"E"c, memberTypes.Event}
|
73 |
}
|
74 |
|
75 |
<ExportAPI("Load")>
|
76 |
Public Function Load(path As String) As Doc
|
77 |
Try
|
78 |
Return path.LoadXml(Of Doc)(preprocess:=AddressOf TrimAssemblyDoc)
|
79 |
Catch ex As Exception
|
80 |
Call ex.PrintException
|
81 |
Throw ex
|
82 |
End Try
|
83 |
End Function
|
84 |
|
85 |
Const cref As String = "<see(also)? cref=""[^""]+?""/>"
|
86 |
Const cref2 As String = "<see(also)? cref=""[^""]+?"">\s*</see(also)?>"
|
87 |
Const crefFull As String = "<see(also)? cref=""[^""]+?"">.+?</see(also)?>"
|
88 |
|
89 |
Const paramRef As String = "<(type)?paramref name=""[^""]+""/>"
|
90 |
Const paramRef2 As String = "<(type)?paramref name=""[^""]+"">\s*</(type)?paramref>"
|
91 |
Const paramRefFull As String = "<(type)?paramref name=""[^""]+"">.+?</(type)?paramref>"
|
92 |
|
93 |
Const code As String = "<code>.+?</code>"
|
94 |
Const example As String = "<example>.*?</example>"
|
95 |
|
96 |
<Extension>
|
97 |
Public Function TrimAssemblyDoc(doc As String) As String
|
98 |
Dim sb As New StringBuilder(doc)
|
99 |
Dim ms As String() = Regex.Matches(doc, cref, RegexICSng).ToArray
|
100 |
|
101 |
For Each m As String In ms
|
102 |
Call sb.Replace(m, "@" & m.__trans)
|
103 |
Next
|
104 |
|
105 |
ms = Regex.Matches(sb.ToString, cref2, RegexICSng).ToArray
|
106 |
|
107 |
For Each m As String In ms
|
108 |
Call sb.Replace(m, "@" & m.__trans)
|
109 |
Next
|
110 |
|
111 |
ms = Regex.Matches(sb.ToString, crefFull, RegexICSng).ToArray
|
112 |
|
113 |
For Each m As String In ms
|
114 |
Call sb.Replace(m, "@" & m.__trans)
|
115 |
Next
|
116 |
|
117 |
doc = sb.__boldParam
|
118 |
|
119 |
Return doc
|
120 |
End Function
|
121 |
|
122 |
<Extension> Private Function __boldParam(sb As StringBuilder) As String
|
123 |
Dim ms As String() = Regex.Matches(sb.ToString, paramRef, RegexICSng).ToArray
|
124 |
|
125 |
For Each m As String In ms
|
126 |
Dim bold As String = m.__trans
|
127 |
bold = Mid(bold, 2, bold.Length - 2)
|
128 |
bold = $"**{bold}**"
|
129 |
Call sb.Replace(m, bold)
|
130 |
Next
|
131 |
|
132 |
ms = Regex.Matches(sb.ToString, paramRef2, RegexICSng).ToArray
|
133 |
|
134 |
For Each m As String In ms
|
135 |
Dim bold As String = m.__trans
|
136 |
bold = Mid(bold, 2, bold.Length - 2)
|
137 |
bold = $"**{bold}**"
|
138 |
Call sb.Replace(m, bold)
|
139 |
Next
|
140 |
|
141 |
ms = Regex.Matches(sb.ToString, paramRefFull, RegexOptions.IgnoreCase Or RegexOptions.Singleline).ToArray
|
142 |
|
143 |
For Each m As String In ms
|
144 |
Dim bold As String = m.__trans
|
145 |
Dim name As String = Regex.Match(bold, "``[^`]*``").Value
|
146 |
|
147 |
' bold = $"**{bold}**"
|
148 |
Call sb.Replace(m, bold)
|
149 |
Next
|
150 |
|
151 |
ms = Regex.Matches(sb.ToString, code, RegexOptions.IgnoreCase Or RegexOptions.Singleline).ToArray
|
152 |
|
153 |
For Each m As String In ms
|
154 |
Call sb.Replace(m, "'" & m.GetValue & "'")
|
155 |
Next
|
156 |
|
157 |
ms = Regex.Matches(sb.ToString, example, RegexOptions.IgnoreCase Or RegexOptions.Singleline).ToArray
|
158 |
|
159 |
For Each m As String In ms
|
160 |
Call sb.Replace(m, "==" & m.GetValue & "==")
|
161 |
Next
|
162 |
|
163 |
Return sb.ToString
|
164 |
End Function
|
165 |
|
166 |
|
167 |
这里会将双引号替换成为markdown里面的inline code形式
|
168 |
</summary>
|
169 |
<param name="cref"></param>
|
170 |
<returns></returns>
|
171 |
<Extension> Private Function __trans(cref As String) As String
|
172 |
Dim m As String = Regex.Match(cref, "="".+?""").Value
|
173 |
Dim alt As String = cref.GetValue
|
174 |
|
175 |
m = Mid(m, 2)
|
176 |
|
177 |
If String.IsNullOrEmpty(alt) Then
|
178 |
Else
|
179 |
m &= $"[{alt}]"
|
180 |
End If
|
181 |
|
182 |
m = m.Replace("""", "``")
|
183 |
|
184 |
Return m
|
185 |
End Function
|
186 |
End Module
|
187 |
End Namespace
|