Commit 6c6fdb34 authored by Henrik Tramberend's avatar Henrik Tramberend
Browse files

WIP

parent 59fbf660
......@@ -69,8 +69,13 @@ needFile path = lift $ need [path]
needFiles :: [FilePath] -> Decker ()
needFiles pathes = lift $ need pathes
addScript :: Script -> Decker ()
addScript script = do
modify (\s -> s {scripts = scripts s ++ [script]})
data DeckerState = DeckerState
{ disposition :: Disposition
{ basePath :: String
, disposition :: Disposition
, slideCount :: Int
, externalReferences :: [U.URI]
, scripts :: [Script]
......
......@@ -57,9 +57,9 @@ import Text.Printf
import Text.Read
processPandoc ::
(Pandoc -> Decker Pandoc) -> Disposition -> Pandoc -> Action Pandoc
processPandoc transformation disposition pandoc =
evalStateT (transformation pandoc) (DeckerState disposition 0 [] [])
(Pandoc -> Decker Pandoc) -> FilePath -> Disposition -> Pandoc -> Action Pandoc
processPandoc transformation basePath disposition pandoc =
evalStateT (transformation pandoc) (DeckerState basePath disposition 0 [] [])
isSlideHeader :: Block -> Bool
isSlideHeader (Header 1 _ _) = True
......
......@@ -26,7 +26,7 @@ import System.Directory (createDirectoryIfMissing, doesFileExist)
import System.FilePath.Posix
import Text.Blaze (customAttribute)
import Text.Blaze.Html.Renderer.String
import Text.Blaze.Html5 as H ((!), script, toHtml, toValue)
import Text.Blaze.Html5 as H ((!), canvas, script, toHtml, toValue)
import Text.Blaze.Html5.Attributes as A
(alt, class_, height, id, src, style, title, width)
import Text.Pandoc
......@@ -41,7 +41,7 @@ renderCodeBlocks pandoc =
data Processor = Processor
{ srcExtensions :: [String]
, extension :: String
, compile :: String -> Attr -> Decker Inline
, compile :: Processor -> String -> Attr -> Decker Inline
} deriving (Show)
renderClass :: String
......@@ -66,10 +66,21 @@ processors =
"\\end{document}")
]
bracketCode :: String -> String -> Processor -> String -> Attr -> Decker String
bracketCode preamble postamble processor code attr =
d3Canvas :: Processor -> FilePath -> Attr -> Decker Inline
d3Canvas processor sourceFile (eid, classes, keyvals) = do
basePath <- gets basePath
sourceUrl <-
lift $ provisionResource (provisioningFromMeta meta) basePath sourceFile
addScript $ ScriptURI "javascript" "https://d3js.org/d3.v4.min.js"
addScript $ ScriptSource "javascript" sourceFile
return $ RawInline (Format "html") $ renderHtml $ canvas ! A.id (toValue eid)
bracketCode ::
String -> String -> Processor -> FilePath -> Attr -> Decker Inline
bracketCode preamble postamble processor sourceFile attr = do
let contents = preamble ++ "\n" ++ code ++ "\n" ++ postamble
path = writeCompiled contents
let path = writeCompiled contents
return $ Image attr [] (path, "")
-- | Calculates the list of all known file extensions that can be rendered into
-- an SVG image.
......
......@@ -219,13 +219,13 @@ versionCheck meta =
readAndProcessMarkdown :: FilePath -> Disposition -> Action Pandoc
readAndProcessMarkdown markdownFile disposition = do
readMetaMarkdown markdownFile >>= processIncludes baseDir >>=
processPandoc pipeline disposition
processPandoc pipeline baseDir disposition
where
baseDir = takeDirectory markdownFile
pipeline =
concatM
[ expandDeckerMacros
, provisionResources baseDir
, provisionResources
, renderMediaTags
, makeSlides
, renderCodeBlocks
......@@ -235,10 +235,11 @@ readAndProcessMarkdown markdownFile disposition = do
-- Disable automatic caching of remote images for a while
-- >>= walkM (cacheRemoteImages (cache dirs))
provisionResources :: FilePath -> Pandoc -> Decker Pandoc
provisionResources baseDir pandoc@(Pandoc meta _) =
provisionResources :: Pandoc -> Decker Pandoc
provisionResources pandoc@(Pandoc meta _) =
lift $ do
let method = provisioningFromMeta meta
baseDir <- gets basePath
mapMetaResources (provisionMetaResource method baseDir) pandoc >>=
mapResources (provisionResource method baseDir)
......@@ -265,13 +266,14 @@ provisionMetaResource _ _ (key, path) = return path
-- resolved against and copied or linked to public from
-- 1. the project root
-- 2. the local filesystem root
--
--
-- Relative file URLs are resolved against and copied or linked to public from
--
-- 1. the directory path of the referencing file
-- 2. the project root Copy and link operations target the public directory
-- in the project root and recreate the source directory structure. This
-- function is used to provision resources that are used at presentation
-- in the project root and recreate the source directory structure.
--
-- This function is used to provision resources that are used at presentation
-- time.
--
-- Returns a public URL relative to base
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment