Skip to content

Commit

Permalink
Format files
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 26, 2022
1 parent c7997ff commit 688cc5c
Show file tree
Hide file tree
Showing 30 changed files with 955 additions and 1,078 deletions.
4 changes: 2 additions & 2 deletions docs/apidocs.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ index: 5
(*** condition: fsx ***)
#if FSX
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // FSX
#endif
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // IPYNB
#endif

(*** hide ***)
let root = "C:\\"
Expand Down
4 changes: 2 additions & 2 deletions docs/codeformat.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ index: 1
(*** condition: fsx ***)
#if FSX
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // FSX
#endif
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // IPYNB
#endif

(**
[![Binder](img/badge-binder.svg)](https://mybinder.org/v2/gh/fsprojects/fsharp.formatting/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
Expand Down
4 changes: 2 additions & 2 deletions docs/content.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ index: 3
(*** condition: fsx ***)
#if FSX
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // FSX
#endif
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // IPYNB
#endif


(**
Expand Down
6 changes: 3 additions & 3 deletions docs/evaluation.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ index: 6
(*** condition: fsx ***)
#if FSX
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // FSX
#endif
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // IPYNB
#endif

(**
[![Binder](img/badge-binder.svg)](https://mybinder.org/v2/gh/fsprojects/fsharp.formatting/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
Expand Down Expand Up @@ -153,7 +153,7 @@ This can be done by calling `cref:M:FSharp.Formatting.Literate.Evaluation.FsiEva
// Create evaluator & register simple formatter for lists
let fsiEvaluator = FsiEvaluator()

fsiEvaluator.RegisterTransformation (fun (o, ty, _executionCount) ->
fsiEvaluator.RegisterTransformation(fun (o, ty, _executionCount) ->
// If the type of value is an F# list, format it nicely
if ty.IsGenericType
&& ty.GetGenericTypeDefinition() = typedefof<list<_>> then
Expand Down
4 changes: 2 additions & 2 deletions docs/literate.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ index: 3
(*** condition: fsx ***)
#if FSX
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // FSX
#endif
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // IPYNB
#endif


(**
Expand Down
4 changes: 2 additions & 2 deletions docs/markdown.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ index: 2
(*** condition: fsx ***)
#if FSX
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // FSX
#endif
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: FSharp.Formatting,{{fsdocs-package-version}}"
#endif // IPYNB
#endif


(**
Expand Down
933 changes: 436 additions & 497 deletions src/FSharp.Formatting.ApiDocs/GenerateHtml.fs

Large diffs are not rendered by default.

197 changes: 103 additions & 94 deletions src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ type MarkdownRender(model: ApiDocModel) =
yield!
m.Parameters
|> List.collect (fun parameter ->
[ p [ strong [ !!parameter.ParameterNameText ]
!! ": "
embedSafe parameter.ParameterType ]
[ p
[ strong [ !!parameter.ParameterNameText ]
!! ": "
embedSafe parameter.ParameterType ]
match parameter.ParameterDocs with
| None -> ()
| Some d -> p [ !!(sprintf ": %s" (htmlStringSafe d)) ]
Expand All @@ -72,33 +73,32 @@ type MarkdownRender(model: ApiDocModel) =

match m.ExtendedType with
| None -> ()
| Some (_, extendedTypeHtml) ->
p [ !! "Extended Type: "
embedSafe extendedTypeHtml
br ]
| Some (_, extendedTypeHtml) -> p [ !! "Extended Type: "; embedSafe extendedTypeHtml; br ]

match m.ReturnInfo.ReturnType with
| None -> ()
| Some (_, returnTypeHtml) ->
p [ !!(if m.Kind <> ApiDocMemberKind.RecordField then
"Returns: "
else
"Field type: ")
embedSafe returnTypeHtml
br
match m.ReturnInfo.ReturnDocs with
| None -> ()
| Some r ->
embedSafe r
br ]
p
[ !!(if m.Kind <> ApiDocMemberKind.RecordField then
"Returns: "
else
"Field type: ")
embedSafe returnTypeHtml
br
match m.ReturnInfo.ReturnDocs with
| None -> ()
| Some r ->
embedSafe r
br ]

if not m.Comment.Exceptions.IsEmpty then
for (nm, url, html) in m.Comment.Exceptions do
p [ match url with
| None -> ()
| Some href -> link [ !!nm ] href
embed html
br ]
p
[ match url with
| None -> ()
| Some href -> link [ !!nm ] href
embed html
br ]

for e in m.Comment.Notes do
p [ !! "Note" ]
Expand All @@ -116,32 +116,34 @@ type MarkdownRender(model: ApiDocModel) =
let hasModules = entities |> List.exists (fun e -> not e.IsTypeDefinition)

table
[ [ p [ !!(if hasTypes && hasModules then
"Type/Module"
elif hasTypes then
"Type"
else
"Modules") ]
[ [ p
[ !!(if hasTypes && hasModules then
"Type/Module"
elif hasTypes then
"Type"
else
"Modules") ]
p [ !! "Description" ]
p [ !! "Source" ] ] ]
[ AlignLeft; AlignLeft; AlignCenter ]
[ for e in entities do
[ [ p [ let nm = e.Name

let multi = (entities |> List.filter (fun e -> e.Name = nm) |> List.length) > 1

let nmWithSiffix =
if multi then
(if e.IsTypeDefinition then
nm + " (Type)"
else
nm + " (Module)")
else
nm

link
[ !!nmWithSiffix ]
(e.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ] ]
[ [ p
[ let nm = e.Name

let multi = (entities |> List.filter (fun e -> e.Name = nm) |> List.length) > 1

let nmWithSiffix =
if multi then
(if e.IsTypeDefinition then
nm + " (Type)"
else
nm + " (Module)")
else
nm

link
[ !!nmWithSiffix ]
(e.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ] ]
[ p [ embedSafe e.Comment.Summary ] ]
[ p [ yield! (sourceLink e.SourceLocation) ] ] ] ] ]

Expand All @@ -158,29 +160,30 @@ type MarkdownRender(model: ApiDocModel) =
| Some m when m.RequiresQualifiedAccess -> m.Name + "." + entity.Name
| _ -> entity.Name

[ ``##`` [ !!(usageName
+ (if entity.IsTypeDefinition then
" Type"
else
" Module")) ]
p [ !! "Namespace: "
link
[ !!info.Namespace.Name ]
(info.Namespace.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ]
[ ``##``
[ !!(usageName
+ (if entity.IsTypeDefinition then
" Type"
else
" Module")) ]
p
[ !! "Namespace: "
link
[ !!info.Namespace.Name ]
(info.Namespace.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ]
p [ !!("Assembly: " + entity.Assembly.Name + ".dll") ]

match info.ParentModule with
| None -> ()
| Some parentModule ->
p [ !! "Parent Module: "
link
[ !!parentModule.Name ]
(parentModule.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ]
p
[ !! "Parent Module: "
link
[ !!parentModule.Name ]
(parentModule.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ]

match entity.AbbreviatedType with
| Some (_, abbreviatedTyp) ->
p [ !! "Abbreviation For: "
embed abbreviatedTyp ]
| Some (_, abbreviatedTyp) -> p [ !! "Abbreviation For: "; embed abbreviatedTyp ]
| None -> ()

match entity.BaseType with
Expand All @@ -190,18 +193,17 @@ type MarkdownRender(model: ApiDocModel) =
match entity.AllInterfaces with
| [] -> ()
| l ->
p [ !! "All Interfaces: "
for (i, (_, interfaceTyHtml)) in Seq.indexed l do
if i <> 0 then !! ", "
embed interfaceTyHtml ]
p
[ !! "All Interfaces: "
for (i, (_, interfaceTyHtml)) in Seq.indexed l do
if i <> 0 then !! ", "
embed interfaceTyHtml ]

if entity.Symbol.IsValueType then
p [ !!("Kind: Struct") ]

match entity.DelegateSignature with
| Some (_, delegateSigHtml) ->
p [ !!("Delegate Signature: ")
embed delegateSigHtml ]
| Some (_, delegateSigHtml) -> p [ !!("Delegate Signature: "); embed delegateSigHtml ]
| None -> ()

if entity.Symbol.IsProvided then
Expand Down Expand Up @@ -236,21 +238,23 @@ type MarkdownRender(model: ApiDocModel) =
// If there is more than 1 category in the type, generate TOC
``###`` [ !! "Table of contents" ]

ul [ for (index, _, name) in byCategory do
[ p [ link [ !!(sprintf "#section%d" index) ] (name) ] ] ]
ul
[ for (index, _, name) in byCategory do
[ p [ link [ !!(sprintf "#section%d" index) ] (name) ] ] ]

//<!-- Render nested types and modules, if there are any -->

let nestedEntities = entity.NestedEntities |> List.filter (fun e -> not e.IsObsolete)

if (nestedEntities.Length > 0) then

``###`` [ !!(if nestedEntities |> List.forall (fun e -> not e.IsTypeDefinition) then
"Nested modules"
elif nestedEntities |> List.forall (fun e -> e.IsTypeDefinition) then
"Types"
else
"Types and nested modules") ]
``###``
[ !!(if nestedEntities |> List.forall (fun e -> not e.IsTypeDefinition) then
"Nested modules"
elif nestedEntities |> List.forall (fun e -> e.IsTypeDefinition) then
"Types"
else
"Types and nested modules") ]

yield! renderEntities nestedEntities

Expand Down Expand Up @@ -299,8 +303,9 @@ type MarkdownRender(model: ApiDocModel) =
if (allByCategory.Length > 1) then
``###`` [ !! "Contents" ]

ul [ for category in allByCategory do
[ p [ link [ !!category.CategoryName ] ("#category-" + category.CategoryIndex) ] ] ]
ul
[ for category in allByCategory do
[ p [ link [ !!category.CategoryName ] ("#category-" + category.CategoryIndex) ] ] ]

for category in allByCategory do
if (allByCategory.Length > 1) then
Expand All @@ -314,10 +319,11 @@ type MarkdownRender(model: ApiDocModel) =
//
// For non-FSharp.Core we only show one link "API Reference" in the nav menu
if otherDocs && nav && model.Collection.CollectionName <> "FSharp.Core" then
p [ !! "API Reference"
link
[ !! "All Namespaces" ]
(model.IndexFileUrl(root, collectionName, qualify, model.FileExtensions.InUrl)) ]
p
[ !! "API Reference"
link
[ !! "All Namespaces" ]
(model.IndexFileUrl(root, collectionName, qualify, model.FileExtensions.InUrl)) ]
else

let categorise = Categorise.model model
Expand All @@ -330,26 +336,29 @@ type MarkdownRender(model: ApiDocModel) =
for allByCategory, ns in categorise do

// Generate the entry for the namespace
p [ link [ !!ns.Name ] (ns.Url(root, collectionName, qualify, model.FileExtensions.InUrl))
p
[ link [ !!ns.Name ] (ns.Url(root, collectionName, qualify, model.FileExtensions.InUrl))

// If not in the navigation list then generate the summary text as well
if not nav then
!! " - "
// If not in the navigation list then generate the summary text as well
if not nav then
!! " - "

match ns.NamespaceDocs with
| Some nsdocs -> embed nsdocs.Summary
| None -> () ]
match ns.NamespaceDocs with
| Some nsdocs -> embed nsdocs.Summary
| None -> () ]

// In the navigation bar generate the expanded list of entities
// for the active namespace
if nav then
match nsOpt with
| Some ns2 when ns.Name = ns2.Name ->
ul [ for category in allByCategory do
for e in category.CategoryEntites do
[ p [ link
[ !!e.Name ]
(e.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ] ] ]
ul
[ for category in allByCategory do
for e in category.CategoryEntites do
[ p
[ link
[ !!e.Name ]
(e.Url(root, collectionName, qualify, model.FileExtensions.InUrl)) ] ] ]
| _ -> () ]

let listOfNamespaces otherDocs nav (nsOpt: ApiDocNamespace option) =
Expand Down
Loading

0 comments on commit 688cc5c

Please sign in to comment.