Skip to content

Commit

Permalink
fix: update override_url to handle internal links
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisAyroles committed May 14, 2021
1 parent 0a9cc43 commit 2b071d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions demo-repository/exercises/demo2/descr.md
@@ -1,5 +1,5 @@
[ceci est un lien](http://google.com)
This exercise is just another demo for the exercise environment.
The following example link will open another tab/window: [OCaml](https://ocaml.org/).
This exercise is just another demo for the exercise environment.
<a href="" onclick="top.location='/exercises/demo/';">Test</a>

<details>
Expand Down
23 changes: 13 additions & 10 deletions src/repo/learnocaml_exercise.ml
Expand Up @@ -317,17 +317,20 @@ module File = struct
descrs := (lang, f raw) :: !descrs;
return ()
in
let open Omd_representation in
let override_url = function
| Url(href,s,title) ->
Some ( let title_url =
if title <> ""
then
Printf.sprintf {| title="%s"|} title
else "" in
Printf.sprintf
let override_url = function
| Omd_representation.Url(href,s,title) ->
if String.length href > 0 then
if Char.equal (String.get href 0) '#' then
None
else
let title_url =
if title <> "" then Printf.sprintf {| title="%s"|} title else "" in
let html =
Printf.sprintf
{|<a href="%s" target="_blank" rel="noopener noreferrer"%s>%s</a>|}
href title_url (Omd_backend.html_of_md s))
href title_url (Omd_backend.html_of_md s) in
Some html
else None
| _ -> None in
let markdown_to_html md =
Omd.(md |> of_string |> to_html ~override:override_url)
Expand Down

0 comments on commit 2b071d1

Please sign in to comment.