From 0a9cc433fe24346558dab6e6df476baa6c7d5297 Mon Sep 17 00:00:00 2001 From: LouisAyroles Date: Wed, 12 May 2021 10:51:40 +0200 Subject: [PATCH 1/4] feat: update the transformation from markdown to html which allow to open in a new tab when clicking on a link --- demo-repository/exercises/demo2/descr.md | 2 +- src/repo/learnocaml_exercise.ml | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/demo-repository/exercises/demo2/descr.md b/demo-repository/exercises/demo2/descr.md index 3b7c6f0ca..4226b96c4 100644 --- a/demo-repository/exercises/demo2/descr.md +++ b/demo-repository/exercises/demo2/descr.md @@ -1,4 +1,4 @@ - +[ceci est un lien](http://google.com) This exercise is just another demo for the exercise environment. Test diff --git a/src/repo/learnocaml_exercise.ml b/src/repo/learnocaml_exercise.ml index 5157b05e0..2790b2afe 100644 --- a/src/repo/learnocaml_exercise.ml +++ b/src/repo/learnocaml_exercise.ml @@ -317,8 +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 + {|%s|} + href title_url (Omd_backend.html_of_md s)) + | _ -> None in let markdown_to_html md = - Omd.(md |> of_string |> to_html) + Omd.(md |> of_string |> to_html ~override:override_url) in let read_descrs () = let langs = [] in From 2b071d1e97eec3fc274304de83ecea3343d650aa Mon Sep 17 00:00:00 2001 From: LouisAyroles Date: Fri, 14 May 2021 10:48:52 +0200 Subject: [PATCH 2/4] fix: update override_url to handle internal links --- demo-repository/exercises/demo2/descr.md | 4 ++-- src/repo/learnocaml_exercise.ml | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/demo-repository/exercises/demo2/descr.md b/demo-repository/exercises/demo2/descr.md index 4226b96c4..8754e645e 100644 --- a/demo-repository/exercises/demo2/descr.md +++ b/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. Test
diff --git a/src/repo/learnocaml_exercise.ml b/src/repo/learnocaml_exercise.ml index 2790b2afe..f919d3a3a 100644 --- a/src/repo/learnocaml_exercise.ml +++ b/src/repo/learnocaml_exercise.ml @@ -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 {|%s|} - 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) From 44b7af549315d9005fe69a84678d4af648ad2355 Mon Sep 17 00:00:00 2001 From: Erik Martin-Dorel Date: Fri, 14 May 2021 13:04:41 +0200 Subject: [PATCH 3/4] docs: Add some title="External link" attribute --- demo-repository/exercises/demo2/descr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo-repository/exercises/demo2/descr.md b/demo-repository/exercises/demo2/descr.md index 8754e645e..13c15704a 100644 --- a/demo-repository/exercises/demo2/descr.md +++ b/demo-repository/exercises/demo2/descr.md @@ -1,4 +1,4 @@ -The following example link will open another tab/window: [OCaml](https://ocaml.org/). +The following example link will open another tab/window: [OCaml](https://ocaml.org "External link") This exercise is just another demo for the exercise environment. Test From ca7714ec62d55991f3aff095524ab5b0bf3b40d1 Mon Sep 17 00:00:00 2001 From: Erik Martin-Dorel Date: Fri, 14 May 2021 13:06:11 +0200 Subject: [PATCH 4/4] chore: Add constraint "omd" {<= "1.3.1"} * Given we rely on (Omd.to_html ~override) * See also issue https://github.com/ocaml/omd/issues/239 --- learn-ocaml-client.opam | 2 +- learn-ocaml.opam | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/learn-ocaml-client.opam b/learn-ocaml-client.opam index f4e06fffc..476ab76e8 100644 --- a/learn-ocaml-client.opam +++ b/learn-ocaml-client.opam @@ -17,7 +17,7 @@ depends: [ "base" {>= "v0.9.4"} "base64" "cmdliner" - "omd" + "omd" {<= "1.3.1"} "asak" "cohttp" {>= "1.0.0" & < "2.0.0"} "cohttp-lwt-unix" {>= "1.0.0" & < "2.0.0"} diff --git a/learn-ocaml.opam b/learn-ocaml.opam index 19c67b877..8777f30d6 100644 --- a/learn-ocaml.opam +++ b/learn-ocaml.opam @@ -46,7 +46,7 @@ depends: [ "ocp-ocamlres" {>= "0.4"} "ocplib-json-typed" {= "0.6"} "odoc" {build & >= "1.3.0"} - "omd" + "omd" {<= "1.3.1"} "pprint" "ppx_cstruct" "ppx_tools"