我有许多 haskell 包,并且我启用了一些标志以允许它们生成黑线鳕文档。现在这些文件位于/usr/share/doc/{package-name}-{version}/html/
.
有组织它们的工具吗?我想要在hackage中按名称页面列出所有包的东西,以便可以在一页中找到所有这些已安装包的本地链接。
如果能告诉hoogle使用这些文件就更好了。到目前为止,我的 hoogle 搜索结果都指向 hackage 中的相应页面。
由于我的问题还没有得到回答,我写了一个快速而肮脏的程序来回答我的第一个问题:
import System.Directory
import System.IO
import System.Environment
import System.Exit
import System.Path
import System.FilePath.Posix
import Control.Applicative
import Control.Monad
import Data.Maybe
import Data.List
import Text.Printf
-- | make markdown table row
makeTableRow :: String -> FilePath -> String
makeTableRow dirName htmlPath = intercalate "|" [ dirName
, link "frames"
, link "index"
, link "doc-index"]
where
link s = printf "[%s](%s)" s $ htmlPath </> s ++ ".html"
scanAndMakeTable :: String -> IO [String]
scanAndMakeTable relDocPath = do
(Just docPath) <- absNormPath' <$> getCurrentDirectory <*> pure relDocPath
dirs <- getDirectoryContents docPath
items <- liftM catMaybes
. mapM (asHaskellPackage docPath)
. sort $ dirs
return $ headers1:headers2:map (uncurry makeTableRow) items
where
headers1 = "| " ++ intercalate " | " (words "Package Frames Contents Index") ++ " |"
headers2 = intercalate " --- " $ replicate 5 "|"
absNormPath' a p = addMissingRoot <$> absNormPath a p
-- sometimes the leading '/' is missing in absNormPath results
addMissingRoot s@('/':_) = s
addMissingRoot s = '/' : s
asHaskellPackage :: String -> String -> IO (Maybe (String,FilePath))
asHaskellPackage docPath dirName = do
-- a valid haskell package has a "haddock dir"
-- in which we can at least find a file with ".haddock" as extension name
b1 <- doesDirectoryExist haddockFileDir
if b1
then do
b2 <- any ((== ".haddock") . takeExtension)
<$> getDirectoryContents haddockFileDir
return $ if b2 then Just (dirName,haddockFileDir) else Nothing
else return Nothing
where
-- guess haddock dir
haddockFileDir = docPath </> dirName </> "html"
main :: IO ()
main = do
args <- getArgs
case args of
[docPath'] -> scanAndMakeTable docPath' >>= putStrLn . unlines
_ -> help
where
help = hPutStrLn stderr "Usage: <program> <path-to-packages>"
>> exitFailure
通过观察这些黑线鳕目录的结构,我通过测试识别了黑线鳕目录:
html
.html
中,则有一个.haddock
扩展名为的文件。运行程序runghc <source-file> /usr/share/doc/ >document-nav.md
应该会生成一个包含文档链接的降价文件。之后只需将其通过管道传输到 pandoc 或其他一些 markdown2html 转换器,并在浏览器中使用生成的 HTML 文件来浏览包文档。