git.iko.soy/typeable/pandoc
on master help sign in
Added Text.Pandoc.Logging (exported module).

This now contains the Verbosity definition previously in Options, as well as a new LogMessage datatype that will eventually be used instead of raw strings for warnings. This will enable us, among other things, to provide machine-readable warnings if desired. See #3392.

commit5e1249481b2e3fc27e845245a0c96c3687a23c3d authorJohn MacFarlane <jgm@berkeley.edu> dateFri 10 Feb 2017, 20:59 (10 years ago) parentc76eec9
13 files changed+95−19
pandoc.cabal+1 src/Text/Pandoc.hs+3 src/Text/Pandoc/Class.hs+2−2 src/Text/Pandoc/Error.hs+3−8 src/Text/Pandoc/Logging.hs+76 src/Text/Pandoc/Options.hs−5 src/Text/Pandoc/PDF.hs+2−2 src/Text/Pandoc/Readers/EPUB.hs+2−1 src/Text/Pandoc/Readers/HTML.hs+2−1 src/Text/Pandoc/Readers/Markdown.hs+1 src/Text/Pandoc/Readers/MediaWiki.hs+1 src/Text/Pandoc/Readers/TWiki.hs+1 src/Text/Pandoc/Readers/Textile.hs+1
pandoc.cabal+1
@@ -392,6 +392,7 @@ Library
392392 Text.Pandoc.XML,
393393 Text.Pandoc.SelfContained,
394394 Text.Pandoc.Highlighting,
395+ Text.Pandoc.Logging,
395396 Text.Pandoc.Process,
396397 Text.Pandoc.MIME,
397398 Text.Pandoc.Class
src/Text/Pandoc.hs+3
@@ -58,6 +58,8 @@ module Text.Pandoc
5858 , module Text.Pandoc.Generic
5959 -- * Options
6060 , module Text.Pandoc.Options
61+ -- * Logging
62+ , module Text.Pandoc.Logging
6163 -- * Typeclass
6264 , PandocMonad
6365 , runIO
@@ -189,6 +191,7 @@ import Text.Pandoc.Writers.Custom
189191import Text.Pandoc.Writers.TEI
190192import Text.Pandoc.Templates
191193import Text.Pandoc.Options
194+import Text.Pandoc.Logging
192195import Text.Pandoc.Shared (safeRead, mapLeft, pandocVersion)
193196import Text.Pandoc.Error
194197import Text.Pandoc.Class
src/Text/Pandoc/Class.hs+2−2
@@ -72,8 +72,8 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile
7272 , openURL )
7373import qualified Text.Pandoc.UTF8 as UTF8
7474import Text.Pandoc.Compat.Time (UTCTime)
75−import Text.Pandoc.Options (Verbosity(..))
76−import Text.Parsec (ParsecT, SourcePos, getPosition)
75+import Text.Pandoc.Logging
76+import Text.Parsec (ParsecT, SourcePos)
7777import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
7878import Text.Pandoc.MIME (MimeType, getMimeType)
7979import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
src/Text/Pandoc/Error.hs+3−8
@@ -29,7 +29,9 @@ This module provides a standard way to deal with possible errors encounted
2929during parsing.
3030
3131-}
32−module Text.Pandoc.Error (PandocError(..), handleError) where
32+module Text.Pandoc.Error (
33+ PandocError(..),
34+ handleError) where
3335
3436import Text.Parsec.Error
3537import Text.Parsec.Pos hiding (Line)
@@ -47,13 +49,6 @@ data PandocError = PandocFileReadError FilePath
4749 | PandocParsecError Input ParseError
4850 deriving (Show, Typeable, Generic)
4951
50−
51−-- data PandocError = -- | Generic parse failure
52−-- ParseFailure String
53−-- -- | Error thrown by a Parsec parser
54−-- | ParsecError Input ParseError
55−-- deriving (Show, Typeable, Generic)
56−
5752instance Exception PandocError
5853
5954-- | Handle PandocError by exiting with an error message.
src/Text/Pandoc/Logging.hsnew file+76
@@ -0,0 +1,76 @@
1+{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
2+{-
3+Copyright (C) 2016-17 John MacFarlane <jgm@berkeley.edu>
4+
5+This program is free software; you can redistribute it and/or modify
6+it under the terms of the GNU General Public License as published by
7+the Free Software Foundation; either version 2 of the License, or
8+(at your option) any later version.
9+
10+This program is distributed in the hope that it will be useful,
11+but WITHOUT ANY WARRANTY; without even the implied warranty of
12+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+GNU General Public License for more details.
14+
15+You should have received a copy of the GNU General Public License
16+along with this program; if not, write to the Free Software
17+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+-}
19+{- |
20+ Module : Text.Pandoc.Logging
21+ Copyright : Copyright (C) 2006-2016 John MacFarlane
22+ License : GNU GPL, version 2 or above
23+
24+ Maintainer : John MacFarlane <jgm@berkeley.edu>
25+ Stability : alpha
26+ Portability : portable
27+
28+This module provides data types and functions for warnings
29+and info messages.
30+
31+-}
32+module Text.Pandoc.Logging (
33+ Verbosity(..)
34+ , LogMessage(..)
35+ , messageVerbosity
36+ ) where
37+
38+import Text.Parsec.Pos
39+import Data.Data (Data)
40+import Data.Generics (Typeable)
41+import GHC.Generics (Generic)
42+
43+-- | Verbosity level.
44+data Verbosity = ERROR | WARNING | INFO | DEBUG
45+ deriving (Show, Read, Eq, Data, Enum, Ord, Bounded, Typeable, Generic)
46+
47+data LogMessage =
48+ SkippedInput String SourcePos
49+ | NotRendered String
50+ | YamlSectionNotAnObject SourcePos
51+ | DuplicateLinkReference String SourcePos
52+ | DuplicateNoteReference String SourcePos
53+ | ParsingUnescaped String SourcePos
54+ | DocxCommentWillNotRetainFormatting String
55+ | CouldNotFetchResource String String
56+ | CouldNotDetermineImageSize String
57+ | CouldNotDetermineMimeType String
58+ | CouldNotConvertTeXMath String
59+ deriving (Show, Eq, Data, Ord, Typeable, Generic)
60+
61+messageVerbosity:: LogMessage -> Verbosity
62+messageVerbosity msg =
63+ case msg of
64+ SkippedInput{} -> INFO
65+ NotRendered{} -> INFO
66+ YamlSectionNotAnObject{} -> WARNING
67+ DuplicateLinkReference{} -> WARNING
68+ DuplicateNoteReference{} -> WARNING
69+ ParsingUnescaped{} -> INFO
70+ DocxCommentWillNotRetainFormatting{} -> INFO
71+ CouldNotFetchResource{} -> WARNING
72+ CouldNotDetermineImageSize{} -> WARNING
73+ CouldNotDetermineMimeType{} -> WARNING
74+ CouldNotConvertTeXMath{} -> WARNING
75+
76+
src/Text/Pandoc/Options.hs−5
@@ -37,7 +37,6 @@ module Text.Pandoc.Options ( module Text.Pandoc.Extensions
3737 , HTMLSlideVariant (..)
3838 , EPUBVersion (..)
3939 , WrapOption (..)
40− , Verbosity (..)
4140 , TopLevelDivision (..)
4241 , WriterOptions (..)
4342 , TrackChanges (..)
@@ -138,10 +137,6 @@ data ReferenceLocation = EndOfBlock -- ^ End of block
138137 | EndOfDocument -- ^ at end of document
139138 deriving (Show, Read, Eq, Data, Typeable, Generic)
140139
141−-- | Verbosity level.
142−data Verbosity = ERROR | WARNING | INFO | DEBUG
143− deriving (Show, Read, Eq, Data, Enum, Ord, Bounded, Typeable, Generic)
144−
145140-- | Options for writers
146141data WriterOptions = WriterOptions
147142 { writerTemplate :: Maybe String -- ^ Template to use
src/Text/Pandoc/PDF.hs+2−2
@@ -52,8 +52,8 @@ import Text.Pandoc.MediaBag
5252import Text.Pandoc.Walk (walkM)
5353import Text.Pandoc.Shared (warn, withTempDir, inDirectory, stringify)
5454import Text.Pandoc.Writers.Shared (getField, metaToJSON)
55−import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..),
56− Verbosity(..))
55+import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..))
56+import Text.Pandoc.Logging (Verbosity(..))
5757import Text.Pandoc.MIME (extensionFromMimeType, getMimeType)
5858import Text.Pandoc.Process (pipeProcess)
5959import Control.Monad.Trans (MonadIO(..))
src/Text/Pandoc/Readers/EPUB.hs+2−1
@@ -12,7 +12,8 @@ import Text.XML.Light
1212import Text.Pandoc.Definition hiding (Attr)
1313import Text.Pandoc.Readers.HTML (readHtml)
1414import Text.Pandoc.Walk (walk, query)
15−import Text.Pandoc.Options ( ReaderOptions(..), Verbosity(..))
15+import Text.Pandoc.Options ( ReaderOptions(..))
16+import Text.Pandoc.Logging (Verbosity(..))
1617import Text.Pandoc.Extensions (enableExtension, Extension(Ext_raw_html))
1718import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField)
1819import Network.URI (unEscapeString)
src/Text/Pandoc/Readers/HTML.hs+2−1
@@ -46,8 +46,9 @@ import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..))
4646import Text.Pandoc.Shared ( extractSpaces, renderTags', addMetaField
4747 , escapeURI, safeRead )
4848import Text.Pandoc.Options (ReaderOptions(readerExtensions), extensionEnabled,
49− Verbosity(..), Extension (Ext_epub_html_exts,
49+ Extension (Ext_epub_html_exts,
5050 Ext_raw_html, Ext_native_divs, Ext_native_spans))
51+import Text.Pandoc.Logging (Verbosity(..))
5152import Text.Pandoc.Parsing hiding ((<|>))
5253import Text.Pandoc.Walk
5354import qualified Data.Map as M
src/Text/Pandoc/Readers/Markdown.hs+1
@@ -51,6 +51,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
5151import qualified Data.Vector as V
5252import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
5353import Text.Pandoc.Options
54+import Text.Pandoc.Logging (Verbosity(..))
5455import Text.Pandoc.Shared
5556import Text.Pandoc.Pretty (charWidth)
5657import Text.Pandoc.XML (fromEntities)
src/Text/Pandoc/Readers/MediaWiki.hs+1
@@ -41,6 +41,7 @@ import qualified Text.Pandoc.Builder as B
4141import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
4242import Data.Monoid ((<>))
4343import Text.Pandoc.Options
44+import Text.Pandoc.Logging (Verbosity(..))
4445import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
4546import Text.Pandoc.XML ( fromEntities )
4647import Text.Pandoc.Parsing hiding ( nested )
src/Text/Pandoc/Readers/TWiki.hs+1
@@ -35,6 +35,7 @@ module Text.Pandoc.Readers.TWiki ( readTWiki
3535import Text.Pandoc.Definition
3636import qualified Text.Pandoc.Builder as B
3737import Text.Pandoc.Options
38+import Text.Pandoc.Logging (Verbosity(..))
3839import Text.Pandoc.Parsing hiding (enclosed, macro, nested)
3940import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag)
4041import Control.Monad
src/Text/Pandoc/Readers/Textile.hs+1
@@ -56,6 +56,7 @@ import Text.Pandoc.Definition
5656import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
5757import qualified Text.Pandoc.Builder as B
5858import Text.Pandoc.Options
59+import Text.Pandoc.Logging (Verbosity(..))
5960import Text.Pandoc.Parsing
6061import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isInlineTag )
6162import Text.Pandoc.Shared (trim)