From cd32009738e05e4eb7f7e0e25ccf700525a7badb Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Fri, 25 Sep 2020 16:21:57 +0100 Subject: Saildoc: do not mangle links targets enclosed in <> This can be useful to reference things that aren't defined by sail. --- src/latex.ml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/latex.ml b/src/latex.ml index 2bb38bd7..6d479a52 100644 --- a/src/latex.ml +++ b/src/latex.ml @@ -237,10 +237,14 @@ let latex_of_markdown str = | Ref (r, name, alt, _) -> (* special case for [id] (format as code) *) let format_fn = if name = alt then inline_code else replace_this in - begin match r#get_ref name with - | None -> sprintf "\\hyperref[%s]{%s}" (refcode_string name) (format_fn alt) - | Some (link, _) -> sprintf "\\hyperref[%s]{%s}" (refcode_string link) (format_fn alt) - end + (* Do not attempt to escape link destinations wrapped in <> *) + if Str.string_match (Str.regexp "<.+>") name 0 then + sprintf "\\hyperref[%s]{%s}" (String.sub name 1 ((String.length name) - 2)) (format_fn alt) + else + begin match r#get_ref name with + | None -> sprintf "\\hyperref[%s]{%s}" (refcode_string name) (format_fn alt) + | Some (link, _) -> sprintf "\\hyperref[%s]{%s}" (refcode_string link) (format_fn alt) + end | Url (href, text, "") -> sprintf "\\href{%s}{%s}" href (format text) | Url (href, text, reference) -> -- cgit v1.2.3