commit 3b63e7ef20ed4c403d077c674b80ab72a3283f5b
parent ed207ac8c4c3b6a99b4bd6901bce025f36015827
Author: Andrew Laack <andrew@laack.co>
Date: Tue, 8 Sep 2026 21:36:41 -0500
fmt
Diffstat:
5 files changed, 42 insertions(+), 33 deletions(-)
diff --git a/learning/lib/parser.ml b/learning/lib/parser.ml
@@ -12,7 +12,9 @@ type line_format =
| Link
| ListItem
-(** [line_format_map format] returns a pair where the first element is the [format] as a string and the second element is the number of characters that format removes from the prefix of a line. *)
+(** [line_format_map format] returns a pair where the first element is the
+ [format] as a string and the second element is the number of characters that
+ format removes from the prefix of a line. *)
let line_format_map format =
match format with
| Normal -> ("Normal", 0)
@@ -26,22 +28,27 @@ let line_format_map format =
| Link -> ("Link", 3)
| ListItem -> ("ListItem", 2)
-(** [line_format_str format] takes as input a line format pair and returns the string element. *)
+(** [line_format_str format] takes as input a line format pair and returns the
+ string element. *)
let line_format_str format = fst (line_format_map format)
-(** [line_format_char_cut format] takes as input a line format pair and returns the element describing how many characters to cut from the prefix of the line. *)
+(** [line_format_char_cut format] takes as input a line format pair and returns
+ the element describing how many characters to cut from the prefix of the
+ line. *)
let line_format_char_cut format = snd (line_format_map format)
type page_line = { content : string; line_type : line_format }
-(** [permute_line line line_type] returns a copy of the [line] after applying the corresponding changes the [line_type] imparts on lines of that format. *)
+(** [permute_line line line_type] returns a copy of the [line] after applying
+ the corresponding changes the [line_type] imparts on lines of that format.
+*)
let permute_line line line_type =
let cut = line_format_char_cut line_type in
String.sub line cut (String.length line - cut)
-let match_prefix_not_formatted line prefix preformatted =
- if prefix = "" then preformatted else
- ((not preformatted) && Shared.match_on_prefix line prefix)
+let match_prefix_not_formatted line prefix preformatted =
+ if prefix = "" then preformatted
+ else (not preformatted) && Shared.match_on_prefix line prefix
let get_line_type line preformatted =
let funs =
@@ -49,7 +56,7 @@ let get_line_type line preformatted =
(Hidden, "?? ");
(Preformatted, "");
(ListItem, "* ");
- (Quote, "> ");
+ (Quote, "> ");
(Embedded, "=>e ");
(Link, "=> ");
(HeaderL1, "# ");
@@ -57,7 +64,11 @@ let get_line_type line preformatted =
(HeaderL3, "### ");
]
in
- let lt = List.find_opt (fun (_, pre) -> match_prefix_not_formatted line pre preformatted) funs in
+ let lt =
+ List.find_opt
+ (fun (_, pre) -> match_prefix_not_formatted line pre preformatted)
+ funs
+ in
match lt with Some v -> fst v | None -> Normal
let parse_simple_line line preformatted =
diff --git a/learning/lib/render.ml b/learning/lib/render.ml
@@ -7,24 +7,24 @@ open Jingoo
let to_tval value = Jg_types.Tobj [ ("name", Jg_types.Tstr value) ]
let get_pages_in_order course_name =
- if Shared.is_directory (Shared.course_dir ^ course_name) then
- let arr = Sys.readdir (Shared.course_dir ^ course_name) in
- Array.sort compare arr;
- let lst : string list =
- List.filter Basic_functions.has_sl_postfix (Array.to_list arr)
- in
- lst
- else []
+ if Shared.is_directory (Shared.course_dir ^ course_name) then (
+ let arr = Sys.readdir (Shared.course_dir ^ course_name) in
+ Array.sort compare arr;
+ let lst : string list =
+ List.filter Basic_functions.has_sl_postfix (Array.to_list arr)
+ in
+ lst)
+ else []
let get_course_home course_name =
List.map to_tval (get_pages_in_order course_name)
let get_course_array () =
- if Shared.is_directory (Shared.course_dir) then
- let arr = Sys.readdir Shared.course_dir in
- Array.sort compare arr;
- arr
- else Array.make 0 ""
+ if Shared.is_directory Shared.course_dir then (
+ let arr = Sys.readdir Shared.course_dir in
+ Array.sort compare arr;
+ arr)
+ else Array.make 0 ""
let get_courses () =
let arr = get_course_array () in
diff --git a/learning/lib/shared.ml b/learning/lib/shared.ml
@@ -2,12 +2,12 @@
let course_dir =
if Array.length Sys.argv > 1 then Sys.argv.(1) ^ "/" else "./test_courses/"
-
let is_file filename = if Sys.file_exists filename then true else false
let is_directory path =
if Sys.file_exists path then if Sys.is_directory path then true else false
else false
-let match_on_prefix s prefix =
- (String.length s >= String.length prefix) && (String.sub s 0 (String.length prefix) = prefix)
+let match_on_prefix s prefix =
+ String.length s >= String.length prefix
+ && String.sub s 0 (String.length prefix) = prefix
diff --git a/learning/lib/templates.ml b/learning/lib/templates.ml
@@ -18,10 +18,10 @@ let course_page_jingoo =
\ <li>{{line.content}}</li>\n\
\ {% else if line.line_type == \"Link\"%}\n\
\ <content-block>\n\
- \ <p>
- \ <a href=\"{{line.content}}\">{{line.content}}</a>\n\
- \ </p>
- \ </content-block>\n\
+ \ <p>\n\
+ \ <a href=\"{{line.content}}\">{{line.content}}</a>\n\
+ \ </p>\n\
+ \ </content-block>\n\
\ {% else if line.line_type == \"Hidden\"%}\n\
\ <details>\n\
\ <summary>{{line.content}}</summary>\n\
diff --git a/learning/test/test_line_parsing.ml b/learning/test/test_line_parsing.ml
@@ -1,10 +1,8 @@
open Learning
-
let test_line_parsing () =
-
- assert ((Parser.get_line_type "" true) = Preformatted);
- assert ((Parser.get_line_type "" false) = Normal);
+ assert (Parser.get_line_type "" true = Preformatted);
+ assert (Parser.get_line_type "" false = Normal);
(* Line-based type tests.*)
(* Only ``` is a format line, no additional characters.*)