summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-01-29 23:54:00 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-02-04 09:56:43 -0800
commit75485c2f112cdc2e1f95f871d01cc356510166ae (patch)
tree2d495f048bd887403db41418c14445b54af1b00c /src/Text/Pandoc/Shared.hs
parent23ca68a5c41ef68397ed2217e31bf6e720fb0534 (diff)
Complete rewrite of LaTeX reader.
* The new reader is more robust, accurate, and extensible. It is still quite incomplete, but it should be easier now to add features. * Text.Pandoc.Parsing: Added withRaw combinator. * Markdown reader: do escapedChar before raw latex inline. Otherwise we capture commands like \{. * Fixed latex citation tests for new citeproc. * Handle \include{} commands in latex. This is done in pandoc.hs, not the (pure) latex reader. But the reader exports the needed function, handleIncludes. * Moved err and warn from pandoc.hs to Shared. * Fixed tests - raw tex should sometimes have trailing space. * Updated lhs-test for highlighting-kate changes.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 7e63c2161..cd5b19164 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -70,11 +70,16 @@ module Text.Pandoc.Shared (
inDirectory,
findDataFile,
readDataFile,
+ -- * Error handling
+ err,
+ warn,
) where
import Text.Pandoc.Definition
import Text.Pandoc.Generic
-import qualified Text.Pandoc.UTF8 as UTF8 (readFile)
+import qualified Text.Pandoc.UTF8 as UTF8
+import System.Environment (getProgName)
+import System.Exit (exitWith, ExitCode(..))
import Data.Char ( toLower, isLower, isUpper, isAlpha,
isLetter, isDigit, isSpace )
import Data.List ( find, isPrefixOf, intercalate )
@@ -89,6 +94,7 @@ import Text.Pandoc.Highlighting (Style, pygments)
import Text.Pandoc.Pretty (charWidth)
import System.Locale (defaultTimeLocale)
import Data.Time
+import System.IO (stderr)
--
-- List processing
@@ -581,3 +587,19 @@ findDataFile (Just u) f = do
-- Cabal data directory.
readDataFile :: Maybe FilePath -> FilePath -> IO String
readDataFile userDir fname = findDataFile userDir fname >>= UTF8.readFile
+
+--
+-- Error reporting
+--
+
+err :: Int -> String -> IO a
+err exitCode msg = do
+ name <- getProgName
+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
+ exitWith $ ExitFailure exitCode
+ return undefined
+
+warn :: String -> IO ()
+warn msg = do
+ name <- getProgName
+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg