diff --git a/TODO.md b/TODO.md index 291989d..2c2ec02 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,9 @@ I'm beginning to evaluate the state of this branch for its eventually merger into main. I will collect here the bugs that I notice, which you can remove once they are fixed or otherwise invalidated. -- [ ] Atom feed renderer should not use
element!!! It needs to use

,

, etc. +- [~] Atom feed renderer should not use
element!!! It needs to use

,

, etc. + + (JMS: I did a quick fix, but this is maybe not the best. Feel free to change.) - [ ] Tests fail on macOS. I think you must be using some platform-dependent options to grep or something. UPDATED OUTPUT: diff --git a/lib/frontend/Atom_client.ml b/lib/frontend/Atom_client.ml index e93cd5b..a0b2446 100644 --- a/lib/frontend/Atom_client.ml +++ b/lib/frontend/Atom_client.ml @@ -125,7 +125,7 @@ let get_embedded_articles (forest : State.t) (article : _ T.article) = let render_entry ~(forest : State.t) ?(scope : URI.t option) (article : T.content T.article) : P.node = - let article_div = Html_client.render_article_as_div ~forest article in + let article_div = Html_client.render_article_for_atom ~forest article in A.entry [] [ render_title forest ?scope article.frontmatter; diff --git a/lib/frontend/Html_client.ml b/lib/frontend/Html_client.ml index 1488840..9061d73 100644 --- a/lib/frontend/Html_client.ml +++ b/lib/frontend/Html_client.ml @@ -24,6 +24,7 @@ open struct [@@deriving repr] end + type 'a control = | Transclusion : T.transclusion -> T.transclusion control | Link : T.(content link) -> T.(content link) control @@ -46,9 +47,14 @@ type env = { in_backmatter: bool; numbered: bool; mode: mode; + simple_headers: bool; + section_depth: int; mainmatter_cache: mainmatter_cache; } +let hx ~env attrs children = + P.std_tag (Format.sprintf "h%i" @@ min 6 env.section_depth) attrs children + let is_counted : T.section_flags -> _ = fun T.{included_in_toc; numbered; _} -> included_in_toc && numbered @@ -276,6 +282,8 @@ and default_env ~forest = in_backmatter = false; mode = Static; numbered = true; + simple_headers = false; + section_depth = 1; mainmatter_cache = create_mainmatter_cache (); } @@ -736,6 +744,7 @@ and render_section ~env ?(numbered = false) in if hidden_when_empty && mainmatter = T.Content [] then H.null [] else + let mainmatter_env = {env with section_depth = env.section_depth + 1} in H.section [ (let base = @@ -745,19 +754,29 @@ and render_section ~env ?(numbered = false) taxon_attr; ] [ - (if Loop_detection.have_seen_uri_opt frontmatter.uri env.loops then - P.txt "Transclusion loop detected, rendering stopped." - else if header_shown then - H.details - [open_; H.id "%s" @@ stable_id_of_frontmatter frontmatter] - [ - H.summary [] [render_frontmatter ~numbered ~env frontmatter]; - H.div - [H.class_ "mainmatter"] - (render_mainmatter ~env ~numbered frontmatter mainmatter - @ [render_bibtex ~env frontmatter]); - ] - else H.null @@ render_content ~env mainmatter); + if Loop_detection.have_seen_uri_opt frontmatter.uri env.loops then + P.txt "Transclusion loop detected, rendering stopped." + else if header_shown then + if env.simple_headers then + H.null [ + begin match frontmatter.title with + | None -> H.null [] + | Some title -> H.header [] [hx ~env [] @@ render_content ~env title] + end; + H.null @@ render_mainmatter ~env:mainmatter_env ~numbered frontmatter mainmatter + ] + else + H.details + [open_; H.id "%s" @@ stable_id_of_frontmatter frontmatter] + [ + H.summary [] [render_frontmatter ~numbered ~env frontmatter]; + H.div + [H.class_ "mainmatter"] + (render_mainmatter ~env:mainmatter_env ~numbered frontmatter mainmatter + @ [render_bibtex ~env frontmatter]); + ] + else + H.null @@ render_content ~env mainmatter; ] (* NOTE: There is a little problem when rendering the backmatter. We want @@ -833,6 +852,7 @@ let render_article ~env (article : T.content T.article) : P.node = ~env: { env with + section_depth = env.section_depth + 1; loops = Loop_detection.add_seen_uri_opt article.frontmatter.uri env.loops; @@ -846,10 +866,10 @@ let render_article ~env (article : T.content T.article) : P.node = ] (* Just used by the atom client *) -let render_article_as_div ~(forest : State.t) (article : T.content T.article) : +let render_article_for_atom ~(forest : State.t) (article : T.content T.article) : P.node = let reserved = [{prefix = ""; xmlns = "http://www.w3.org/1999/xhtml"}] in - let env = {(default_env ~forest) with scope = article.frontmatter.uri} in + let env = {(default_env ~forest) with scope = article.frontmatter.uri; simple_headers = true; section_depth = 2} in H.div (List.map render_xmlns_prefix reserved) [H.null @@ render_content ~env article.mainmatter] diff --git a/lib/frontend/Html_client.mli b/lib/frontend/Html_client.mli index df50d91..86316e6 100644 --- a/lib/frontend/Html_client.mli +++ b/lib/frontend/Html_client.mli @@ -22,6 +22,8 @@ type env = { in_backmatter: bool; numbered: bool; mode: Forester_core.mode; + simple_headers: bool; + section_depth: int; mainmatter_cache: mainmatter_cache; } @@ -30,7 +32,7 @@ val dynamic_env : forest:Forester_compiler.State.t -> env val render_content : env:env -> T.content -> P.node list -val render_article_as_div : +val render_article_for_atom : forest:Forester_compiler.State.t -> T.content T.article -> P.node val render_toc : env:env -> T.content -> P.node list