diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-11-28 13:06:48 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-11-28 13:10:07 +0100 |
commit | 739c0d06b63bed7619b39eb189c5e5a34fd8da49 (patch) | |
tree | 0c4c0f39ccce82f5a325045db3c043c699e5c907 /app/Issue | |
parent | c138fb9910c661f7efd00cc7dceb6fc68dc790a9 (diff) |
editing issues preserves comment style
Diffstat (limited to 'app/Issue')
-rw-r--r-- | app/Issue/Text.hs | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/app/Issue/Text.hs b/app/Issue/Text.hs index 5d1dddb..4cfc5f7 100644 --- a/app/Issue/Text.hs +++ b/app/Issue/Text.hs @@ -6,52 +6,17 @@ module Issue.Text where import Control.Arrow (first, second) -import Data.List (find) -import Data.Maybe (fromMaybe) import Data.Text (Text) import Data.Text qualified as T -import TreeGrepper.FileType (FileType) -import TreeGrepper.FileType qualified as G -extractText :: FileType -> Text -> (Text, Maybe Text) -extractText fileType rawText = (title, description) +extractText :: Text -> (Text, Maybe Text) +extractText text = (title, description) where - text = stripComments fileType $ stripLines rawText - stripLines = T.intercalate "\n" . map T.strip . T.lines (title, description') = second T.stripStart $ T.breakOn "\n" text description | T.null description' = Nothing | otherwise = Just description' -stripComments :: G.FileType -> Text -> Text -stripComments fileType text = - maybe - (stripLineComments (G.info fileType).lineStart text) - ( \(blockInfo, blockStart) -> - stripBlockComment blockStart blockInfo.blockEnd text - ) - $ do - blockInfo <- (G.info fileType).block - (,) blockInfo <$> find (`T.isPrefixOf` text) blockInfo.blockStart - -stripLineComments :: Text -> Text -> Text -stripLineComments lineStart text = - onLines - ( \line -> - fromMaybe line . fmap T.stripStart $ - T.stripPrefix lineStart line - ) - text - where - onLines f = T.intercalate "\n" . map f . T.lines - -stripBlockComment :: Text -> Text -> Text -> Text -stripBlockComment blockStart blockEnd text = - T.strip - . (fromMaybe text . T.stripSuffix blockEnd) - . (fromMaybe text . T.stripPrefix blockStart) - $ text - issueMarkers :: [T.Text] issueMarkers = [ "TODO", |