-
Notifications
You must be signed in to change notification settings - Fork 7
/
Render.fs
927 lines (759 loc) · 30.6 KB
/
Render.fs
1
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
module Nacara.ApiGen.Render
open FSharp.Formatting.ApiDocs
open System.Text
open StringBuilder.Extensions
open Nacara.ApiGen
open Helpers
open System.Collections.Generic
open FSharp.Compiler.Symbols
open FSlugify.SlugGenerator
let slugify text =
slugify DefaultSlugGeneratorOptions text
let wrapWithClass cls text =
$"""<span class="{cls}">{text}</span>"""
let wrapInKeyword text =
wrapWithClass "keyword" text
[<RequireQualifiedAccess>]
type TextNode =
| Text of string
| Anchor of url : string * label : string
| AnchorWithId of url : string * id: string * label : string
| Space
| Dot
| Empty
| Comma
| Arrow
| GreaterThan
| Colon
| LessThan
| LeftParent
| RightParent
| Equal
| Tick
| Node of TextNode list
| Keyword of string
| OpenTag of string
| OpenTagWithClass of string * string
| NewLine
| SelfClosingTag of string
| CloseTag of string
| Property of string
| Spaces of int
static member ToHtml (node : TextNode) : string =
node.Html
member this.Html
with get () =
match this with
| Text s ->
s
| Colon ->
wrapInKeyword ":"
| Anchor (url, text) ->
$"""<a href="{url}">{text}</a>"""
| AnchorWithId (url, id, text) ->
$"""<a href="{url}" id="{id}">{text}</a>"""
| Keyword text ->
wrapInKeyword text
| Property text ->
wrapWithClass "property" text
| OpenTag tagName ->
$"""<{tagName}>"""
| OpenTagWithClass (tagName, cls) ->
$"""<{tagName} class="{cls}">"""
| CloseTag tagName ->
$"""</{tagName}>"""
| SelfClosingTag tagName ->
$"""<{tagName}/>"""
| Spaces n ->
[
for i in 0..n do
Space
]
|> Node
|> TextNode.ToHtml
| NewLine ->
"\n"
| Arrow ->
wrapInKeyword "->"
| Dot ->
wrapInKeyword "."
| Empty ->
""
| Comma ->
wrapInKeyword ","
| Space ->
" "
| GreaterThan ->
wrapInKeyword ">"
| LessThan ->
wrapInKeyword "<"
| Equal ->
wrapInKeyword "="
| Tick ->
"'"
| LeftParent ->
wrapInKeyword "("
| RightParent ->
wrapInKeyword ")"
| Node node ->
node
|> List.map (fun node ->
node.Html
)
|> String.concat ""
member this.Length
with get () =
match this with
| Text s ->
s.Length
| Anchor (_, text)
| AnchorWithId (_, _, text)
| Keyword text
| Property text ->
text.Length
| Arrow ->
2
| Node node ->
node
|> List.map (fun node ->
node.Length
)
|> List.sum
| Empty
| OpenTag _
| CloseTag _
| OpenTagWithClass _
| SelfClosingTag _
| NewLine ->
0
| Spaces count ->
count
| Comma
| Colon
| Dot
| Space
| GreaterThan
| LessThan
| LeftParent
| RightParent
| Equal
| Tick ->
1
let renderDeclaredTypes
(sb : StringBuilder)
(docLocator : DocLocator)
(linkGenerator : string -> string)
(entities : ApiDocEntity list) =
let typeDeclarations =
entities
|> List.filter (fun entity ->
entity.IsTypeDefinition
)
if not typeDeclarations.IsEmpty then
sb.WriteLine """<p class="is-size-5"><strong>Declared types</strong></p>"""
sb.NewLine ()
sb.WriteLine "<p>"
sb.WriteLine """<table class="table is-bordered docs-types">"""
sb.WriteLine "<thead>"
sb.WriteLine "<tr>"
sb.WriteLine """<th width="25%">Type</th>"""
sb.WriteLine """<th width="75%">Description</th>"""
sb.WriteLine "</tr>"
sb.WriteLine "</thead>"
sb.WriteLine "<tbody>"
typeDeclarations
|> List.iter (fun typ ->
let url = linkGenerator typ.UrlBaseName
sb.WriteLine "<tr>"
sb.WriteLine $"""<td><a href="{url}">{typ.Name}</a></td>"""
match docLocator.TryFindComment typ.Symbol.XmlDocSig with
| Some comment ->
sb.WriteLine $"""<td>{CommentFormatter.format comment}</td>"""
| None ->
sb.WriteLine $"""<td></td>"""
sb.WriteLine "</tr>"
)
sb.WriteLine "</tbody>"
sb.WriteLine "</table>"
sb.WriteLine "</p>"
let inline html (s: string) = s
/// <summary>
/// Generate a list of generic parameters
/// <example>
/// 'T, 'T2, 'MyType
/// </example>
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
let renderGenericParameters (parameters : IList<FSharpGenericParameter>) : TextNode =
[
for index in 0 .. parameters.Count - 1 do
let param = parameters.[index]
if index <> 0 then
TextNode.Comma
TextNode.Space
TextNode.Tick
TextNode.Text param.DisplayName
]
|> TextNode.Node
let rec renderParameterType (isTopLevel : bool) (typ : FSharpType) : TextNode =
// This correspond to a generic paramter like: 'T
if typ.IsGenericParameter then
TextNode.Node [
TextNode.Tick
TextNode.Text typ.GenericParameter.DisplayName
]
// Not a generic type we can display it as it is
// Example:
// - string
// - int
// - MyObject
else if typ.GenericArguments.Count = 0 then
TextNode.Text typ.TypeDefinition.DisplayName
// This is a generic type we need more logic
else
// This is a function, we need to generate something like:
// - 'T -> string
// - 'T -> 'T option
if typ.IsFunctionType then
let separator =
TextNode.Node [
TextNode.Space
TextNode.Arrow
TextNode.Space
]
let result =
[
for index in 0 .. typ.GenericArguments.Count - 1 do
let arg = typ.GenericArguments.[index]
// Add the separator if this is not the first argument
if index <> 0 then
separator
// This correspond to a generic paramter like: 'T
if arg.IsGenericParameter then
TextNode.Tick
TextNode.Text arg.GenericParameter.DisplayName
// This is a type definition like: 'T option or Choice<'T1, 'T2>
else if arg.HasTypeDefinition then
// For some generic types definition we don't add the generic arguments
if arg.TypeDefinition.DisplayName = "exn"
|| arg.TypeDefinition.DisplayName = "unit" then
TextNode.Text arg.TypeDefinition.DisplayName
else
// This is the name of the type definition
// In Choice<'T1, 'T2> this correspond to Choice
TextNode.Text arg.TypeDefinition.DisplayName
TextNode.LessThan
// Render the generic parameters list in the form of 'T1, 'T2
renderGenericParameters arg.TypeDefinition.GenericParameters
TextNode.GreaterThan
else if arg.IsFunctionType then
let res =
[
for index in 0 .. arg.GenericArguments.Count - 1 do
let arg = arg.GenericArguments.[index]
if index <> 0 then
TextNode.Space
TextNode.Arrow
TextNode.Space
renderParameterType false arg
]
// Try to detect curried case
// Like in:
// let create (f: ('T -> unit) -> (exn -> unit) -> unit): JS.Promise<'T> = jsNative
// FCS gives back an equivalent of :
// let create (f: ('T -> unit) -> ((exn -> unit) -> unit)): JS.Promise<'T> = jsNative
// So we try to detect it to avoid the extract Parents
match res with
| (TextNode.Node (TextNode.LeftParent :: _ ) :: _ ) ->
TextNode.Node res
| _ ->
TextNode.Node [
TextNode.LeftParent
yield! res
TextNode.RightParent
]
else
let i = 0
TextNode.Text "Unkown syntax please open an issue"
]
// If this is a top level function we don't neeed to add the parenthesis
TextNode.Node [
if not isTopLevel then
TextNode.LeftParent
TextNode.Node result
if not isTopLevel then
TextNode.RightParent
]
else
let separator =
TextNode.Node [
TextNode.Space
TextNode.Comma
]
let result =
[
for index in 0 .. typ.GenericArguments.Count - 1 do
let arg = typ.GenericArguments.[index]
// Add the separator if this is not the first argument
if index <> 0 then
separator
if arg.IsGenericParameter then
TextNode.Tick
TextNode.Text arg.GenericParameter.DisplayName
else
let url =
arg.TypeDefinition.FullName
|> String.toLower
|> String.replace "." "-"
|> String.append ".html"
let subType =
renderParameterType false arg
TextNode.Anchor (url, arg.TypeDefinition.DisplayName)
TextNode.LessThan
subType
TextNode.GreaterThan
]
TextNode.Node result
type ParamTypesInformation =
{
Infos : (string * TextNode) list
MaxNameLength : int
MaxReturnTypeLength : int
}
static member Empty =
{
Infos = []
MaxNameLength = 0
MaxReturnTypeLength = 0
}
let rec extractParamTypesInformation
(state : ParamTypesInformation)
(paramTypes : list<Choice<FSharpParameter,FSharpField> * string * ApiDocHtml>) =
match paramTypes with
| paramType::tail ->
match paramType with
| Choice1Of2 fsharpParameter, name, _apiDoc ->
let returnType =
renderParameterType true fsharpParameter.Type
let newState =
{ state with
Infos = state.Infos @ [ name, returnType ]
MaxNameLength = System.Math.Max (state.MaxNameLength, name.Length)
MaxReturnTypeLength = System.Math.Max (state.MaxReturnTypeLength, returnType.Length)
}
extractParamTypesInformation newState tail
| Choice2Of2 _fsharpField, _name, _apiDoc ->
let newState =
{ state with
Infos = state.Infos @ [ "TODO: extractParamTypesInformation -> fsharpField", TextNode.Empty ]
}
extractParamTypesInformation newState tail
| [] ->
state
let renderValueOrFunction
(sb : StringBuilder)
(docLocator : DocLocator)
(linkGenerator : string -> string)
(entities : ApiDocMember list) =
if not entities.IsEmpty then
sb.WriteLine """<p class="is-size-5"><strong>Values and functions</strong></p>"""
sb.NewLine ()
sb.WriteLine "<hr/>"
for entity in entities do
let (ApiDocMemberDetails(usageHtml, paramTypes, returnType, modifiers, typars, baseType, location, compiledName)) =
entity.Details
let returnHtml =
// Todo: Parse the return type information from
// let x = entity.Symbol :?> FSharpMemberOrFunctionOrValue
// x.FullType <-- Here we have access to all the type including the argument for the function that we should ignore... (making the processing complex)
// For now, we are just using returnType.HtmlText to have something ready as parsing from
// FSharpMemberOrFunctionOrValue seems to be quite complex
match returnType with
| Some returnType ->
// Remove the starting <code> and ending </code>
returnType.HtmlText.[6 .. returnType.HtmlText.Length - 8]
// Adapt the text to have basic syntax highlighting
|> fun text ->
text.Replace("<", wrapInKeyword "<")
|> fun text ->
text.Replace(">", wrapInKeyword ">")
|> fun text ->
text.Replace(",", wrapInKeyword ",")
| None ->
"unit"
let initial =
{ ParamTypesInformation.Empty with
MaxNameLength = entity.Name.Length
}
let paramTypesInfo =
extractParamTypesInformation
initial
paramTypes
if paramTypesInfo.Infos.Length = 0 then
// This is a value
sb.WriteLine """<div class="api-code">"""
sb.WriteLine $"""<div><span class="keyword">val</span> %s{entity.Name} <span class="keyword">:</span>"""
sb.Write returnHtml
sb.Write "</div>"
sb.Write "</div>"
else
let slug =
slugify entity.Name
// This is a function/member
[
TextNode.OpenTagWithClass ("div", "api-code")
TextNode.NewLine
TextNode.OpenTag "div"
TextNode.Keyword "val"
TextNode.Space
TextNode.AnchorWithId ($"#{slug}", slug, entity.Name)
TextNode.Space
TextNode.Colon
TextNode.CloseTag "div"
]
|> TextNode.Node
|> TextNode.ToHtml
|> sb.Write
// sb.WriteLine """<div class="api-code">"""
// sb.WriteLine $"""<div><span class="keyword">val</span> %s{entity.Name} <span class="keyword">:</span></div>"""
for index in 0 .. paramTypesInfo.Infos.Length - 1 do
let (name, returnType) = paramTypesInfo.Infos.[index]
sb.Write "<div>"
sb.Space 4 // Equivalent to 'val '
sb.Write name
sb.Space (paramTypesInfo.MaxNameLength - name.Length + 1) // Complete with space to align the ':'
sb.Write """<span class="keyword">:</span>"""
sb.Space 1
sb.Write returnType.Html
sb.Space (paramTypesInfo.MaxReturnTypeLength - returnType.Length + 1) // Complete with space to align the '->'
// Don't add the arrow after the last parameter
if index <> paramTypesInfo.Infos.Length - 1 then
sb.Write """<span class="keyword">-></span>"""
sb.Write "</div>"
sb.NewLine ()
sb.Write "<div>"
sb.Space (4 + paramTypesInfo.MaxNameLength + 1)
sb.Write """<span class="keyword">-></span>"""
sb.Space 1
sb.Write returnHtml
sb.Write "</div>"
sb.WriteLine "</div>"
sb.NewLine ()
match docLocator.TryFindComment entity with
| Some comment ->
sb.WriteLine (CommentFormatter.formatSummaryOnly comment)
if paramTypesInfo.Infos.Length <> 0 then
sb.WriteLine """<p><strong>Parameters</strong></p>"""
for (name, returnType) in paramTypesInfo.Infos do
match CommentFormatter.tryFormatParam name comment with
| Some paramDoc ->
[
TextNode.OpenTagWithClass ("div", "doc-parameter")
TextNode.NewLine
TextNode.OpenTagWithClass ("div", "api-code")
TextNode.OpenTagWithClass ("span", "property")
TextNode.Text name
TextNode.CloseTag "span"
TextNode.Space
TextNode.Keyword ":"
TextNode.Space
TextNode.Text returnType.Html
TextNode.CloseTag "div"
TextNode.NewLine
TextNode.Text paramDoc
TextNode.CloseTag "div"
]
|> TextNode.Node
|> TextNode.ToHtml
|> sb.Write
| None ->
[
TextNode.OpenTagWithClass ("div", "doc-parameter")
TextNode.NewLine
TextNode.OpenTagWithClass ("div", "api-code")
TextNode.OpenTagWithClass ("span", "property")
TextNode.Text name
TextNode.CloseTag "span"
TextNode.Space
TextNode.Keyword ":"
TextNode.Space
TextNode.Text returnType.Html
TextNode.CloseTag "div"
TextNode.CloseTag "div"
]
|> TextNode.Node
|> TextNode.ToHtml
|> sb.Write
sb.NewLine ()
match CommentFormatter.tryFormatReturnsOnly comment with
| Some returnsDoc ->
[
TextNode.OpenTag "p"
TextNode.OpenTag "strong"
TextNode.Text "Returns"
TextNode.CloseTag "strong"
TextNode.CloseTag "p"
TextNode.OpenTag "p"
TextNode.Text returnsDoc
TextNode.CloseTag "p"
]
|> TextNode.Node
|> TextNode.ToHtml
|> sb.WriteLine
| None ->
()
| None ->
()
sb.WriteLine "<hr/>"
let renderDeclaredModules
(sb : StringBuilder)
(docLocator : DocLocator)
(linkGenerator : string -> string)
(entities : ApiDocEntity list) =
let moduleDeclarations =
entities
|> List.filter (fun ns ->
ns.Symbol.IsFSharpModule
)
if not moduleDeclarations.IsEmpty then
sb.WriteLine """<p class="is-size-5"><strong>Declared modules</strong></p>"""
sb.NewLine ()
sb.WriteLine "<p>"
sb.WriteLine """<table class="table is-bordered docs-modules">"""
sb.WriteLine "<thead>"
sb.WriteLine "<tr>"
sb.WriteLine """<th width="25%">Module</th>"""
sb.WriteLine """<th width="75%">Description</th>"""
sb.WriteLine "</tr>"
sb.WriteLine "</thead>"
sb.WriteLine "<tbody>"
moduleDeclarations
|> List.iter (fun md ->
let url = linkGenerator md.UrlBaseName
sb.WriteLine "<tr>"
sb.WriteLine $"""<td><a href="{url}">{md.Name}</a></td>"""
match docLocator.TryFindComment md.Symbol.XmlDocSig with
| Some comment ->
sb.WriteLine $"""<td>{CommentFormatter.formatSummaryOnly comment}</td>"""
| None ->
sb.WriteLine $"""<td></td>"""
sb.WriteLine "</tr>"
)
sb.WriteLine "</tbody>"
sb.WriteLine "</table>"
sb.WriteLine "</p>"
let renderNamespace
(sb : StringBuilder)
(docLocator : DocLocator)
(linkGenerator : string -> string)
(apiDoc : ApiDocNamespace) =
sb.WriteLine $"""<h2 class="title is-3">{apiDoc.Name}</h2>"""
renderDeclaredModules
sb
docLocator
linkGenerator
apiDoc.Entities
let renderIndex
(sb : StringBuilder)
(docLocator : DocLocator)
(linkGenerator : string -> string)
(namespaces: list<ApiDocNamespace>) =
let globalNamespace, standardNamespaces =
namespaces
|> List.partition (fun ns ->
ns.Name = "global"
)
if not standardNamespaces.IsEmpty then
sb.WriteLine """<p class="is-size-5"><strong>Declared namespaces</strong></p>"""
sb.NewLine ()
sb.WriteLine "<p>"
sb.WriteLine """<table class="table is-bordered docs-modules">"""
sb.WriteLine "<thead>"
sb.WriteLine "<tr>"
sb.WriteLine """<th width="25%">Namespace</th>"""
sb.WriteLine """<th width="75%">Description</th>"""
sb.WriteLine "</tr>"
sb.WriteLine "</thead>"
sb.WriteLine "<tbody>"
for ns in standardNamespaces do
// TODO: Support <namespacedoc> tag as supported by F# formatting
// Namespace cannot have documentatin so this is a trick to support it
let url = linkGenerator ns.UrlBaseName
sb.WriteLine "<tr>"
sb.WriteLine $"""<td><a href="{url}">{ns.Name}</a></td>"""
sb.WriteLine $"""<td></td>"""
sb.WriteLine "</tr>"
sb.WriteLine "</tbody>"
sb.WriteLine "</table>"
sb.WriteLine "</p>"
if not globalNamespace.IsEmpty then
renderDeclaredModules
sb
docLocator
linkGenerator
globalNamespace.Head.Entities
let renderRecordType
(sb : StringBuilder)
(docLocator : DocLocator)
(info : ApiDocEntityInfo) =
let entity = info.Entity
sb.WriteLine $"""<div class="api-code">"""
sb.WriteLine $"""<div><span class="keyword">type</span> <span class="type">%s{entity.Name}</span> <span class="keyword">=</span></div>"""
sb.Indent 1
sb.WriteLine """<span class="keyword">{</span>"""
for field in entity.RecordFields do
match field.ReturnInfo.ReturnType with
| Some returnType ->
let escapedReturnType =
// Remove the starting <code> and ending </code>
returnType.HtmlText.[6 .. returnType.HtmlText.Length - 8]
sb.Write """<div class="record-field">"""
sb.Indent 2
sb.Write $"""<a class="record-field-name" href="#{slugify field.Name}" >{field.Name}</a> <span class="keyword">:</span> <span class="record-field-type">{escapedReturnType}</span>"""
sb.WriteLine "</div>"
| None ->
()
sb.Write "<div>"
sb.Indent 1
sb.WriteLine """<span class="keyword">}</span>"""
sb.WriteLine "</div>"
if entity.InstanceMembers.Length <> 0 then
sb.WriteLine "<br />"
for m in entity.InstanceMembers do
match m.Symbol with
| :? FSharpMemberOrFunctionOrValue as symbol ->
sb.WriteLine "<div>"
let nodes =
TextNode.Node
[
TextNode.Space
TextNode.Space
TextNode.Space
TextNode.Space
TextNode.Keyword "member"
TextNode.Space
TextNode.Text "this"
TextNode.Dot
TextNode.Property symbol.DisplayName
match symbol.HasGetterMethod, symbol.HasSetterMethod with
| true, true ->
TextNode.Space
TextNode.Keyword "with"
TextNode.Space
TextNode.Text "get"
TextNode.Comma
TextNode.Space
TextNode.Text "set"
| true, false ->
TextNode.Space
TextNode.Keyword "with"
TextNode.Space
TextNode.Text "get"
| false, true ->
TextNode.Space
TextNode.Keyword "with"
TextNode.Space
TextNode.Text "set"
| false, false ->
()
]
sb.Write (nodes.Html)
sb.WriteLine "</div>"
| _ ->
()
sb.WriteLine "</div>"
match docLocator.TryFindComment entity.Symbol.XmlDocSig with
| Some docComment ->
sb.WriteLine """<div class="docs-summary">"""
sb.WriteLine "<p><strong>Description</strong></p>"
sb.WriteLine "<p>"
sb.WriteLine (CommentFormatter.format docComment)
sb.WriteLine "</p>"
sb.WriteLine "</div>"
| None ->
()
sb.WriteLine "<p><strong>Properties</strong></p>"
sb.NewLine ()
sb.WriteLine """<dl class="docs-parameters">"""
sb.NewLine()
for field in entity.RecordFields do
match field.ReturnInfo.ReturnType with
| Some returnType ->
let escapedReturnType =
// Remove the starting <code> and ending </code>
returnType.HtmlText.[6 .. returnType.HtmlText.Length - 8]
let slug = slugify field.Name
sb.WriteLine """<dt class="api-code">"""
sb.Write $"""<a id={slug} href="#{slug}" class="property">{field.Name}</a> <span class="keyword">:</span> <span class="return-type">{escapedReturnType}</span>"""
sb.WriteLine "</dt>"
sb.WriteLine """<dd>"""
match docLocator.TryFindComment field with
| Some docComment ->
sb.WriteLine (CommentFormatter.format docComment)
| None ->
()
sb.WriteLine "</dd>"
| None ->
()
sb.WriteLine "</dl>"
let renderUnionType
(sb : StringBuilder)
(docLocator : DocLocator)
(info : ApiDocEntityInfo) =
let entity = info.Entity
sb.WriteLine $"""<div class="api-code">"""
sb.WriteLine $"""<div><span class="keyword">type</span> <span class="type">%s{entity.Name}</span> <span class="keyword">=</span></div>"""
for case in entity.UnionCases do
sb.Write """<div class="union-case">"""
sb.Indent 1
sb.Write """<span class="keyword">|</span>"""
sb.Space 1
sb.Write $"""<a href="#{slugify case.Name}" class="union-case-property">{case.Name}</a>"""
sb.Space 1
if case.Parameters.Length <> 0 then
sb.Write """<span class="keyword">of</span>"""
sb.Space 1
for parameter in case.Parameters do
match parameter.ParameterSymbol with
| Choice1Of2 fsharpParameter ->
()
| Choice2Of2 fsharpField ->
// Don't use generated names, we try detect it manually because
// fsharpField.IsNameGenerated doesn't seems to do what it should...
if not (fsharpField.Name.StartsWith("Item")) then
sb.Write fsharpField.Name
sb.Space 1
sb.Write """<span class="keyword">:</span>"""
sb.Space 1
let returnType =
renderParameterType true fsharpField.FieldType
sb.Write returnType.Html
sb.WriteLine "</div>"
sb.WriteLine "</div>"
match docLocator.TryFindComment entity.Symbol.XmlDocSig with
| Some docComment ->
sb.WriteLine """<div class="docs-summary">"""
sb.WriteLine "<p><strong>Description</strong></p>"
sb.WriteLine "<p>"
sb.WriteLine (CommentFormatter.format docComment)
sb.WriteLine "</p>"
sb.WriteLine "</div>"
| None ->
()
sb.WriteLine "<p><strong>Cases</strong></p>"
sb.NewLine ()
sb.WriteLine """<dl class="docs-parameters">"""
sb.NewLine()
for case in entity.UnionCases do
sb.WriteLine """<dt>"""
sb.Write $"""<code id="#{slugify case.Name}">{case.Name}</code>"""
sb.WriteLine "</dt>"
sb.WriteLine """<dd>"""
match docLocator.TryFindComment case with
| Some docComment ->
sb.WriteLine (CommentFormatter.format docComment)
| None ->
()
sb.WriteLine "</dd>"
sb.WriteLine "</dl>"