From e11b56127fa47cb42714a501c155f4729eab44ab Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 16 Jun 2017 10:59:23 -0400 Subject: [PATCH] =?UTF-8?q?Take=20the=20range=20of=20headings=E2=80=99=20c?= =?UTF-8?q?hildren=20instead=20of=20the=20whole=20heading.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don’t want to include the ## in a section entry, so we union the ranges of the children (if any). --- src/Renderer/TOC.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index 923c02659..045678db7 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -21,6 +21,7 @@ import Data.Align (crosswalk) import Data.Functor.Both hiding (fst, snd) import qualified Data.Functor.Both as Both import Data.Functor.Listable +import Data.List.NonEmpty (nonEmpty) import Data.Proxy import Data.Record import Data.Text (toLower) @@ -114,12 +115,12 @@ declarationAlgebra proxy source r where getSource = toText . flip Source.slice source . byteRange . extract -- | Compute 'Declaration's with the headings of 'Markup.Section's. -markupSectionAlgebra :: (Markup.Section :< fs, Syntax.Error error :< fs, HasField fields Range, Show error, Functor (Union fs)) +markupSectionAlgebra :: (Markup.Section :< fs, Syntax.Error error :< fs, HasField fields Range, Show error, Functor (Union fs), Foldable (Union fs)) => Proxy error -> Source -> RAlgebra (TermF (Union fs) (Record fields)) (Term (Union fs) (Record fields)) (Maybe Declaration) markupSectionAlgebra proxy source r - | Just (Markup.Section (heading, _) _) <- prj (tailF r) = Just $ SectionDeclaration (getSource heading) + | Just (Markup.Section (heading, _) _) <- prj (tailF r) = Just $ SectionDeclaration (maybe (getSource heading) (toText . flip Source.slice source . sconcat) (nonEmpty (byteRange . extract <$> toList (unwrap heading)))) | Just (Syntax.Error err) <- prj (tailF r) = Just $ ErrorDeclaration (show (err `asProxyTypeOf` proxy)) | otherwise = Nothing where getSource = toText . flip Source.slice source . byteRange . extract