Skip to content

Conversation

@baronfel
Copy link
Collaborator

@baronfel baronfel commented Sep 8, 2021

Based on this discussion it seems like we should support user-defined ids for examples (for example to allow deep-linking to a specific example).

let sepWith s l = l |> List.sepWith (!! s) |> span []

type System.Xml.Linq.XElement with
member x.TryAttr (attr: string) =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this for convenience and then only used it in the new code, but I'd of course be willing to reuse it in the existing attribute fetches in this file if you like.

let n = if id = 0 then "example" else "example-" + string id
rawData.[n] <- e.Value
let exampleId =
match e.TryAttr "id" with
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tied to the question in the RFC change, what level of uniqueness should be enforced by tooling?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally fail if --strict is used, and warn otherwise

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm noodling around the implementation a bit here still for validation purposes: if the scope is just within a particular example then that's easy to do validation on, because we have all the examples locally, but at any other scope than that things get hard because we don't have that data available and/or we'd have to push the validation up a level...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settled on duplicate within a member at the moment, but we could expand that to the type semi-easily if desired

@dsyme
Copy link
Contributor

dsyme commented Sep 9, 2021

@baronfel Thanks! Could you add a test please?

for e in m.Comment.Examples do
h5 [Class "fsdocs-example-header"] [!! "Example"]
p [Class "fsdocs-example"] [embed e]
p [Class "fsdocs-example"; if e.Id.IsSome then Id e.Id.Value ] [embed e]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id's generated in the html now, yay

comment.Examples
|> List.choose (fun x -> x.Id)
|> List.countBy id
for (id, count) in knownExampleIds do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pass checks for duplicate example ids on a per-member basis

else
printfn "%s(%d,%d): error: duplicate id for example '%s'" m.FileName m.StartLine m.StartColumn id
for (id, _count) in knownExampleIds do
if id.StartsWith "example-" then
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pass checks for missing example ids where we potentially inserted a dummy id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then on same line as if please per style guide

@dsyme dsyme merged commit e45c793 into fsprojects:master Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants