git.iko.soy/typeable/pandoc
on master help sign in
Logging: Added NoLangSpecified, use toConstr to avoid boilerplate.
11e57c4John MacFarlane
src/Text/Pandoc/Logging.hs+30−42
@@ -43,7 +43,7 @@ import Data.Aeson
43import Data.Aeson.Encode.Pretty (Config (..), defConfig, encodePretty',
43import Data.Aeson.Encode.Pretty (Config (..), defConfig, encodePretty',
44 keyOrder)
44 keyOrder)
45import qualified Data.ByteString.Lazy as BL
45import qualified Data.ByteString.Lazy as BL
46−import Data.Data (Data)
46+import Data.Data (Data, toConstr)
47import Data.Generics (Typeable)
47import Data.Generics (Typeable)
48import qualified Data.Text as Text
48import qualified Data.Text as Text
49import GHC.Generics (Generic)
49import GHC.Generics (Generic)
@@ -78,102 +78,86 @@ data LogMessage =
78 | CouldNotParseCSS String
78 | CouldNotParseCSS String
79 | Fetching String
79 | Fetching String
80 | NoTitleElement String
80 | NoTitleElement String
81+ | NoLangSpecified
81 deriving (Show, Eq, Data, Ord, Typeable, Generic)
82 deriving (Show, Eq, Data, Ord, Typeable, Generic)
82
83
83instance ToJSON LogMessage where
84instance ToJSON LogMessage where
85+ toJSON x = object $
84− toJSON x = object $ "verbosity" .= toJSON (messageVerbosity x) :
86+ "verbosity" .= toJSON (messageVerbosity x) :
87+ "type" .= toJSON (show $ toConstr x) :
85 case x of
88 case x of
86 SkippedContent s pos ->
89 SkippedContent s pos ->
87− ["type" .= String "SkippedContent",
88− "contents" .= Text.pack s,
90+ ["contents" .= Text.pack s,
89 "source" .= Text.pack (sourceName pos),
91 "source" .= Text.pack (sourceName pos),
90 "line" .= sourceLine pos,
92 "line" .= sourceLine pos,
91 "column" .= sourceColumn pos]
93 "column" .= sourceColumn pos]
92 CouldNotParseYamlMetadata s pos ->
94 CouldNotParseYamlMetadata s pos ->
93− ["type" .= String "YamlSectionNotAnObject",
94− "message" .= Text.pack s,
95+ ["message" .= Text.pack s,
95 "source" .= Text.pack (sourceName pos),
96 "source" .= Text.pack (sourceName pos),
96 "line" .= toJSON (sourceLine pos),
97 "line" .= toJSON (sourceLine pos),
97 "column" .= toJSON (sourceColumn pos)]
98 "column" .= toJSON (sourceColumn pos)]
98 DuplicateLinkReference s pos ->
99 DuplicateLinkReference s pos ->
99− ["type" .= String "DuplicateLinkReference",
100− "contents" .= Text.pack s,
100+ ["contents" .= Text.pack s,
101 "source" .= Text.pack (sourceName pos),
101 "source" .= Text.pack (sourceName pos),
102 "line" .= toJSON (sourceLine pos),
102 "line" .= toJSON (sourceLine pos),
103 "column" .= toJSON (sourceColumn pos)]
103 "column" .= toJSON (sourceColumn pos)]
104 DuplicateNoteReference s pos ->
104 DuplicateNoteReference s pos ->
105− ["type" .= String "DuplicateNoteReference",
106− "contents" .= Text.pack s,
105+ ["contents" .= Text.pack s,
107 "source" .= Text.pack (sourceName pos),
106 "source" .= Text.pack (sourceName pos),
108 "line" .= toJSON (sourceLine pos),
107 "line" .= toJSON (sourceLine pos),
109 "column" .= toJSON (sourceColumn pos)]
108 "column" .= toJSON (sourceColumn pos)]
110 ReferenceNotFound s pos ->
109 ReferenceNotFound s pos ->
111− ["type" .= String "ReferenceNotFound",
112− "contents" .= Text.pack s,
110+ ["contents" .= Text.pack s,
113 "source" .= Text.pack (sourceName pos),
111 "source" .= Text.pack (sourceName pos),
114 "line" .= toJSON (sourceLine pos),
112 "line" .= toJSON (sourceLine pos),
115 "column" .= toJSON (sourceColumn pos)]
113 "column" .= toJSON (sourceColumn pos)]
116 CircularReference s pos ->
114 CircularReference s pos ->
117− ["type" .= String "CircularReference",
118− "contents" .= Text.pack s,
115+ ["contents" .= Text.pack s,
119 "source" .= Text.pack (sourceName pos),
116 "source" .= Text.pack (sourceName pos),
120 "line" .= toJSON (sourceLine pos),
117 "line" .= toJSON (sourceLine pos),
121 "column" .= toJSON (sourceColumn pos)]
118 "column" .= toJSON (sourceColumn pos)]
122 ParsingUnescaped s pos ->
119 ParsingUnescaped s pos ->
123− ["type" .= String "ParsingUnescaped",
124− "contents" .= Text.pack s,
120+ ["contents" .= Text.pack s,
125 "source" .= Text.pack (sourceName pos),
121 "source" .= Text.pack (sourceName pos),
126 "line" .= toJSON (sourceLine pos),
122 "line" .= toJSON (sourceLine pos),
127 "column" .= toJSON (sourceColumn pos)]
123 "column" .= toJSON (sourceColumn pos)]
128 CouldNotLoadIncludeFile fp pos ->
124 CouldNotLoadIncludeFile fp pos ->
129− ["type" .= String "CouldNotLoadIncludeFile",
130− "path" .= Text.pack fp,
125+ ["path" .= Text.pack fp,
131 "source" .= Text.pack (sourceName pos),
126 "source" .= Text.pack (sourceName pos),
132 "line" .= toJSON (sourceLine pos),
127 "line" .= toJSON (sourceLine pos),
133 "column" .= toJSON (sourceColumn pos)]
128 "column" .= toJSON (sourceColumn pos)]
134 ParsingTrace s pos ->
129 ParsingTrace s pos ->
135− ["type" .= String "ParsingTrace",
136− "contents" .= Text.pack s,
130+ ["contents" .= Text.pack s,
137 "source" .= Text.pack (sourceName pos),
131 "source" .= Text.pack (sourceName pos),
138 "line" .= sourceLine pos,
132 "line" .= sourceLine pos,
139 "column" .= sourceColumn pos]
133 "column" .= sourceColumn pos]
140 InlineNotRendered il ->
134 InlineNotRendered il ->
141− ["type" .= String "InlineNotRendered",
142− "contents" .= toJSON il]
135+ ["contents" .= toJSON il]
143 BlockNotRendered bl ->
136 BlockNotRendered bl ->
144− ["type" .= String "BlockNotRendered",
145− "contents" .= toJSON bl]
137+ ["contents" .= toJSON bl]
146 DocxParserWarning s ->
138 DocxParserWarning s ->
147− ["type" .= String "DocxParserWarning",
148− "contents" .= Text.pack s]
139+ ["contents" .= Text.pack s]
149 CouldNotFetchResource fp s ->
140 CouldNotFetchResource fp s ->
150− ["type" .= String "CouldNotFetchResource",
151− "path" .= Text.pack fp,
141+ ["path" .= Text.pack fp,
152 "message" .= Text.pack s]
142 "message" .= Text.pack s]
153 CouldNotDetermineImageSize fp s ->
143 CouldNotDetermineImageSize fp s ->
154− ["type" .= String "CouldNotDetermineImageSize",
155− "path" .= Text.pack fp,
144+ ["path" .= Text.pack fp,
156 "message" .= Text.pack s]
145 "message" .= Text.pack s]
157 CouldNotConvertImage fp s ->
146 CouldNotConvertImage fp s ->
158− ["type" .= String "CouldNotConvertImage",
159− "path" .= Text.pack fp,
147+ ["path" .= Text.pack fp,
160 "message" .= Text.pack s]
148 "message" .= Text.pack s]
161 CouldNotDetermineMimeType fp ->
149 CouldNotDetermineMimeType fp ->
162− ["type" .= String "CouldNotDetermineMimeType",
163− "path" .= Text.pack fp]
150+ ["path" .= Text.pack fp]
164 CouldNotConvertTeXMath s msg ->
151 CouldNotConvertTeXMath s msg ->
165− ["type" .= String "CouldNotConvertTeXMath",
166− "contents" .= Text.pack s,
152+ ["contents" .= Text.pack s,
167 "message" .= Text.pack msg]
153 "message" .= Text.pack msg]
168 CouldNotParseCSS msg ->
154 CouldNotParseCSS msg ->
169− ["type" .= String "CouldNotParseCSS",
170− "message" .= Text.pack msg]
155+ ["message" .= Text.pack msg]
171 Fetching fp ->
156 Fetching fp ->
172− ["type" .= String "CouldNotParseCSS",
173− "path" .= Text.pack fp]
157+ ["path" .= Text.pack fp]
174 NoTitleElement fallback ->
158 NoTitleElement fallback ->
175− ["type" .= String "NoTitleElement",
176− "fallback" .= Text.pack fallback]
159+ ["fallback" .= Text.pack fallback]
160+ NoLangSpecified -> []
177
161
178showPos :: SourcePos -> String
162showPos :: SourcePos -> String
179showPos pos = sn ++ "line " ++
163showPos pos = sn ++ "line " ++
@@ -238,6 +222,9 @@ showLogMessage msg =
238 "This document format requires a nonempty <title> element.\n" ++
222 "This document format requires a nonempty <title> element.\n" ++
239 "Please specify either 'title' or 'pagetitle' in the metadata.\n" ++
223 "Please specify either 'title' or 'pagetitle' in the metadata.\n" ++
240 "Falling back to '" ++ fallback ++ "'"
224 "Falling back to '" ++ fallback ++ "'"
225+ NoLangSpecified ->
226+ "No value for 'lang' was specified in the metadata.\n" ++
227+ "It is recommended that lang be specified for this format."
241
228
242messageVerbosity:: LogMessage -> Verbosity
229messageVerbosity:: LogMessage -> Verbosity
243messageVerbosity msg =
230messageVerbosity msg =
@@ -262,3 +249,4 @@ messageVerbosity msg =
262 CouldNotParseCSS{} -> WARNING
249 CouldNotParseCSS{} -> WARNING
263 Fetching{} -> INFO
250 Fetching{} -> INFO
264 NoTitleElement{} -> WARNING
251 NoTitleElement{} -> WARNING
252+ NoLangSpecified -> INFO