Skip to content

Commit e0e3f2f

Browse files
authored
Merge pull request #392 from pfitaxel/markdown-preview
Update the markdown-to-html transformation so links open a new tab
2 parents 7c9132d + ca7714e commit e0e3f2f

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
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-
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 "External link")
2+
This exercise is just another demo for the exercise environment.
33
<a href="" onclick="top.location='/exercises/demo/';">Test</a>
44

55
<details>

learn-ocaml-client.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ depends: [
1717
"base" {>= "v0.9.4"}
1818
"base64"
1919
"cmdliner"
20-
"omd"
20+
"omd" {<= "1.3.1"}
2121
"asak"
2222
"cohttp" {>= "1.0.0" & < "2.0.0"}
2323
"cohttp-lwt-unix" {>= "1.0.0" & < "2.0.0"}

learn-ocaml.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ depends: [
4646
"ocp-ocamlres" {>= "0.4"}
4747
"ocplib-json-typed" {= "0.6"}
4848
"odoc" {build & >= "1.3.0"}
49-
"omd"
49+
"omd" {<= "1.3.1"}
5050
"pprint"
5151
"ppx_cstruct"
5252
"ppx_tools"

src/repo/learnocaml_exercise.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,23 @@ module File = struct
317317
descrs := (lang, f raw) :: !descrs;
318318
return ()
319319
in
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
330+
{|<a href="%s" target="_blank" rel="noopener noreferrer"%s>%s</a>|}
331+
href title_url (Omd_backend.html_of_md s) in
332+
Some html
333+
else None
334+
| _ -> None in
320335
let markdown_to_html md =
321-
Omd.(md |> of_string |> to_html)
336+
Omd.(md |> of_string |> to_html ~override:override_url)
322337
in
323338
let read_descrs () =
324339
let langs = [] in

0 commit comments

Comments
 (0)