packages feed

hyakko 0.3.0 → 0.3.1

raw patch · 3 files changed

+50/−45 lines, 3 filesdep ~pandoc

Dependency ranges changed: pandoc

Files

hyakko.cabal view
@@ -1,5 +1,5 @@ name:             hyakko-version:          0.3.0+version:          0.3.1 cabal-version:    >= 1.6 build-type:       Simple license:          MIT@@ -11,7 +11,7 @@ stability:        alpha homepage:         http://sourrust.github.com/hyakko/ category:         Documentation-tested-with:      GHC == 7.0.3+tested-with:      GHC == 7.4.2 synopsis:         Literate-style Documentation Generator description:      Hyakko is a Haskell port of Docco: the original quick-and-dirty,                   hundred-line-long, literate-programming-style documentation@@ -39,7 +39,7 @@                   regex-pcre >= 0.9,                   containers >= 0.4,                   directory >= 1,-                  pandoc >= 1.8.2,+                  pandoc >= 1.10,                   bytestring >= 0.9   hs-source-dirs: src   ghc-options:    -O2 -Wall
src/Hyakko.hs view
@@ -35,7 +35,7 @@ import qualified Data.ByteString.Lazy.Char8 as L import Data.List (sort, groupBy) import Data.Maybe (fromJust)-import Control.Monad (filterM)+import Control.Monad (filterM, (>=>)) import Text.Pandoc.Templates import Text.Regex import Text.Regex.PCRE ((=~))@@ -82,36 +82,37 @@ --     ] -- inSections :: [ByteString] -> ByteString -> [Map String ByteString]-inSections xs r =-  let mkRegex' = mkRegex . (=~ r)-      -- Generalized function used to section off code and comments-      groupBy' t t1 = groupBy $ \x y -> and $ map (t1 . (=~ r)) [t x, t y]-      -- Replace the beggining comment symbol with nothing-      replace = L.unlines . map (\y ->-        let y' = L.unpack y-        in L.pack $ subRegex (mkRegex' y') y' "")-      -- Clump sectioned off lines into doc and code text.-      clump [] = []-      clump [x] = clump $ ensurePair [x]-      clump (x:y:ys) = [("docsText", replace x),("codeText", L.unlines y)] : clump ys-      -- Make sure the result is in the right pairing order-      ensurePair ys = if even $ length ys then ys else-        if (head . head) ys =~ r then ys ++ [[""]] else [""]:ys--      -- Group comments into a list-      s1 = groupBy' id id xs-      -- Group code into a list-      s2 = groupBy' head not s1-      -- Bring the lists together into groups of comment and groups of code-      -- pattern.-      s3 = ensurePair $ map concat s2-  in [M.fromList l | l <- clump s3]+inSections xs r = do+  l <- clump s+  return $ M.fromList l+  where+    -- Generalized function used to section off code and comments+    groupBy' t t1 = groupBy $ \x y -> and $ map (t1 . (=~ r)) [t x, t y]+    -- Replace the beggining comment symbol with nothing+    replace = L.unlines . map (\x -> let y = L.unpack x+                                         mkReg = mkRegex . (=~ r)+                                     in L.pack $ subRegex (mkReg y) y "")+    -- Clump sectioned off lines into doc and code text.+    clump [x] = clump $ ensurePair [x]+    clump (x:y:ys) = [("docsText", replace x),("codeText", L.unlines y)] : clump ys+    clump _ = []+    -- Make sure the result is in the right pairing order+    ensurePair ys | even (length ys) = ys+                  | otherwise = appendList [[""]]+      where appendList | (head . head) ys =~ r = (ys ++)+                       | otherwise             = (++ ys)+    -- Bring the lists together into groups of comment and groups of code+    -- pattern.+    s = ensurePair . map concat+                   -- Group code into a list+                   . groupBy' head not+                   -- Group comments into a list+                   $ groupBy' id id xs  parse :: Maybe (Map String ByteString) -> ByteString -> [Map String ByteString]-parse Nothing _ = []-parse (Just src) code =-  let line = filter ((/=) "#!" . L.take 2) $ L.lines code-  in inSections line $ src M.! "comment"+parse Nothing _       = []+parse (Just src) code = inSections line $ src M.! "comment"+  where line = filter ((/=) "#!" . L.take 2) $ L.lines code  -- Highlights a single chunk of Haskell code, using **Pygments** over stdio, -- and runs the text of its corresponding comment through **Markdown**, using the@@ -193,14 +194,14 @@   -- Build out the appropriate matchers and delimiters for each language.   in M.map (\x -> let s = x M.! "symbol"     -- Does the line begin with a comment?-    in M.insert "comment" ("^\\s*"><s><"\\s?") $+    in M.insert "comment" ("^\\s*"><s><"\\s?")        -- The dividing token we feed into Pygments, to delimit the boundaries        -- between sections.-       M.insert "dividerText" ("\n"><s><"DIVIDER\n") $+     . M.insert "dividerText" ("\n"><s><"DIVIDER\n")        -- The mirror of `divider_text` that we expect Pygments to return. We can        -- split on this to recover the original sections.        -- Note: the class is "c" for Python and "c1" for the other languages-       M.insert "dividerHtml" ("\n*<span class=\"c1?\">"><s><"DIVIDER</span>\n") x) l+     $ M.insert "dividerHtml" ("\n*<span class=\"c1?\">"><s><"DIVIDER</span>\n") x) l  -- Get the current language we're documenting, based on the extension. getLanguage :: FilePath -> Maybe (Map String ByteString)@@ -234,15 +235,16 @@  -- Reads from resource path given in cabal package readDataFile :: FilePath -> IO ByteString-readDataFile f = getDataFileName f >>= L.readFile+readDataFile = getDataFileName >=> L.readFile  -- For each source file passed in as an argument, generate the documentation. sources :: IO [FilePath]-sources = getArgs >>= unpack >>= return . sort . concat+sources = getArgs >>= unpack   where-    unpack = mapM (\x -> do-      isDir <- doesDirectoryExist x-      if isDir then unpackDirectories x else return [x])+    unpack = mapM (\x -> doesDirectoryExist x >>= unpack' x)+               >=> return . sort . concat+    unpack' x True  = unpackDirectories x+    unpack' x False = return [x]  -- Turns the directory give into a list of files including all of the files -- in sub-directories.
src/Text/Markdown.hs view
@@ -1,16 +1,19 @@ module Text.Markdown (toHTML) where  import Text.Pandoc-  ( readMarkdown+  ( Pandoc+  , readMarkdown   , writeHtmlString-  , defaultParserState-  , defaultWriterOptions+  , def   )+ import Data.ByteString.Lazy.Char8 (ByteString, pack) +writeHTMLStr :: Pandoc -> String+writeHTMLStr = writeHtmlString def -- Function for translating Markdown to HTML since `Pandoc` has several -- different generators for other markup languages. toHTML :: String -> ByteString-toHTML = pack . writeHtmlString defaultWriterOptions . parse-  where parse = readMarkdown defaultParserState+toHTML = pack . writeHTMLStr . parse+  where parse = readMarkdown def {-# INLINE toHTML #-}