Skip to content

Commit 4625765

Browse files
panglesdjonludlam
authored andcommitted
Media: Do not interpret markup in replacement text
1 parent a101c82 commit 4625765

File tree

17 files changed

+88
-106
lines changed

17 files changed

+88
-106
lines changed

src/document/comment.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,10 @@ let rec nestable_block_element :
280280
| `Media (href, media, content) ->
281281
let content =
282282
match (content, href) with
283-
| [], `Reference path ->
284-
let s = Reference.render_unresolved (path :> Comment.Reference.t) in
285-
[ inline @@ Inline.Source (source_of_code s) ]
286-
| [], `Link href -> [ inline @@ Inline.Source (source_of_code href) ]
287-
| _ -> inline_element_list content
283+
| "", `Reference path ->
284+
Reference.render_unresolved (path :> Comment.Reference.t)
285+
| "", `Link href -> href
286+
| _ -> content
288287
in
289288
let url =
290289
match href with

src/document/doctree.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,17 @@ end = struct
380380
fun x ->
381381
match x.desc with
382382
| Inline x -> inline x
383-
| Audio (_, x) -> inline x
384-
| Video (_, x) -> inline x
385-
| Image (_, x) -> inline x
386383
| Paragraph x -> inline x
387384
| List (_, x) -> List.exists block x
388385
| Table { data; align = _ } ->
389386
List.exists (List.exists (fun (cell, _) -> block cell)) data
390387
| Description x -> description x
391388
| Math _ -> true
392-
| Source _ | Verbatim _ | Raw_markup _ -> false
389+
| Audio (_, _)
390+
| Video (_, _)
391+
| Image (_, _)
392+
| Source _ | Verbatim _ | Raw_markup _ ->
393+
false
393394
in
394395
List.exists block_ x
395396

src/document/types.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ and Block : sig
9494
| Verbatim of string
9595
| Raw_markup of Raw_markup.t
9696
| Table of t Table.t
97-
| Image of Target.t * Inline.t
98-
| Video of Target.t * Inline.t
99-
| Audio of Target.t * Inline.t
97+
| Image of Target.t * string
98+
| Video of Target.t * string
99+
| Audio of Target.t * string
100100

101101
and list_type = Ordered | Unordered
102102
end =

src/html/generator.ml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,26 +207,6 @@ let text_align = function
207207

208208
let cell_kind = function `Header -> Html.th | `Data -> Html.td
209209

210-
(* Turns an inline into a string, for use as alternative text in
211-
images *)
212-
let rec alt_of_inline (i : Inline.t) =
213-
let rec alt_of_source s =
214-
List.map
215-
(function
216-
| Source.Elt i -> alt_of_inline i | Tag (_, t) -> alt_of_source t)
217-
s
218-
|> String.concat ""
219-
in
220-
let alt_of_one (o : Inline.one) =
221-
match o.desc with
222-
| Text t | Math t | Entity t -> t
223-
| Linebreak -> "\n"
224-
| Styled (_, i) | Link { content = i; _ } -> alt_of_inline i
225-
| Source s -> alt_of_source s
226-
| Raw_markup _ -> ""
227-
in
228-
List.map alt_of_one i |> String.concat ""
229-
230210
let rec block ~config ~resolve (l : Block.t) : flow Html.elt list =
231211
let as_flow x = (x : phrasing Html.elt list :> flow Html.elt list) in
232212
let one (t : Block.one) =
@@ -242,7 +222,7 @@ let rec block ~config ~resolve (l : Block.t) : flow Html.elt list =
242222
let url = Link.href ~config ~resolve uri in
243223
media_block url
244224
| Internal Unresolved ->
245-
let content = inline ~config ~resolve content in
225+
let content = [ Html.txt content ] in
246226
let a = Html.a_class [ "xref-unresolved" ] :: [] in
247227
[ Html.span ~a content ]
248228
in
@@ -286,7 +266,6 @@ let rec block ~config ~resolve (l : Block.t) : flow Html.elt list =
286266
mk_media_block video target content
287267
| Image (target, alt) ->
288268
let image src =
289-
let alt = alt_of_inline alt in
290269
let img =
291270
Html.a
292271
~a:[ Html.a_href src; Html.a_class [ "img-link" ] ]

src/latex/generator.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ let rec block ~in_source (l : Block.t) =
282282
match t.desc with
283283
| Inline i -> inline ~verbatim:false ~in_source:false i
284284
| Audio (_, content) | Video (_, content) | Image (_, content) ->
285-
inline ~verbatim:false ~in_source:false content
285+
txt ~verbatim:false ~in_source:false [ content ]
286286
@ if in_source then [] else [ Break Paragraph ]
287287
| Paragraph i ->
288288
inline ~in_source:false ~verbatim:false i

src/manpage/generator.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ let rec block (l : Block.t) =
368368
match b.desc with
369369
| Inline i -> inline i ++ continue rest
370370
| Video (_, content) | Audio (_, content) | Image (_, content) ->
371-
inline content ++ continue rest
371+
str "%s" content ++ continue rest
372372
| Paragraph i -> inline i ++ continue rest
373373
| List (list_typ, l) ->
374374
let f n b =

src/model/comment.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type 'a abstract_table = {
5858

5959
type media_href = [ `Link of string | `Reference of Reference.Asset.t ]
6060

61-
type media_element = [ `Media of media_href * media * paragraph ]
61+
type media_element = [ `Media of media_href * media * string ]
6262

6363
type nestable_block_element =
6464
[ `Paragraph of paragraph

src/model/semantics.ml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ type internal_tags_removed =
55
[ `Tag of Ast.ocamldoc_tag
66
| `Heading of Ast.heading
77
| `Media of
8-
Ast.reference_kind
9-
* Ast.media_href Ast.with_location
10-
* Ast.inline_element Ast.with_location list
11-
* Ast.media
8+
Ast.reference_kind * Ast.media_href Ast.with_location * string * Ast.media
129
| Ast.nestable_block_element ]
1310
(** {!Ast.block_element} without internal tags. *)
1411

@@ -277,8 +274,7 @@ let rec nestable_block_element :
277274
in
278275
`Table { Comment.data; align } |> Location.at location
279276
| { value = `Media (_, { value = `Link href; _ }, content, m); location } ->
280-
let text = inline_elements status content in
281-
`Media (`Link href, m, text) |> Location.at location
277+
`Media (`Link href, m, content) |> Location.at location
282278
| {
283279
value =
284280
`Media
@@ -290,16 +286,16 @@ let rec nestable_block_element :
290286
let placeholder =
291287
match kind with
292288
| `Simple -> `Code_span href
293-
| `With_text -> `Styled (`Emphasis, content)
289+
| `With_text ->
290+
`Styled (`Emphasis, [ `Word content |> Location.at location ])
294291
in
295292
`Paragraph
296293
(inline_elements status [ placeholder |> Location.at location ])
297294
|> Location.at location
298295
in
299296
match Error.raise_warnings (Reference.parse_asset href_location href) with
300297
| Result.Ok target ->
301-
let text = inline_elements status content in
302-
`Media (`Reference target, m, text) |> Location.at location
298+
`Media (`Reference target, m, content) |> Location.at location
303299
| Result.Error error -> fallback error)
304300

305301
and nestable_block_elements status elements =

src/model_desc/comment_desc.ml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ type general_block_element =
3333
Comment.heading_attrs * Identifier.Label.t * general_link_content
3434
| `Tag of general_tag
3535
| `Media of
36-
[ `Reference of Paths.Reference.t | `Link of string ]
37-
* media
38-
* general_link_content
36+
[ `Reference of Paths.Reference.t | `Link of string ] * media * string
3937
| `MediaLink of string * media * general_link_content ]
4038

4139
and general_tag =
@@ -155,10 +153,7 @@ let rec block_element : general_block_element t =
155153
| `Heading h -> C ("`Heading", h, heading)
156154
| `Tag x -> C ("`Tag", x, tag)
157155
| `Media (x1, m, x2) ->
158-
C
159-
( "`MediaReference",
160-
(x1, m, x2),
161-
Triple (media_href, media, link_content) )
156+
C ("`MediaReference", (x1, m, x2), Triple (media_href, media, string))
162157
| `MediaLink (x1, m, x2) ->
163158
C ("`MediaLink", (x1, m, x2), Triple (string, media, link_content)))
164159

src/parser/ast.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ and nestable_block_element =
6161
* nestable_block_element with_location list list
6262
| `Table of table
6363
| `Math_block of string (** @since 2.0.0 *)
64-
| `Media of
65-
reference_kind
66-
* media_href with_location
67-
* inline_element with_location list
68-
* media
64+
| `Media of reference_kind * media_href with_location * string * media
6965
(** @since 3.0.0 *) ]
7066
(** Some block elements may be nested within lists or tags, but not all.
7167
The [`List] constructor has a parameter of type [\[`Light | `Heavy\]].

0 commit comments

Comments
 (0)