1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 00:44:57 +03:00

Merge pull request #1168 from github/drop-section-heading-punctuation-from-table-of-contents

Exclude heading punctuation from Markdown ToC
This commit is contained in:
Rob Rix 2017-06-16 11:16:39 -04:00 committed by GitHub
commit 1e0d3e6251

View File

@ -21,6 +21,7 @@ import Data.Align (crosswalk)
import Data.Functor.Both hiding (fst, snd) import Data.Functor.Both hiding (fst, snd)
import qualified Data.Functor.Both as Both import qualified Data.Functor.Both as Both
import Data.Functor.Listable import Data.Functor.Listable
import Data.List.NonEmpty (nonEmpty)
import Data.Proxy import Data.Proxy
import Data.Record import Data.Record
import Data.Text (toLower) import Data.Text (toLower)
@ -114,12 +115,12 @@ declarationAlgebra proxy source r
where getSource = toText . flip Source.slice source . byteRange . extract where getSource = toText . flip Source.slice source . byteRange . extract
-- | Compute 'Declaration's with the headings of 'Markup.Section's. -- | 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 => Proxy error
-> Source -> Source
-> RAlgebra (TermF (Union fs) (Record fields)) (Term (Union fs) (Record fields)) (Maybe Declaration) -> RAlgebra (TermF (Union fs) (Record fields)) (Term (Union fs) (Record fields)) (Maybe Declaration)
markupSectionAlgebra proxy source r 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)) | Just (Syntax.Error err) <- prj (tailF r) = Just $ ErrorDeclaration (show (err `asProxyTypeOf` proxy))
| otherwise = Nothing | otherwise = Nothing
where getSource = toText . flip Source.slice source . byteRange . extract where getSource = toText . flip Source.slice source . byteRange . extract