Skip to content

Commit

Permalink
Merge pull request #392 from pfitaxel/markdown-preview
Browse files Browse the repository at this point in the history
Update the markdown-to-html transformation so links open a new tab
  • Loading branch information
erikmd committed May 14, 2021
2 parents 7c9132d + ca7714e commit e0e3f2f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions demo-repository/exercises/demo2/descr.md
@@ -1,5 +1,5 @@

This exercise is just another demo for the exercise environment.
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.
<a href="" onclick="top.location='/exercises/demo/';">Test</a>

<details>
Expand Down
2 changes: 1 addition & 1 deletion learn-ocaml-client.opam
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion learn-ocaml.opam
Expand Up @@ -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"
Expand Down
17 changes: 16 additions & 1 deletion src/repo/learnocaml_exercise.ml
Expand Up @@ -317,8 +317,23 @@ module File = struct
descrs := (lang, f raw) :: !descrs;
return ()
in
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) in
Some html
else None
| _ -> 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
Expand Down

0 comments on commit e0e3f2f

Please sign in to comment.