Commit 6b054d58 authored by Jan-Philipp Stauffert's avatar Jan-Philipp Stauffert
Browse files

Merge branch 'code-snippet' into 'master'

Include source code from local source files

See merge request decker/decker!54
parents 72c44758 204292c1
......@@ -68,6 +68,7 @@ dependencies:
- pandoc-citeproc
- pandoc-lens
- pandoc-types
- pandoc-include-code
- process
- pureMD5
- random
......
......@@ -4,6 +4,7 @@ module Filter
, OutputFormat(..)
, Disposition(..)
, processPandoc
, Filter.includeCode
, processSlides
, useCachedImages
, escapeToFilePath
......@@ -55,6 +56,7 @@ import Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A (alt, class_, id, title)
import Text.Pandoc
import Text.Pandoc.Definition ()
import Text.Pandoc.Filter.IncludeCode as P
import Text.Pandoc.Lens
import Text.Pandoc.Shared
import Text.Pandoc.Walk
......@@ -216,6 +218,13 @@ zapImages :: Inline -> Inline
zapImages Image {} = Space
zapImages inline = inline
-- start snippet includeCode
includeCode :: Pandoc -> Decker Pandoc
includeCode (Pandoc meta blocks) = do
included <- doIO $ walkM (P.includeCode Nothing) blocks
return $ Pandoc meta included
-- end snippet includeCode
-- Transform inline image or video elements within the header line with
-- background attributes of the respective section.
handleBackground :: Slide -> Decker Slide
......
......@@ -288,6 +288,7 @@ readAndProcessMarkdown markdownFile disp = do
concatM
[ expandDeckerMacros
, renderCodeBlocks
, includeCode
, provisionResources
, processSlides
, renderMediaTags
......@@ -318,16 +319,16 @@ provisionResources pandoc = do
provisionMetaResource ::
FilePath -> Provisioning -> (String, FilePath) -> Action FilePath
provisionMetaResource base method (key, url)
provisionMetaResource base method kv@(key, url)
| key `elem` runtimeMetaKeys = do
filePath <- urlToFilePathIfLocal base url
provisionResource base method filePath
provisionMetaResource base method (key, url)
provisionMetaResource base method kv@(key, url)
| key `elem` templateOverrideMetaKeys = do
cwd <- liftIO $ Dir.getCurrentDirectory
filePath <- urlToFilePathIfLocal cwd url
provisionTemplateOverrideSupportTopLevel cwd method filePath
provisionMetaResource base _ (key, url)
provisionMetaResource base _ kv@(key, url)
| key `elem` compiletimeMetaKeys = do
filePath <- urlToFilePathIfLocal base url
need [filePath]
......@@ -639,6 +640,7 @@ elementAttributes =
, "data-background-video"
, "data-background-image"
, "data-background-iframe"
, "include"
]
-- | Resources in meta data that are needed at compile time. They have to be
......
......@@ -11,6 +11,7 @@ extra-deps:
- libyaml-0.1.0.0
- pandoc-2.4
- pandoc-lens-0.6.3
- pandoc-include-code-1.3.0.0
- skylighting-0.7.4
- skylighting-core-0.7.4
- yaml-0.11.0.0
......
---
title: Include Code
---
# Include the entire file
``` {.haskell include="/src/Filter.hs"}
```
# Include just a range
``` {.haskell include="/src/Filter.hs" startLine="221" endLine="224"}
```
# Include a tagged snippet
``` {.haskell include="/src/Filter.hs" snippet="includeCode"}
```
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