BlogLiterately 0.7.1.3 → 0.7.1.4
raw patch · 3 files changed
+37/−9 lines, 3 filesdep +strictdep +temporary
Dependencies added: strict, temporary
Files
- BlogLiterately.cabal +3/−1
- CHANGES.md +6/−0
- src/Text/BlogLiterately/Ghci.hs +28/−8
BlogLiterately.cabal view
@@ -1,5 +1,5 @@ Name: BlogLiterately-Version: 0.7.1.3+Version: 0.7.1.4 Synopsis: A tool for posting Haskelly articles to blogs Description: Write blog posts in Markdown format, then use BlogLiterately to do syntax highlighting, format ghci sessions, and upload@@ -47,6 +47,8 @@ containers, bool-extras, mtl,+ temporary >= 1.1 && < 1.3,+ strict >= 0.3 && < 0.4, split >= 0.1.4 && < 0.3, utf8-string >= 0.3 && < 0.4, transformers >= 0.3 && < 0.4,
CHANGES.md view
@@ -1,3 +1,9 @@+0.7.1.4 (3 February 2014)+-------------------------++ * (#11) Workaround allowing [ghci] blocks in .lhs files containing+ lines that start with #+ 0.7.1.3 (30 January 2014) -------------------------
src/Text/BlogLiterately/Ghci.hs view
@@ -41,7 +41,10 @@ import Data.Char (isSpace) import Data.Functor ((<$>)) import Data.List (intercalate, isPrefixOf)+import System.FilePath (takeFileName) import System.IO+import qualified System.IO.Strict as Strict+import System.IO.Temp import System.Process (ProcessHandle, runInteractiveCommand, waitForProcess)@@ -93,16 +96,33 @@ -- it, and finally stop the process. withGhciProcess :: FilePath -> ReaderT ProcessInfo IO a -> IO a withGhciProcess f m = do- isLit <- isLiterate f- h <- runInteractiveCommand $ "ghci -v0 -ignore-dot-ghci "- ++ (if isLit then f else "")- res <- runReaderT m h- stopGhci h- return res+ src <- Strict.readFile f+ let isLit = isLiterate src+ withLiterateHashWorkaround f src $ \f' -> do+ h <- runInteractiveCommand $ "ghci -v0 -ignore-dot-ghci "+ ++ (if isLit then f' else "")+ res <- runReaderT m h+ stopGhci h+ return res +-- | Workaround for https://ghc.haskell.org/trac/ghc/ticket/4836; see+-- also https://github.com/byorgey/BlogLiterately/issues/11. If the+-- file contains any lines beginning with #, create a temporary file+-- with those lines filtered out, and pass that instead.[+withLiterateHashWorkaround :: FilePath -> String -> (FilePath -> IO a) -> IO a+withLiterateHashWorkaround f src k = do+ let bad = ("#" `isPrefixOf`)+ b = any bad . lines $ src+ case b of+ False -> k f+ True -> withTempFile "" (takeFileName f) $ \f' h -> do+ hPutStr h (unlines . filter (not . bad) . lines $ src)+ hClose h+ k f'+ -- | Poor man's check to see whether we have a literate Haskell file.-isLiterate :: FilePath -> IO Bool-isLiterate f = (any ("> " `isPrefixOf`) . lines) <$> readFile f+isLiterate :: String -> Bool+isLiterate = any ("> " `isPrefixOf`) . lines -- | Stop a ghci process by passing it @:q@ and waiting for it to exit. stopGhci :: ProcessInfo -> IO ()