Fix front matter regexp and catch String.sub exception

This commit is contained in:
Stavros Polymenis 2017-11-15 22:04:50 +00:00
parent ce1f3e3a3b
commit f8ab384f0d

View File

@ -39,10 +39,13 @@ let front_matter_body_split s =
List.(nth l 0, nth l 1)
| _ ->
if Re_str.(string_match (regexp ".*:.*")) s 0
then match Re_str.(bounded_split (regexp "^\n\n")) s 2 with
then match Re_str.(bounded_split (regexp "\n\n")) s 2 with
| front::body::[] -> (front, body)
| _ -> ("", s)
else ("", s)
| exception Invalid_argument _ ->
prerr_endline @@ "Not enough characters in: " ^ s;
("", s)
let of_string s =
let (front_matter, body) = front_matter_body_split s in