Skip to content

Commit 2b071d1

Browse files
committed
fix: update override_url to handle internal links
1 parent 0a9cc43 commit 2b071d1

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

demo-repository/exercises/demo2/descr.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[ceci est un lien](http://google.com)
2-
This exercise is just another demo for the exercise environment.
1+
The following example link will open another tab/window: [OCaml](https://ocaml.org/).
2+
This exercise is just another demo for the exercise environment.
33
<a href="" onclick="top.location='/exercises/demo/';">Test</a>
44

55
<details>

src/repo/learnocaml_exercise.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,20 @@ module File = struct
317317
descrs := (lang, f raw) :: !descrs;
318318
return ()
319319
in
320-
let open Omd_representation in
321-
let override_url = function
322-
| Url(href,s,title) ->
323-
Some ( let title_url =
324-
if title <> ""
325-
then
326-
Printf.sprintf {| title="%s"|} title
327-
else "" in
328-
Printf.sprintf
320+
let override_url = function
321+
| Omd_representation.Url(href,s,title) ->
322+
if String.length href > 0 then
323+
if Char.equal (String.get href 0) '#' then
324+
None
325+
else
326+
let title_url =
327+
if title <> "" then Printf.sprintf {| title="%s"|} title else "" in
328+
let html =
329+
Printf.sprintf
329330
{|<a href="%s" target="_blank" rel="noopener noreferrer"%s>%s</a>|}
330-
href title_url (Omd_backend.html_of_md s))
331+
href title_url (Omd_backend.html_of_md s) in
332+
Some html
333+
else None
331334
| _ -> None in
332335
let markdown_to_html md =
333336
Omd.(md |> of_string |> to_html ~override:override_url)

0 commit comments

Comments
 (0)