-
Notifications
You must be signed in to change notification settings - Fork 103
Add labels to basic text block (such as paragraphs and code blocks) #974
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,23 +216,45 @@ let rec inline_element : | |
|
|
||
| and inline_elements status elements = List.map (inline_element status) elements | ||
|
|
||
| let generate_label = | ||
| let current_label = ref 0 in | ||
| fun kind status -> | ||
| let lbl = | ||
| match kind with | ||
| | `Paragraph -> "p" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these likely to clash with any other hand-written labels? |
||
| | `Code_block -> "code" | ||
| | `Verbatim -> "v" | ||
| | `Math_block -> "math" | ||
| in | ||
| let name = Format.sprintf "%s%d" lbl !current_label in | ||
| incr current_label; | ||
| Paths.Identifier.Mk.label | ||
| (status.parent_of_sections, Names.LabelName.make_std name) | ||
|
|
||
| let rec nestable_block_element : | ||
| status -> | ||
| Odoc_parser.Ast.nestable_block_element with_location -> | ||
| Comment.nestable_block_element with_location = | ||
| fun status element -> | ||
| match element with | ||
| | { value = `Paragraph content; location } -> | ||
| Location.at location (`Paragraph (inline_elements status content)) | ||
| let content = inline_elements status content in | ||
| let label = generate_label `Paragraph status in | ||
| Location.at location (`Paragraph (label, content)) | ||
| | { value = `Code_block (metadata, code); location } -> | ||
| let lang_tag = | ||
| match metadata with | ||
| | Some ({ Location.value; _ }, _) -> Some value | ||
| | None -> None | ||
| in | ||
| Location.at location (`Code_block (lang_tag, code)) | ||
| | { value = `Math_block s; location } -> Location.at location (`Math_block s) | ||
| | { value = `Verbatim _; _ } as element -> element | ||
| let label = generate_label `Code_block status in | ||
| Location.at location (`Code_block (label, lang_tag, code)) | ||
| | { value = `Math_block s; location } -> | ||
| let label = generate_label `Verbatim status in | ||
| Location.at location (`Math_block (label, s)) | ||
| | { value = `Verbatim v; location } -> | ||
| let label = generate_label `Math_block status in | ||
| Location.at location (`Verbatim (label, v)) | ||
| | { value = `Modules modules; location } -> | ||
| let modules = | ||
| List.fold_left | ||
|
|
@@ -381,9 +403,10 @@ let section_heading : | |
| | `None, _any_level -> | ||
| Error.raise_warning (headings_not_allowed location); | ||
| let text = (text :> Comment.inline_element with_location list) in | ||
| let label = generate_label `Paragraph status in | ||
| let element = | ||
| Location.at location | ||
| (`Paragraph [ Location.at location (`Styled (`Bold, text)) ]) | ||
| (`Paragraph (label, [ Location.at location (`Styled (`Bold, text)) ])) | ||
| in | ||
| (top_heading_level, element) | ||
| | `No_titles, 0 -> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -462,9 +462,21 @@ end = | |
| Substitution | ||
|
|
||
| and CComment : sig | ||
| type nestable_block_element = | ||
| [ `Paragraph of Label.t * Odoc_model.Comment.paragraph | ||
| | `Code_block of | ||
| Label.t * string option * string Odoc_model.Comment.with_location | ||
| | `Math_block of Label.t * string | ||
| | `Verbatim of Label.t * string | ||
| | `Modules of Odoc_model.Comment.module_reference list | ||
| | `List of | ||
| [ `Unordered | `Ordered ] | ||
| * nestable_block_element Odoc_model.Comment.with_location list list ] | ||
|
|
||
| type block_element = | ||
| [ Odoc_model.Comment.nestable_block_element | ||
| | `Heading of Label.t | ||
| [ nestable_block_element | ||
| | `Heading of | ||
| Odoc_model.Comment.heading_attrs * Label.t * Odoc_model.Comment.paragraph | ||
| | `Tag of Odoc_model.Comment.tag ] | ||
|
|
||
| type docs = block_element Odoc_model.Comment.with_location list | ||
|
|
@@ -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 = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The attrs have been moved onto the |
||
| attrs : Odoc_model.Comment.heading_attrs; | ||
| label : Ident.label; | ||
| text : Odoc_model.Comment.paragraph; | ||
| content : content; | ||
| location : Odoc_model.Location_.span; | ||
| (** In order to check for ambiguous labels *) | ||
| } | ||
| end = | ||
| Label | ||
|
|
@@ -2412,16 +2427,51 @@ module Of_Lang = struct | |
| in | ||
| { items; removed = []; compiled = sg.compiled; doc = docs ident_map sg.doc } | ||
|
|
||
| and block_element _ b : | ||
| and nestable_block_element map | ||
| (b : Odoc_model.Comment.nestable_block_element Comment.with_location) = | ||
| let mk_label label location = | ||
| { | ||
| Label.label = Ident.Of_Identifier.label label; | ||
| location; | ||
| content = NestableBlock; | ||
| } | ||
| in | ||
| match b with | ||
| | { Odoc_model.Location_.value = `Paragraph (label, text); location } -> | ||
| let label = mk_label label location in | ||
| let para = `Paragraph (label, text) in | ||
| Odoc_model.Location_.same b para | ||
| | { value = `Code_block (label, l, s); location } -> | ||
| let label = mk_label label location in | ||
| let cb = `Code_block (label, l, s) in | ||
| Odoc_model.Location_.same b cb | ||
| | { value = `Math_block (label, s); location } -> | ||
| let label = mk_label label location in | ||
| let mb = `Math_block (label, s) in | ||
| Odoc_model.Location_.same b mb | ||
| | { value = `Verbatim (label, s); location } -> | ||
| let label = mk_label label location in | ||
| let v = `Verbatim (label, s) in | ||
| Odoc_model.Location_.same b v | ||
| | { value = `List (ord, items); _ } -> | ||
| let items = List.map (List.map (nestable_block_element map)) items in | ||
| let l = `List (ord, items) in | ||
| Odoc_model.Location_.same b l | ||
| | { value = `Modules _; _ } as n -> n | ||
|
|
||
| and block_element map b : | ||
| CComment.block_element Odoc_model.Comment.with_location = | ||
| match b with | ||
| | { Odoc_model.Location_.value = `Heading (attrs, label, text); location } | ||
| -> | ||
| let label = Ident.Of_Identifier.label label in | ||
| Odoc_model.Location_.same b | ||
| (`Heading { Label.attrs; label; text; location }) | ||
| (`Heading | ||
| (attrs, { Label.label; content = Heading text; location }, text)) | ||
| | { value = `Tag _; _ } as t -> t | ||
| | { value = #Odoc_model.Comment.nestable_block_element; _ } as n -> n | ||
| | { value = #Odoc_model.Comment.nestable_block_element; _ } as n -> | ||
| (nestable_block_element map n | ||
| :> CComment.block_element Odoc_model.Comment.with_location) | ||
|
|
||
| and docs ident_map d = List.map (block_element ident_map) d | ||
|
|
||
|
|
||
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.