module Issue.Text ( extractText, stripIssueMarkers, issueMarkers, ) where import Control.Arrow (first, second) import Data.Text (Text) import Data.Text qualified as T extractText :: Text -> (Text, Maybe Text) extractText text = (title, description) where (title, description') = second T.stripStart $ T.breakOn "\n" text description | T.null description' = Nothing | otherwise = Just description' issueMarkers :: [T.Text] issueMarkers = [ "TODO", "FIXME", "QUESTION" ] stripIssueMarkers :: T.Text -> ([T.Text], T.Text) stripIssueMarkers text = case [marker | marker <- issueMarkers, T.isPrefixOf marker text] of (marker : _) -> first (marker :) . stripIssueMarkers $ T.stripStart (T.drop (T.length marker) text) [] -> ([], text)