Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions Data/Graph/Analysis/Reporting/Pandoc.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

{- |
Module : Data.Graph.Analysis.Reporting.Pandoc
Description : Graphalyze Types and Classes
Expand Down Expand Up @@ -39,15 +41,23 @@ import Data.List (intersperse)
import Data.Maybe (fromJust, isNothing)
import System.Directory (removeDirectoryRecursive)
import System.FilePath ((<.>), (</>))
import Data.Text (Text(..))
import qualified Data.Text as T

-- -----------------------------------------------------------------------------

{- $writers
The actual exported writers.
-}

#if MIN_VERSION_pandoc (2,0,0)
writeHtmlStringGeneric = writeHtml5String
#else
writeHtmlStringGeneric = writeHtmlString
#endif

pandocHtml :: PandocDocument
pandocHtml = pd { writer = writeHtmlString
pandocHtml = pd { writer = writeHtmlStringGeneric
, extension = "html"
, templateName = "html"
, extGraphProps = Just VProps { grSize = DefaultSize
Expand Down Expand Up @@ -84,7 +94,11 @@ pandocMarkdown = pd { writer = writeMarkdown
-- | Definition of a Pandoc Document. Size measurements are in inches,
-- and a 6:4 ratio is used for width:length.
data PandocDocument = PD { -- | The Pandoc document style
#if MIN_VERSION_pandoc (2,0,0)
writer :: WriterOptions -> Pandoc -> PandocPure Text
#else
writer :: WriterOptions -> Pandoc -> String
#endif
-- | The file extension used
, extension :: FilePath
-- | Which template to get.
Expand Down Expand Up @@ -144,23 +158,29 @@ defaultProcess = PP { secLevel = 1

-- | Create the document.
createPandoc :: PandocDocument -> Document -> IO (Maybe FilePath)
createPandoc p d = do created <- tryCreateDirectory dir
-- If the first one fails, so will this one.
_ <- tryCreateDirectory $ dir </> gdir
if not created
then failDoc
else do d' <- addLegend dir gdir (graphProps p) d
elems <- multiElems pp $ content d'
case elems of
Just es -> do let es' = htmlAuthDt : es
pnd = Pandoc meta es'
doc = convert pnd
wr <- tryWrite doc
case wr of
(Right _) -> success
(Left _) -> failDoc
Nothing -> failDoc
where
createPandoc p d = do
created <- tryCreateDirectory dir
-- If the first one fails, so will this one.
_ <- tryCreateDirectory $ dir </> gdir
if not created
then failDoc
else do
d' <- addLegend dir gdir (graphProps p) d
elems <- multiElems pp $ content d'
case elems of
Just es -> do
let es' = htmlAuthDt : es
pnd = Pandoc meta es'
#if MIN_VERSION_pandoc (2,0,0)
let doc = runPure $ convert pnd
#else
doc <- tryWrite $ convert pnd
#endif
case doc of
(Right _) -> success
(Left _) -> failDoc
Nothing -> failDoc
where
dir = rootDirectory d
gdir = graphDirectory d
auth = author d
Expand Down
13 changes: 6 additions & 7 deletions Graphalyze.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: Graphalyze
Version: 0.15.0.0
Version: 0.15.0.1
Synopsis: Graph-Theoretic Analysis library.
Description: A library to use graph theory to analyse the relationships
inherent in discrete data.
Expand All @@ -13,8 +13,7 @@ Extra-Source-Files: TODO
Cabal-Version: >= 1.6
Build-Type: Simple

Tested-With: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4,
GHC == 7.10.2, GHC == 7.11.*
Tested-With: GHC == 8.4.2

Source-Repository head
Type: git
Expand All @@ -34,10 +33,10 @@ Library {
filepath,
process,
random,
bktrees >= 0.2 && <0.4,
fgl == 5.5.*,
graphviz >= 2999.15 && < 2999.20,
pandoc == 1.19.*,
bktrees >= 0.2,
fgl >= 5.6,
graphviz >= 2999.20 ,
pandoc >= 2.0 ,
text

if flag(old-locale) {
Expand Down