git.iko.soy/typeable/pandoc
on master help sign in
Org reader: replace ugly code with view pattern

Some less-than-smart code required a pragma switching of overlapping pattern warnings in order to compile seamlessly. Using view patterns makes the code easier to read and also doesn't require overlapping pattern checks to be disabled.

commitf417fecf5fc60ae6c600be9f71bf0deef60a4113 authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 4 Jul 2016, 11:20 (10 years ago) parente548b8d
1 file changed+4−5
src/Text/Pandoc/Readers/Org/Blocks.hs+4−5
src/Text/Pandoc/Readers/Org/Blocks.hs+4−5
@@ -1,6 +1,6 @@
11{-# LANGUAGE FlexibleContexts #-}
22{-# LANGUAGE RecordWildCards #-}
3−{-# OPTIONS_GHC -fno-warn-overlapping-patterns #-}
3+{-# LANGUAGE ViewPatterns #-}
44{-
55Copyright (C) 2014-2016 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
66
@@ -54,7 +54,6 @@ import Data.Char ( isSpace, toLower, toUpper)
5454import Data.List ( foldl', intersperse, isPrefixOf )
5555import qualified Data.Map as M
5656import Data.Maybe ( fromMaybe, isNothing )
57−import qualified Data.Sequence as S
5857import Network.HTTP ( urlEncode )
5958
6059--
@@ -142,7 +141,7 @@ headlineToBlocks hdln@(Headline {..}) = do
142141 _ | any isArchiveTag headlineTags -> archivedHeadlineToBlocks hdln
143142 _ | isCommentTitle headlineText -> return mempty
144143 _ | headlineLevel >= maxHeadlineLevels -> headlineToHeaderWithList hdln
145− _ -> headlineToHeaderWithContents hdln
144+ _ | otherwise -> headlineToHeaderWithContents hdln
146145
147146isNoExportTag :: Tag -> Bool
148147isNoExportTag = (== toTag "noexport")
@@ -154,8 +153,8 @@ isArchiveTag = (== toTag "ARCHIVE")
154153-- FIXME: This accesses builder internals not intended for use in situations
155154-- like these. Replace once keyword parsing is supported.
156155isCommentTitle :: Inlines -> Bool
157−isCommentTitle xs = (B.Many . S.take 1 . B.unMany) xs == B.str "COMMENT"
158−isCommentTitle _ = False
156+isCommentTitle (B.toList -> (Str "COMMENT":_)) = True
157+isCommentTitle _ = False
159158
160159archivedHeadlineToBlocks :: Headline -> OrgParser Blocks
161160archivedHeadlineToBlocks hdln = do