Skip to content

Commit

Permalink
Replace Dependency on omd with cmarkit, advance opam-repository pin (#…
Browse files Browse the repository at this point in the history
…1642)

---------

Co-authored-by: Sabine Schmaltz <[email protected]>
  • Loading branch information
oyenuga17 and sabine authored Nov 24, 2023
1 parent a258c7a commit 9a07e66
Show file tree
Hide file tree
Showing 28 changed files with 145 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ocaml/opam:debian-ocaml-4.14

# Branch freeze was opam-repo HEAD at the time of commit
RUN cd ~/opam-repository && git checkout -b freeze c1fcfbe8369cb5a7cb8d7be63db59856dbd85d19 && opam update
RUN cd ~/opam-repository && git checkout -b freeze 8cc107f96e33a4601f7c39346eb19fbbe46486d3 && opam update

# Dev tools
RUN opam install -y dune-release merlin ocamlformat=0.24.1 utop ocaml-lsp-server
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: ${{ matrix.os != 'macos-latest' }}
opam-repositories: |
pin: git+https://github.com/ocaml/opam-repository#c1fcfbe8369cb5a7cb8d7be63db59856dbd85d19
pin: git+https://github.com/ocaml/opam-repository#8cc107f96e33a4601f7c39346eb19fbbe46486d3
opam-disable-sandboxing: true

- name: Install system dependencies (Linux)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dummy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
ocaml-compiler: ocaml-base-compiler.4.14.1
opam-repositories: |
pin: git+https://github.com/ocaml/opam-repository#c1fcfbe8369cb5a7cb8d7be63db59856dbd85d19
pin: git+https://github.com/ocaml/opam-repository#8cc107f96e33a4601f7c39346eb19fbbe46486d3
opam-disable-sandboxing: true

- run: git rev-parse HEAD
2 changes: 1 addition & 1 deletion .github/workflows/linkcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: ${{ matrix.os != 'macos-latest' }}
opam-repositories: |
pin: git+https://github.com/ocaml/opam-repository#c1fcfbe8369cb5a7cb8d7be63db59856dbd85d19
pin: git+https://github.com/ocaml/opam-repository#8cc107f96e33a4601f7c39346eb19fbbe46486d3
opam-disable-sandboxing: true
opam-depext-flags: "--update"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scrape.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: ${{ matrix.os != 'macos-latest' }}
opam-repositories: |
pin: git+https://github.com/ocaml/opam-repository#c1fcfbe8369cb5a7cb8d7be63db59856dbd85d19
pin: git+https://github.com/ocaml/opam-repository#8cc107f96e33a4601f7c39346eb19fbbe46486d3
opam-disable-sandboxing: true

- name: Install system dependencies
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM ocaml/opam:alpine-3.18-ocaml-4.14 as build
RUN sudo apk update && sudo apk add --update libev-dev openssl-dev gmp-dev oniguruma-dev inotify-tools curl-dev autoconf

# Branch freeze was opam-repo HEAD at the time of commit
RUN cd opam-repository && git pull origin c1fcfbe8369cb5a7cb8d7be63db59856dbd85d19 && opam update
RUN cd opam-repository && git pull origin 8cc107f96e33a4601f7c39346eb19fbbe46486d3 && opam update

WORKDIR /home/opam

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deps: create_switch ## Install development dependencies

.PHONY: create_switch
create_switch: ## Create switch and pinned opam repo
opam switch create . 4.14.1 --no-install --repos pin=git+https://github.com/ocaml/opam-repository#c1fcfbe8369cb5a7cb8d7be63db59856dbd85d19
opam switch create . 4.14.1 --no-install --repos pin=git+https://github.com/ocaml/opam-repository#8cc107f96e33a4601f7c39346eb19fbbe46486d3

.PHONY: switch
switch: deps ## Create an opam switch and install development dependencies
Expand Down
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
fpath
fmt
logs
(omd
(>= "2.0.0~alpha4"))
(cmarkit
(>= 0.2.0))
opam-format
(timedesc
(>= 1.1.1))
yojson
lwt
tailwindcss
(hilite
(>= 0.3.0))
(>= 0.4.0))
river
syndic
(alcotest :with-test)
Expand Down
4 changes: 2 additions & 2 deletions ocamlorg.opam
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ depends: [
"fpath"
"fmt"
"logs"
"omd" {>= "2.0.0~alpha4"}
"cmarkit" {>= "0.2.0"}
"opam-format"
"timedesc" {>= "1.1.1"}
"yojson"
"lwt"
"tailwindcss"
"hilite" {>= "0.3.0"}
"hilite" {>= "0.4.0"}
"river"
"syndic"
"alcotest" {with-test}
Expand Down
1 change: 0 additions & 1 deletion src/ocamlorg_data/data.mli
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ module Workshop : sig
presentations : presentation list;
program_committee : committee_member list;
organising_committee : committee_member list;
toc_html : string;
body_md : string;
body_html : string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ocamlorg_web/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
dream
dream-accept
dream-encoding
omd
cmarkit
ocamlorg.data
timedesc
mirage-kv-mem))
4 changes: 3 additions & 1 deletion src/ocamlorg_web/lib/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@ module Package_helper = struct
(Option.map Ocamlorg_package.Version.to_string latest_version);
synopsis = info.Ocamlorg_package.Info.synopsis;
description =
info.Ocamlorg_package.Info.description |> Omd.of_string |> Omd.to_html;
info.Ocamlorg_package.Info.description
|> Cmarkit.Doc.of_string ~strict:true
|> Cmarkit_html.of_doc ~safe:true;
tags = info.tags;
rev_deps;
authors = List.map owner info.authors;
Expand Down
4 changes: 3 additions & 1 deletion tool/ood-gen/lib/academic_institution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ let of_metadata m = of_metadata m ~slug:(Utils.slugify m.name)

let decode (_, (head, body_md)) =
let metadata = metadata_of_yaml head in
let body_html = Omd.of_string body_md |> Omd.to_html in
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md |> Cmarkit_html.of_doc ~safe:true
in
Result.map (of_metadata ~body_md ~body_html) metadata

let all () = Utils.map_files decode "academic_institutions"
Expand Down
4 changes: 3 additions & 1 deletion tool/ood-gen/lib/book.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ let of_metadata m = of_metadata m
let decode (_, (head, body)) =
let metadata = metadata_of_yaml head in
let body_md = String.trim body in
let body_html = Omd.of_string body |> Omd.to_html in
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md |> Cmarkit_html.of_doc ~safe:true
in
Result.map (of_metadata ~body_md ~body_html) metadata

let all () =
Expand Down
9 changes: 6 additions & 3 deletions tool/ood-gen/lib/changelog.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ let decode (fname, (head, body)) =
let slug = Filename.basename (Filename.remove_extension fname) in
let metadata = metadata_of_yaml head in
let body_html =
Omd.to_html (Hilite.Md.transform (Omd.of_string (String.trim body)))
Cmarkit_html.of_doc ~safe:false
(Hilite.Md.transform
(Cmarkit.Doc.of_string ~strict:true (String.trim body)))
in

Result.map
Expand All @@ -36,8 +38,9 @@ let decode (fname, (head, body)) =
| None -> None
| Some changelog ->
Some
(Omd.to_html
(Hilite.Md.transform (Omd.of_string (String.trim changelog))))
(Cmarkit.Doc.of_string ~strict:true (String.trim changelog)
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false)
in
of_metadata ~slug ~changelog_html ~body_html metadata)
metadata
Expand Down
2 changes: 1 addition & 1 deletion tool/ood-gen/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name ood_gen)
(libraries
ocamlorg.global
omd
cmarkit
yaml
unix
ptime
Expand Down
4 changes: 3 additions & 1 deletion tool/ood-gen/lib/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ let of_metadata m = of_metadata m ~slug:(Utils.slugify m.title)

let decode (_, (head, body_md)) =
let metadata = metadata_of_yaml head in
let body_html = Omd.of_string body_md |> Omd.to_html in
let body_html =
Cmarkit.Doc.of_string body_md |> Cmarkit_html.of_doc ~safe:true
in
Result.map (of_metadata ~body_md ~body_html) metadata

let all () =
Expand Down
64 changes: 32 additions & 32 deletions tool/ood-gen/lib/exercise.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,23 @@ type metadata = {
}
[@@deriving of_yaml]

let split_statement_statement (blocks : _ Omd.block list) =
let rec blocks_until_heading acc = function
| [] -> (List.rev acc, [])
| Omd.Heading (_, 1, _) :: _ as l -> (List.rev acc, l)
| el :: rest -> blocks_until_heading (el :: acc) rest
let get_title (h : Cmarkit.Block.Heading.t) =
let title =
Cmarkit.Inline.to_plain_text ~break_on_soft:false
(Cmarkit.Block.Heading.inline h)
in
let rec skip_non_heading_blocks = function
| [] -> []
| Omd.Heading (_, 1, _) :: _ as l -> l
| _ :: rest -> skip_non_heading_blocks rest
in
let err =
"The format of the statement file is not valid. Expected exactly two \
top-level headings: \"Solution\" and \"Statement\""
in
match skip_non_heading_blocks blocks with
| Omd.Heading (_, 1, Omd.Text (_, "Solution")) :: rest -> (
let solution_blocks, rest = blocks_until_heading [] rest in
match rest with
| Omd.Heading (_, 1, Omd.Text (_, "Statement")) :: rest -> (
let statements_blocks, rest = blocks_until_heading [] rest in
match rest with
| [] -> (statements_blocks, solution_blocks)
| _ -> raise (Exn.Decode_error err))
| _ -> raise (Exn.Decode_error err))
| _ -> raise (Exn.Decode_error err)
String.concat "\n" (List.map (String.concat "") title)

let split_statement_solution (body : string) =
match Str.split (Str.regexp {|#[ ]*Solution|}) body with
| [ _; statement_and_solution ] -> (
match
Str.split (Str.regexp {|#[ ]*Statement|}) statement_and_solution
with
| [ solution; statement ] ->
Ok (Cmarkit.Doc.of_string statement, Cmarkit.Doc.of_string solution)
| _ -> Error (`Msg "Failed to split on '# Statement' heading"))
| _ -> Error (`Msg "Failed to split on '# Solution' heading")

type t = {
title : string;
Expand All @@ -62,14 +53,23 @@ type t = {
stable_record ~version:metadata ~remove:[ statement; solution ],
show { with_path = false }]

let decode (_, (head, body)) =
let metadata = metadata_of_yaml head in
let statement_blocks, solution_blocks =
split_statement_statement (Omd.of_string body)
let attach_filepath fpath (`Msg m) = `Msg ("Error in file '" ^ fpath ^ "': " ^ m)

let decode (fpath, (head, body)) : (t, [> `Msg of string ]) result =
let ( let* ) = Result.bind in
let* metadata =
metadata_of_yaml head |> Result.map_error (attach_filepath fpath)
in
let* statement_doc, solution_doc =
split_statement_solution body |> Result.map_error (attach_filepath fpath)
in
let statement =
Cmarkit_html.of_doc ~safe:false (Hilite.Md.transform statement_doc)
in
let solution =
Cmarkit_html.of_doc ~safe:false (Hilite.Md.transform solution_doc)
in
let statement = Omd.to_html (Hilite.Md.transform statement_blocks) in
let solution = Omd.to_html (Hilite.Md.transform solution_blocks) in
Result.map (of_metadata ~statement ~solution) metadata
Ok (metadata |> of_metadata ~statement ~solution)

let all () = Utils.map_files decode "exercises/*.md"

Expand Down
4 changes: 3 additions & 1 deletion tool/ood-gen/lib/industrial_user.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ let of_metadata m = of_metadata m ~slug:(Utils.slugify m.name)

let decode (_, (head, body_md)) =
let metadata = metadata_of_yaml head in
let body_html = Omd.of_string body_md |> Omd.to_html in
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md |> Cmarkit_html.of_doc ~safe:true
in
Result.map (of_metadata ~body_md ~body_html) metadata

let all () = Utils.map_files decode "industrial_users"
Expand Down
11 changes: 7 additions & 4 deletions tool/ood-gen/lib/is_ocaml_yet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ type t = {

let decode (_, (head, body_md)) =
let metadata = metadata_of_yaml head in
let body_html = Omd.of_string body_md |> Omd.to_html in
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md |> Cmarkit_html.of_doc ~safe:true
in
Result.map
(fun (metadata : metadata) ->
let categories =
Expand All @@ -42,9 +44,10 @@ let decode (_, (head, body_md)) =
{
category with
description =
Omd.to_html
(Hilite.Md.transform
(Omd.of_string (String.trim category.description)));
Cmarkit.Doc.of_string ~strict:true
(String.trim category.description)
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false;
})
metadata.categories
in
Expand Down
4 changes: 3 additions & 1 deletion tool/ood-gen/lib/news.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ let decode (fname, (head, body)) =
let slug = Filename.basename (Filename.remove_extension fname) in
let metadata = metadata_of_yaml head in
let body_html =
Omd.to_html (Hilite.Md.transform (Omd.of_string (String.trim body)))
Cmarkit.Doc.of_string ~strict:true (String.trim body)
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false
in
Result.map (of_metadata ~slug ~body_html) metadata

Expand Down
7 changes: 5 additions & 2 deletions tool/ood-gen/lib/page.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ type t = {

let decode (file, (head, body_md)) =
let metadata = metadata_of_yaml head in
let omd = Omd.of_string body_md in
let body_html = Omd.to_html (Hilite.Md.transform omd) in
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false
in
let slug =
file |> Filename.basename |> Filename.remove_extension
|> String.map (function '_' -> '-' | c -> c)
Expand Down
7 changes: 5 additions & 2 deletions tool/ood-gen/lib/planet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ module Local = struct
let decode (fpath, (head, body)) =
let metadata = metadata_of_yaml head in
let body_html =
Omd.to_html (Hilite.Md.transform (Omd.of_string (String.trim body)))
Cmarkit.Doc.of_string ~strict:true (String.trim body)
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false
in
let source, slug =
match Str.split (Str.regexp_string "/") fpath with
Expand Down Expand Up @@ -191,7 +193,8 @@ module External = struct
let decode (fpath, (head, body)) =
let metadata = metadata_of_yaml head in
let body_html =
Omd.to_html (Hilite.Md.transform (Omd.of_string (String.trim body)))
Cmarkit.Doc.of_string ~strict:true (String.trim body)
|> Cmarkit_html.of_doc ~safe:true
in
let source =
match Str.split (Str.regexp_string "/") fpath with
Expand Down
14 changes: 11 additions & 3 deletions tool/ood-gen/lib/release.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,26 @@ type t = {

let of_metadata m =
of_metadata m ~intro_md:m.intro
~intro_html:(Omd.of_string m.intro |> Omd.to_html)
~intro_html:
(Cmarkit.Doc.of_string ~strict:true m.intro
|> Cmarkit_html.of_doc ~safe:true)
~highlights_md:m.highlights
~highlights_html:
(Omd.of_string m.highlights |> Hilite.Md.transform |> Omd.to_html)
(Cmarkit.Doc.of_string ~strict:true m.highlights
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false)

let sort_by_decreasing_version x y =
let to_list s = List.map int_of_string_opt @@ String.split_on_char '.' s in
compare (to_list y.version) (to_list x.version)

let decode (_, (head, body_md)) =
let metadata = metadata_of_yaml head in
let body_html = Omd.of_string body_md |> Hilite.Md.transform |> Omd.to_html in
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false
in
Result.map (of_metadata ~body_md ~body_html) metadata

let all () =
Expand Down
4 changes: 3 additions & 1 deletion tool/ood-gen/lib/success_story.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ let of_metadata m = of_metadata m ~slug:(Utils.slugify m.title)

let decode (_, (head, body_md)) =
let metadata = metadata_of_yaml head in
let body_html = Omd.of_string body_md |> Omd.to_html in
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md |> Cmarkit_html.of_doc ~safe:true
in
Result.map (of_metadata ~body_md ~body_html) metadata

let all () = Utils.map_files decode "success_stories"
Expand Down
Loading

0 comments on commit 9a07e66

Please sign in to comment.