Skip to content

Commit

Permalink
Improve github and signature links (#681)
Browse files Browse the repository at this point in the history
* copy sig tooltips

* github tooltip

* update icons

* icon size

* fix bug

* attempt fix
  • Loading branch information
gbaydin authored Jun 17, 2021
1 parent 5789b8d commit 11aa8d0
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 41 deletions.
4 changes: 3 additions & 1 deletion docs/content/fsdocs-default.css
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ body {
.fsdocs-source-link img {
border-style: none;
margin-left: 10px;
width: auto;
height: 1.4em;
}

.fsdocs-source-link .hover {
Expand Down Expand Up @@ -409,7 +411,7 @@ body {
}

/*--------------------------------------------------------------------------
/*--------------------------------------------------------------------------*/

#fsdocs-content table.pre pre {
Expand Down
Binary file removed docs/content/img/copy-blue.png
Binary file not shown.
Binary file removed docs/content/img/copy-md-blue.png
Binary file not shown.
Binary file added docs/content/img/copy-md-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/content/img/copy-md.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/content/img/copy-xml-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/content/img/copy-xml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/content/img/copy.png
Binary file not shown.
Binary file removed docs/content/img/github-blue.png
Binary file not shown.
Binary file added docs/content/img/github-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/content/img/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 39 additions & 40 deletions src/FSharp.Formatting.ApiDocs/GenerateHtml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ type HtmlRender(model: ApiDocModel) =
[ match url with
| None -> ()
| Some href ->
a [Href href; Class"fsdocs-source-link" ] [
a [Href href; Class"fsdocs-source-link"; HtmlProperties.Title "Source on GitHub" ] [
img [Src (sprintf "%scontent/img/github.png" root); Class "normal"]
img [Src (sprintf "%scontent/img/github-blue.png" root); Class "hover"]
img [Src (sprintf "%scontent/img/github-hover.png" root); Class "hover"]
] ]

let removeParen (memberName:string) =
let firstParen = memberName.IndexOf("(")
if firstParen > 0 then memberName.Substring(0, firstParen) else memberName

// Copy XML sig for use in `cref` XML
// Copy XML sig for use in `cref` XML
let copyXmlSigIcon xmlDocSig =
div [ Class"fsdocs-source-link"; OnClick (sprintf "Clipboard_CopyTo('<see cref=\\\'%s\\\'/>')" xmlDocSig) ] [
img [Src (sprintf "%scontent/img/copy.png" root); Class "normal"]
img [Src (sprintf "%scontent/img/copy-blue.png" root); Class "hover"]
]
div [ Class"fsdocs-source-link"; HtmlProperties.Title "Copy signature (XML)"; OnClick (sprintf "Clipboard_CopyTo('<see cref=\\\'%s\\\'/>')" xmlDocSig) ] [
img [Src (sprintf "%scontent/img/copy-xml.png" root); Class "normal"]
img [Src (sprintf "%scontent/img/copy-xml-hover.png" root); Class "hover"]
]

let copyXmlSigIconForSymbol (symbol: FSharpSymbol) =
[ match symbol with
Expand All @@ -75,10 +75,10 @@ type HtmlRender(model: ApiDocModel) =
if xmlDocSig.Contains("``") then "```"
elif xmlDocSig.Contains("`") then "``"
else "`"
div [ Class"fsdocs-source-link"; OnClick (sprintf "Clipboard_CopyTo('%scref:%s%s')" delim xmlDocSig delim) ] [
div [ Class"fsdocs-source-link"; HtmlProperties.Title "Copy signature (Markdown)"; OnClick (sprintf "Clipboard_CopyTo('%scref:%s%s')" delim xmlDocSig delim) ] [
img [Src (sprintf "%scontent/img/copy-md.png" root); Class "normal"]
img [Src (sprintf "%scontent/img/copy-md-blue.png" root); Class "hover"]
]
img [Src (sprintf "%scontent/img/copy-md-hover.png" root); Class "hover"]
]

let copyXmlSigIconForSymbolMarkdown (symbol: FSharpSymbol) =
[ match symbol with
Expand All @@ -104,7 +104,7 @@ type HtmlRender(model: ApiDocModel) =
for m in members do
tr [] [
td [Class "fsdocs-member-usage"] [

codeWithToolTip [
// This adds #MemberName anchor. These may be ambiguous due to overloading
p [] [a [Id m.Name] [a [Href ("#"+m.Name)] [embed m.UsageHtml]]]
Expand Down Expand Up @@ -147,13 +147,13 @@ type HtmlRender(model: ApiDocModel) =
// where these have not been explicitly declared
match m.FormatTypeArguments with
| None -> ()
| Some v ->
| Some v ->
!!"Type parameters: "
encode(v)
]
]
]

td [Class "fsdocs-member-xmldoc"] [
div [Class "fsdocs-summary"]
[ yield! copyXmlSigIconForSymbolMarkdown m.Symbol
Expand Down Expand Up @@ -209,11 +209,11 @@ type HtmlRender(model: ApiDocModel) =
td [] [embed html]]
]

for e in m.Comment.Notes do
for e in m.Comment.Notes do
h5 [Class "fsdocs-note-header"] [!! "Note"]
p [Class "fsdocs-note"] [embed e]

for e in m.Comment.Examples do
for e in m.Comment.Examples do
h5 [Class "fsdocs-example-header"] [!! "Example"]
p [Class "fsdocs-example"] [embed e]

Expand All @@ -240,10 +240,10 @@ type HtmlRender(model: ApiDocModel) =
]
]
tbody [] [
for e in entities do
for e in entities do
tr [] [
td [Class "fsdocs-entity-name"] [
let nm = e.Name
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

Expand All @@ -268,7 +268,7 @@ type HtmlRender(model: ApiDocModel) =
let entity = info.Entity
let members = entity.AllMembers |> List.filter (fun e -> not e.IsObsolete)
let byCategory = members |> Categorise.getMembersByCategory

let usageName =
match info.ParentModule with
| Some m when m.RequiresQualifiedAccess -> m.Name + "." + entity.Name
Expand All @@ -283,12 +283,12 @@ type HtmlRender(model: ApiDocModel) =
| None -> ()
| Some parentModule ->
dt [] [!! "Parent Module: "; a [Href (parentModule.Url(root, collectionName, qualify, model.FileExtensions.InUrl))] [!! parentModule.Name ]]


match entity.AbbreviatedType with
| Some abbreviatedTyp ->
dt [] [!! "Abbreviation For: "; embed abbreviatedTyp]

| None -> ()

match entity.BaseType with
Expand All @@ -305,10 +305,10 @@ type HtmlRender(model: ApiDocModel) =
if i <> 0 then
!! ", "
embed ity ]

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

match entity.DelegateSignature with
| Some d ->
dt [] [!! ("Delegate Signature: "); embed d]
Expand Down Expand Up @@ -338,38 +338,38 @@ type HtmlRender(model: ApiDocModel) =
| Some r ->
p [Class "fsdocs-remarks"] [embed r]
| None -> ()
for note in entity.Comment.Notes do
for note in entity.Comment.Notes do
h5 [Class "fsdocs-note-header"] [!! "Note"]
p [Class "fsdocs-note"] [embed note]

for example in entity.Comment.Examples do
for example in entity.Comment.Examples do
h5 [Class "fsdocs-example-header"] [!! "Example"]
p [Class "fsdocs-example"] [embed example]

]

if (byCategory.Length > 1) then
// If there is more than 1 category in the type, generate TOC
// If there is more than 1 category in the type, generate TOC
h3 [] [!!"Table of contents"]
ul [] [
for (index, _, name) in byCategory do
li [] [ a [Href (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
div [] [
h3 [] [!! (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
]

for (index, ms, name) in byCategory do
// Iterate over all the categories and print members. If there are more than one
// categories, print the category heading (as <h2>) and add XML comment from the type
Expand Down Expand Up @@ -400,7 +400,7 @@ type HtmlRender(model: ApiDocModel) =
match nsdocs.Remarks with
| Some r -> p [] [embed r ]
| None -> ()

| None -> ()
]

Expand All @@ -411,17 +411,17 @@ type HtmlRender(model: ApiDocModel) =
for category in allByCategory do
li [] [a [Href ("#category-" + category.CategoryIndex)] [!!category.CategoryName]]
]

for category in allByCategory do
if (allByCategory.Length > 1) then
h3 [] [a [Class "anchor"; Name ("category-" + category.CategoryIndex); Href ("#category-" + category.CategoryIndex)] [!! category.CategoryName]]
yield! renderEntities category.CategoryEntites
]
]

let tableOfNamespacesAux () =
[
let categorise = Categorise.model model

for _allByCategory, ns in categorise do

// Generate the entry for the namespace
Expand All @@ -439,23 +439,23 @@ type HtmlRender(model: ApiDocModel) =
[
// For FSharp.Core we make all entries available to other docs else there's not a lot else to show.
//
// For non-FSharp.Core we only show one link "API Reference" in the nav menu
// For non-FSharp.Core we only show one link "API Reference" in the nav menu
if otherDocs && model.Collection.CollectionName <> "FSharp.Core" then
li [Class "nav-header"] [!! "API Reference"]
li [ Class "nav-item" ] [a [Class "nav-link"; Href (model.IndexFileUrl(root, collectionName, qualify, model.FileExtensions.InUrl))] [!! "All Namespaces" ] ]
li [ Class "nav-item" ] [a [Class "nav-link"; Href (model.IndexFileUrl(root, collectionName, qualify, model.FileExtensions.InUrl))] [!! "All Namespaces" ] ]
else

let categorise = Categorise.model model
let someExist = categorise.Length > 0

let someExist = categorise.Length > 0

if someExist then
li [Class "nav-header"] [!! "Namespaces"]

for allByCategory, ns in categorise do

// Generate the entry for the namespace
li [ Class ("nav-item" +
li [ Class ("nav-item" +
// add the 'active' class if this is the namespace of the thing being shown
match nsOpt with
| Some ns2 when ns.Name = ns2.Name -> " active"
Expand Down Expand Up @@ -521,7 +521,7 @@ type HtmlRender(model: ApiDocModel) =
]
]
let pageTitle = sprintf "%s (API Reference)" collectionName
let toc = listOfNamespacesNav false None
let toc = listOfNamespacesNav false None
let substitutions = getSubstitutons model.Substitutions toc content pageTitle
let outFile = Path.Combine(outDir, model.IndexOutputFile(collectionName, model.Qualify, model.FileExtensions.InFile) )
printfn " Generating %s" outFile
Expand All @@ -547,4 +547,3 @@ type HtmlRender(model: ApiDocModel) =
let outFile = Path.Combine(outDir, info.Entity.OutputFile(collectionName, model.Qualify, model.FileExtensions.InFile))
printfn " Generating %s" outFile
SimpleTemplating.UseFileAsSimpleTemplate (substitutions, templateOpt, outFile)

0 comments on commit 11aa8d0

Please sign in to comment.