packages feed

pandoc-include (empty) → 0.0.1

raw patch · 6 files changed

+230/−0 lines, 6 filesdep +basedep +directorydep +pandocsetup-changed

Dependencies added: base, directory, pandoc, pandoc-types, text

Files

+ CHANGELOG.md view
@@ -0,0 +1,7 @@+# Changelog++## v0.0.1 – 2015-12-08+* Project restructured+* License+* Initial documentation+* Cabal package file
+ IncludeFilter.hs view
@@ -0,0 +1,97 @@+#!/usr/bin/env runhaskell++{-+The MIT License (MIT)++Copyright (c) 2015 Dániel Stein <daniel@stein.hu>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+-}++{-|+A Pandoc filter that replaces include labeled Code Blocks with the contents of+the referenced files. Even nested, recursive includes.++Based on the scripting tutorial for Pandoc:+http://pandoc.org/scripting.html#include-files++The Code Blocks like the following will include every file in a new line. The+reference paths should be either absolute or relative to the folder where the+pandoc command will be executed.++> ```include+> /absolute/file/path.md+> relative/to/the/command/root.md+> #do/not/include/this.md+> ```++If the file does not exist, it will be skipped completely. No warnings, no+residue, nothing. Putting an # as the first character in the line will make the+filter skip that file.++For now the nested includes only work for two levels, after that the source+will be inserted and not parsed.++Note: the metadata from the included source files are discarded.++-}++import           Control.Monad+import           Data.List+import           System.Directory++import           Text.Pandoc+import           Text.Pandoc.Error+import           Text.Pandoc.JSON++stripPandoc :: Either PandocError Pandoc -> [Block]+stripPandoc p =+  case p of+    Left _ -> [Null]+    Right (Pandoc _ blocks) -> blocks++ioReadMarkdown :: String -> IO(Either PandocError Pandoc)+ioReadMarkdown content = return $! readMarkdown def content++getContent :: String -> IO [Block]+getContent file = do+  c <- readFile file+  p <- ioReadMarkdown c+  return $! stripPandoc p++getProcessableFileList :: String -> IO [String]+getProcessableFileList list = do+  let f = lines list+  let files = filter (\x -> not $ "#" `isPrefixOf` x) f+  filterM doesFileExist files++processFiles :: [String] -> IO [Block]+processFiles toProcess =+  fmap concat (mapM getContent toProcess)++doInclude :: Block -> IO [Block]+doInclude (CodeBlock (_, classes, _) list)+  | "include" `elem` classes = do+    let toProcess = getProcessableFileList list+    processFiles =<< toProcess+doInclude x = return [x]++main :: IO ()+main = toJSONFilter doInclude
+ LICENSE view
@@ -0,0 +1,23 @@+The MIT License (MIT)++Copyright (c) 2015 Dániel Stein <daniel@stein.hu>+++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,56 @@+# pandoc-include+A Pandoc filter that replaces include labeled Code Blocks with the contents of+the referenced files. Even nested, recursive includes.++Based on the scripting tutorial for Pandoc:+http://pandoc.org/scripting.html#include-files++## Format+The Code Blocks like the following will include every file in a new line. The+reference paths should be either absolute or relative to the folder where the+pandoc command will be executed.++`````+```include+/absolute/file/path.md+relative/to/the/command/root.md+#do/not/include/this.md+```+`````++If the file does not exist, it will be skipped completely. No warnings, no+residue, nothing. Putting an `#` as the first character in the line will make the+filter skip that file.++For now the nested includes only work for two levels, after that the source+will be inserted and not parsed.++*Note: the metadata from the included source files are discarded.*++## Installation+One could either install it using the Cabal packaging system by running:++```+cabal update+cabal install pandoc-include+```++Or it is also possible to use the pipe method using the source code described in the *Usage* section.++## Usage+In order to use this Pandoc filter, one has to include it into the Pandoc transformation workflow. This can be done by using the `--filter` parameter, like so:++```+pandoc --from markdown --to latex --filter pandoc-include input.md+```++All this does in the background is pipelining the output of Pandoc and the last filter into the standard input of the include filter and using its output as the next filter's input:++```+pandoc --from markdown --to json input.md | runhaskell IncludeFilter.hs | pandoc --from json --to latex+```++## License+Copyright ©2015 [Dániel Stein](https://twitter.com/steindani)++Source code is released under the Terms and Conditions of [MIT License](http://opensource.org/licenses/MIT).
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pandoc-include.cabal view
@@ -0,0 +1,45 @@+Name:                 pandoc-include+Version:              0.0.1+Synopsis:             Include other Markdown files+Description:          A Pandoc filter that replaces include labeled+                      Code Blocks with the contents of the referenced+                      Markdown files. Even nested, recursive includes.+Homepage:             https://github.com/steindani/pandoc-include+Bug-Reports:          https://github.com/steindani/pandoc-include/issues+License:              MIT+License-File:         LICENSE+Author:               Dániel Stein <daniel@stein.hu>+Maintainer:           Dániel Stein <daniel@stein.hu>+Copyright:            (c) 2015 Dániel Stein+Stability:            alpha+Category:             Text+Build-Type:           Simple+Data-Files:           README.md+Extra-Source-Files:   CHANGELOG.md+Cabal-Version:        >=1.10+Source-repository     head+  type:               git+  location:           git://github.com/steindani/pandoc-include.git++Library+  Build-Depends:      base >= 4.6 && < 5,+                      text >= 0.11,+                      pandoc >= 1.13.0.0,+                      pandoc-types >= 1.12.0.0,+                      directory+  Hs-Source-Dirs:     src+  Default-Extensions: CPP+  Exposed-Modules:+  Buildable:          True+  Default-Language:   Haskell2010++Executable pandoc-include+  Build-Depends:      base >= 4.6,+                      text >= 0.11,+                      pandoc >= 1.13.0.0,+                      pandoc-types >= 1.12.0.0,+                      directory+  Hs-Source-Dirs:     .+  Main-Is:            IncludeFilter.hs+  Buildable:          True+  Default-Language:   Haskell2010