diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-10 20:59:54 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-10 20:59:54 +0100 |
commit | 5e1249481b2e3fc27e845245a0c96c3687a23c3d (patch) | |
tree | ae8518c276aa6860755f6c2118e02d14b5f950e0 /src/Text/Pandoc | |
parent | c76eec97d4a8f78d3c1c212664364015a21b7404 (diff) | |
download | pandoc-5e1249481b2e3fc27e845245a0c96c3687a23c3d.tar.gz |
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Class.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/Error.hs | 11 | ||||
-rw-r--r-- | src/Text/Pandoc/Logging.hs | 76 | ||||
-rw-r--r-- | src/Text/Pandoc/Options.hs | 5 | ||||
-rw-r--r-- | src/Text/Pandoc/PDF.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/EPUB.hs | 3 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 3 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 1 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 1 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/TWiki.hs | 1 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Textile.hs | 1 |
11 files changed, 91 insertions, 19 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index df831c8b2..b1958510c 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -72,8 +72,8 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile , openURL ) import qualified Text.Pandoc.UTF8 as UTF8 import Text.Pandoc.Compat.Time (UTCTime) -import Text.Pandoc.Options (Verbosity(..)) -import Text.Parsec (ParsecT, SourcePos, getPosition) +import Text.Pandoc.Logging +import Text.Parsec (ParsecT, SourcePos) import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime) import Text.Pandoc.MIME (MimeType, getMimeType) import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs index b624f4cb0..55b2d981a 100644 --- a/src/Text/Pandoc/Error.hs +++ b/src/Text/Pandoc/Error.hs @@ -29,7 +29,9 @@ This module provides a standard way to deal with possible errors encounted during parsing. -} -module Text.Pandoc.Error (PandocError(..), handleError) where +module Text.Pandoc.Error ( + PandocError(..), + handleError) where import Text.Parsec.Error import Text.Parsec.Pos hiding (Line) @@ -47,13 +49,6 @@ data PandocError = PandocFileReadError FilePath | PandocParsecError Input ParseError deriving (Show, Typeable, Generic) - --- data PandocError = -- | Generic parse failure --- ParseFailure String --- -- | Error thrown by a Parsec parser --- | ParsecError Input ParseError --- deriving (Show, Typeable, Generic) - instance Exception PandocError -- | Handle PandocError by exiting with an error message. diff --git a/src/Text/Pandoc/Logging.hs b/src/Text/Pandoc/Logging.hs new file mode 100644 index 000000000..1272ff095 --- /dev/null +++ b/src/Text/Pandoc/Logging.hs @@ -0,0 +1,76 @@ +{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-} +{- +Copyright (C) 2016-17 John MacFarlane <jgm@berkeley.edu> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-} +{- | + Module : Text.Pandoc.Logging + Copyright : Copyright (C) 2006-2016 John MacFarlane + License : GNU GPL, version 2 or above + + Maintainer : John MacFarlane <jgm@berkeley.edu> + Stability : alpha + Portability : portable + +This module provides data types and functions for warnings +and info messages. + +-} +module Text.Pandoc.Logging ( + Verbosity(..) + , LogMessage(..) + , messageVerbosity + ) where + +import Text.Parsec.Pos +import Data.Data (Data) +import Data.Generics (Typeable) +import GHC.Generics (Generic) + +-- | Verbosity level. +data Verbosity = ERROR | WARNING | INFO | DEBUG + deriving (Show, Read, Eq, Data, Enum, Ord, Bounded, Typeable, Generic) + +data LogMessage = + SkippedInput String SourcePos + | NotRendered String + | YamlSectionNotAnObject SourcePos + | DuplicateLinkReference String SourcePos + | DuplicateNoteReference String SourcePos + | ParsingUnescaped String SourcePos + | DocxCommentWillNotRetainFormatting String + | CouldNotFetchResource String String + | CouldNotDetermineImageSize String + | CouldNotDetermineMimeType String + | CouldNotConvertTeXMath String + deriving (Show, Eq, Data, Ord, Typeable, Generic) + +messageVerbosity:: LogMessage -> Verbosity +messageVerbosity msg = + case msg of + SkippedInput{} -> INFO + NotRendered{} -> INFO + YamlSectionNotAnObject{} -> WARNING + DuplicateLinkReference{} -> WARNING + DuplicateNoteReference{} -> WARNING + ParsingUnescaped{} -> INFO + DocxCommentWillNotRetainFormatting{} -> INFO + CouldNotFetchResource{} -> WARNING + CouldNotDetermineImageSize{} -> WARNING + CouldNotDetermineMimeType{} -> WARNING + CouldNotConvertTeXMath{} -> WARNING + + diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs index 2e11a64d0..bc62f87d0 100644 --- a/src/Text/Pandoc/Options.hs +++ b/src/Text/Pandoc/Options.hs @@ -37,7 +37,6 @@ module Text.Pandoc.Options ( module Text.Pandoc.Extensions , HTMLSlideVariant (..) , EPUBVersion (..) , WrapOption (..) - , Verbosity (..) , TopLevelDivision (..) , WriterOptions (..) , TrackChanges (..) @@ -138,10 +137,6 @@ data ReferenceLocation = EndOfBlock -- ^ End of block | EndOfDocument -- ^ at end of document deriving (Show, Read, Eq, Data, Typeable, Generic) --- | Verbosity level. -data Verbosity = ERROR | WARNING | INFO | DEBUG - deriving (Show, Read, Eq, Data, Enum, Ord, Bounded, Typeable, Generic) - -- | Options for writers data WriterOptions = WriterOptions { writerTemplate :: Maybe String -- ^ Template to use diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs index b3bbcb4f5..1b3b4eb88 100644 --- a/src/Text/Pandoc/PDF.hs +++ b/src/Text/Pandoc/PDF.hs @@ -52,8 +52,8 @@ import Text.Pandoc.MediaBag import Text.Pandoc.Walk (walkM) import Text.Pandoc.Shared (warn, withTempDir, inDirectory, stringify) import Text.Pandoc.Writers.Shared (getField, metaToJSON) -import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), - Verbosity(..)) +import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..)) +import Text.Pandoc.Logging (Verbosity(..)) import Text.Pandoc.MIME (extensionFromMimeType, getMimeType) import Text.Pandoc.Process (pipeProcess) import Control.Monad.Trans (MonadIO(..)) diff --git a/src/Text/Pandoc/Readers/EPUB.hs b/src/Text/Pandoc/Readers/EPUB.hs index 851d4771f..49a035c37 100644 --- a/src/Text/Pandoc/Readers/EPUB.hs +++ b/src/Text/Pandoc/Readers/EPUB.hs @@ -12,7 +12,8 @@ import Text.XML.Light import Text.Pandoc.Definition hiding (Attr) import Text.Pandoc.Readers.HTML (readHtml) import Text.Pandoc.Walk (walk, query) -import Text.Pandoc.Options ( ReaderOptions(..), Verbosity(..)) +import Text.Pandoc.Options ( ReaderOptions(..)) +import Text.Pandoc.Logging (Verbosity(..)) import Text.Pandoc.Extensions (enableExtension, Extension(Ext_raw_html)) import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField) import Network.URI (unEscapeString) diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index a464847fb..c452d2acf 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -46,8 +46,9 @@ import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..)) import Text.Pandoc.Shared ( extractSpaces, renderTags', addMetaField , escapeURI, safeRead ) import Text.Pandoc.Options (ReaderOptions(readerExtensions), extensionEnabled, - Verbosity(..), Extension (Ext_epub_html_exts, + Extension (Ext_epub_html_exts, Ext_raw_html, Ext_native_divs, Ext_native_spans)) +import Text.Pandoc.Logging (Verbosity(..)) import Text.Pandoc.Parsing hiding ((<|>)) import Text.Pandoc.Walk import qualified Data.Map as M diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 0c10889d4..e35b70240 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -51,6 +51,7 @@ import qualified Text.Pandoc.UTF8 as UTF8 import qualified Data.Vector as V import Text.Pandoc.Builder (Inlines, Blocks, trimInlines) import Text.Pandoc.Options +import Text.Pandoc.Logging (Verbosity(..)) import Text.Pandoc.Shared import Text.Pandoc.Pretty (charWidth) import Text.Pandoc.XML (fromEntities) diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index b81d0f3e4..e70509bd1 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -41,6 +41,7 @@ import qualified Text.Pandoc.Builder as B import Text.Pandoc.Builder (Inlines, Blocks, trimInlines) import Data.Monoid ((<>)) import Text.Pandoc.Options +import Text.Pandoc.Logging (Verbosity(..)) import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag ) import Text.Pandoc.XML ( fromEntities ) import Text.Pandoc.Parsing hiding ( nested ) diff --git a/src/Text/Pandoc/Readers/TWiki.hs b/src/Text/Pandoc/Readers/TWiki.hs index 1a827bcd9..af9b38895 100644 --- a/src/Text/Pandoc/Readers/TWiki.hs +++ b/src/Text/Pandoc/Readers/TWiki.hs @@ -35,6 +35,7 @@ module Text.Pandoc.Readers.TWiki ( readTWiki import Text.Pandoc.Definition import qualified Text.Pandoc.Builder as B import Text.Pandoc.Options +import Text.Pandoc.Logging (Verbosity(..)) import Text.Pandoc.Parsing hiding (enclosed, macro, nested) import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag) import Control.Monad diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 07fb65b20..f404079ec 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -56,6 +56,7 @@ import Text.Pandoc.Definition import Text.Pandoc.Builder (Inlines, Blocks, trimInlines) import qualified Text.Pandoc.Builder as B import Text.Pandoc.Options +import Text.Pandoc.Logging (Verbosity(..)) import Text.Pandoc.Parsing import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isInlineTag ) import Text.Pandoc.Shared (trim) |