Better HTML generation

This commit is contained in:
Denis Merigoux 2021-05-15 19:50:06 +02:00
parent f9b88e2259
commit 4d5c3191d7
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
3 changed files with 2095 additions and 2094 deletions

File diff suppressed because one or more lines are too long

View File

@ -137,7 +137,7 @@ let rec law_structure_to_html (language : C.backend_lang) (fmt : Format.formatte
| A.LawText t ->
let t = pre_html t in
if t = "" then () else Format.fprintf fmt "<p class='law-text'>%s</p>" t
| A.CodeBlock (_, c, _) ->
| A.CodeBlock (_, c, metadata) ->
let date = "\\d\\d/\\d\\d/\\d\\d\\d\\d" in
let syms = R.regexp (date ^ "|!=|<=|>=|--|->|\\*|\\/") in
let syms_subst = function
@ -151,11 +151,12 @@ let rec law_structure_to_html (language : C.backend_lang) (fmt : Format.formatte
| s -> s
in
let pprinted_c = R.substitute ~rex:syms ~subst:syms_subst (Pos.unmark c) in
Format.fprintf fmt "<div class='code-wrapper'>\n<div class='filename'>%s</div>\n%s\n</div>"
Format.fprintf fmt "<div class='code-wrapper%s'>\n<div class='filename'>%s</div>\n%s\n</div>"
(if metadata then " code-metadata" else "")
(Pos.get_file (Pos.get_position c))
(pygmentize_code (Pos.same_pos_as ("```catala" ^ pprinted_c ^ "```") c) language)
| A.LawHeading (heading, children) ->
let h_number = heading.law_heading_precedence + 2 in
let h_number = heading.law_heading_precedence + 1 in
Format.fprintf fmt "<h%d class='law-heading'><a href='%s'>%s</a></h%d>\n" h_number
(match (heading.law_heading_id, language) with
| Some id, `Fr ->

View File

@ -29,7 +29,7 @@ let get_law_heading (lexbuf : lexbuf) : token =
in
let get_substring = R.get_substring (R.exec ~rex:extract_article_title (Utf8.lexeme lexbuf)) in
let title = String.trim (get_substring 2) in
let article_id = try Some (get_substring 4) with Not_found -> None in
let article_expiration_date = try Some (get_substring 6) with Not_found -> None in
let precedence = calc_precedence (get_substring 1) in
let article_id = try Some (String.trim (get_substring 4)) with Not_found -> None in
let article_expiration_date = try Some (String.trim (get_substring 6)) with Not_found -> None in
let precedence = calc_precedence (String.trim (get_substring 1)) in
LAW_HEADING (title, article_id, article_expiration_date, precedence)