-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add labels to basic text block (such as paragraphs and code blocks) #974
Conversation
This allows to generate anchors, and link to specific places in the rendered html. This is useful for search results in doc comments or mld page. Clickable anchors are not generated. Signed-off-by: Paul-Elliot <peada@free.fr>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some < 4.10
test files are not uptodate.
[ `Paragraph of Identifier.Label.t * paragraph | ||
| `Code_block of Identifier.Label.t * string option * string with_location | ||
| `Math_block of Identifier.Label.t * string | ||
| `Verbatim of Identifier.Label.t * string | ||
| `Modules of module_reference list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modules compiles to a html block element and doesn't contain odoc nestable block elements so could have a label too.
List.for_all | ||
(function | ||
| `Label | ||
(_, { Component.Label.label = _; content = Heading _; location = _ }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the warning should be removed if it's due to generated labels ? The printing function used in the warning should at least not name it section-p0
.
For example
(** *)
(** foo *)
(** {1:p0 A} *)
(** {!p0} *)
Warning: Reference to 'p0' is ambiguous. Please specify its kind: section-p0, section-p0.
File "../test.mli", line 5, characters 4-12:
Warning: Label 'p0' is ambiguous. The other occurrences are:
File "../test.mli", line 3, character 4
({ Odoc_model.Paths.Identifier.iv = `Label (lbl_parent, label_name); _ } as | ||
id) = | ||
let label_name = Names.LabelName.to_string label_name in | ||
let need_new_label label = ambiguous_labels ~loc env label != [] in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a O(n^2)
complexity ? There's ambiguous_labels
inside Env
that works on identifiers and could be exposed through a new is_label_ambiguous
function.
@@ -443,11 +455,14 @@ and CComment : sig | |||
end | |||
|
|||
and Label : sig | |||
(** In order to generate content for links without content *) | |||
type content = Heading of Odoc_model.Comment.paragraph | NestableBlock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier.Label.t
is often deconstructed directly and used to have one meaning. Now it has two due to this and I can't be sure it makes sense everywhere it's matched on.
Have you though of adding a new kind of identifier for generated labels ? That wouldn't be a simplification but the disambiguation and reference resolving would be explicit in how they deal with the new kind of labels.
fun kind status -> | ||
let lbl = | ||
match kind with | ||
| `Paragraph -> "p" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these likely to clash with any other hand-written labels?
@@ -474,11 +486,14 @@ end = | |||
CComment | |||
|
|||
and Label : sig | |||
(** In order to generate content for links without content *) | |||
type content = Heading of Odoc_model.Comment.paragraph | NestableBlock | |||
|
|||
type t = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attrs have been moved onto the `Heading
constructor right? Any idea why they weren't there to begin with? With your fix it's much more similar to Comment.block_element
now, so I'm confused why we didn't do that from day one!
I'm a little nervous about allowing these new labels as valid references, it seems a bit brittle. I'd much prefer it that if you wanted to link to a paragraph or code block or whatever that we could add in an explicit label. I can see the use of them in search, where we'll want to be able to link to anything automatically, of course. |
These labels are indeed going to be quite brittle, changing when the page changes. I'm starting to think that maybe search should just only link directly on stuff that has direct user defined anchors (that includes structure items). When there is no such anchor it seems to me that just linking on the page like regular search engines do is ok. |
I still think it's quite useful to be able to link directly from the search to the relevant part, especially in a large file. Though if that's the primary use-case then it's a little questionable why we're adding the links in the model rather than only in the html output, since it does mean a bit of pain going back and forth between |
When you browse the web via a search engine the conjunction of result snippets and in page search usually does a good job at that. I just worry that people are going to cut and paste around brittle links. |
One possibility would be to use the last heading as target when clicking on a search result corresponding to a paragraph. It would be a bit less precise, but still better than just linking to the page. Disambiguation of headings also need to be done earlier than after the |
That could be an idea!
Indeed. I don't think they are a good idea either. But somehow it's either that or having less usable pages because people don't care. There's no real good solution that I'm aware of. |
The compilation of the search index is done from the One possibility would be to add a common first phase to |
I wonder what is @jonludlam and @Julow opinion on using the last heading as target. I'm hesitant between this and the current approach. |
Note that this kind of stuff is hard to assess whether it will work well or not with users. There's little you can do but try and see how it fares in practice… (And as such I would try that idea first) |
Last heading or most recent anchor of any sort? I'm in favour of using the anchors we have right now and if that turns out to be a bad user experience then we can revisit this decision. |
Aren't we outputting an html snippet in the index? |
Yes, but we are generating them separately for each entry. Disambiguation needs the document as a whole to work. I'm putting this PR on pause to focus on the "last heading" or "last anchor" solution. |
Right, makes sense, thanks. |
I'll close this PR now then - we can do disambiguation in another PR. |
This allows to generate anchors, and link to specific places in the rendered html.
This is useful for search results in doc comments or mld page. Clickable anchors are not generated.
Somehow part of #972.