pax_global_header 0000666 0000000 0000000 00000000064 14433757572 0014533 g ustar 00root root 0000000 0000000 52 comment=3fd65bc302838c6bca25e0fd3c78292cf227cfd2 pandoc-sidenote-0.23.0/ 0000775 0000000 0000000 00000000000 14433757572 0014671 5 ustar 00root root 0000000 0000000 pandoc-sidenote-0.23.0/.gitignore 0000664 0000000 0000000 00000000043 14433757572 0016656 0 ustar 00root root 0000000 0000000 .*.sw[nop] tags .stack-work *.zip pandoc-sidenote-0.23.0/LICENSE 0000664 0000000 0000000 00000002072 14433757572 0015677 0 ustar 00root root 0000000 0000000 The MIT License (MIT) Copyright (c) 2016 Jacob Zimmerman 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. pandoc-sidenote-0.23.0/Main.hs 0000664 0000000 0000000 00000000231 14433757572 0016105 0 ustar 00root root 0000000 0000000 module Main where import Text.Pandoc.SideNote (usingSideNotes) import Text.Pandoc.JSON (toJSONFilter) main :: IO () main = toJSONFilter usingSideNotes pandoc-sidenote-0.23.0/Makefile 0000664 0000000 0000000 00000000563 14433757572 0016335 0 ustar 00root root 0000000 0000000 VERSION := 0.23.0 all: pandoc-sidenote-$(VERSION).zip .PHONY: stack stack: stack build pandoc-sidenote-%.zip: stack find .stack-work/install/x86_64-osx -name pandoc-sidenote -type f \ -exec zip -j $@ '{}' ';' # Assumes that a tag has already been created and pushed .PHONY: release release: pandoc-sidenote-$(VERSION).zip hub release create -a $< $(VERSION) pandoc-sidenote-0.23.0/README.md 0000664 0000000 0000000 00000005520 14433757572 0016152 0 ustar 00root root 0000000 0000000 # pandoc-sidenote > Convert Pandoc Markdown-style footnotes into sidenotes This is a simple [Pandoc filter] to convert footnotes into a format that can be consumed by [Tufte CSS] and [Pandoc Markdown CSS Theme]. On the whole, this project weighs in at well under 100 lines of code. Check out [SideNote.hs](src/Text/Pandoc/SideNote.hs) if you're curious how it works. It's used by calling `pandoc --filter pandoc-sidenote`. To see it in action, see [Tufte Pandoc CSS], a project which uses it. In particular, take a look at the Makefile included in that project. The core functionality is also exposed as a library, which can be called by Haskell applications such as Hakyll. ## Dependencies `pandoc-sidenote` is build against a specific version of Pandoc. This table maps `pandoc` versions to `pandoc-sidenote` versions: | pandoc | pandoc-sidenote | | ------ | --------------- | | 3.0 | 0.23.0 | | 2.11 | 0.22.0, 0.22.1, 0.22.2 | | 2.9 | 0.20.0 | | 2.1, 1.19 | 0.19.0 | | 1.18 | 0.9.0 | If a newer version of `pandoc` has been released, the Stack build manifest will need to be adjusted for that version, and the project then rebuilt. ## Installation ### Cabal `pandoc-sidenote` is on Hackage and can thus be installed using `cabal`: ```bash cabal install pandoc-sidenote ``` ### Homebrew If you're on OS X, you can install the `pandoc-sidenote` binary from my Homebrew tap: ```bash brew install jez/formulae/pandoc-sidenote ``` ### From Source Otherwise, you'll have to install from source. This project is written in Haskell and built using [Stack]. If you're new to Haskell, now's a perfect time to wet your toes! Go [install Stack first], then run these commands: ```bash git clone https://github.com/jez/pandoc-sidenote cd pandoc-sidenote # this is going to be reaaally long the first time stack build # copy the compiled binary onto your PATH stack install ``` ## Notes to myself Side note: I run this command to generate the zip files attached to releases that are downloaded by the Homebrew formula: ```bash make ``` It would be nice to get GitHub Actions set up to build and publish releases for each tagged commit automatically. I run this command to publish packages to Hackage: ```bash # First, edit `package.yaml` to remove `-Werror`, then: stack upload . ``` ## License [](https://jez.io/MIT-LICENSE.txt) [Tufte CSS]: https://edwardtufte.github.io/tufte-css/ [Stack]: https://docs.haskellstack.org/en/stable/README/ [install Stack first]: https://docs.haskellstack.org/en/stable/README/ [Pandoc filter]: http://pandoc.org/scripting.html#json-filters [Tufte Pandoc CSS]: https://github.com/jez/tufte-pandoc-css [Pandoc Markdown CSS Theme]: https://github.com/jez/pandoc-markdown-css-theme pandoc-sidenote-0.23.0/Setup.hs 0000664 0000000 0000000 00000000056 14433757572 0016326 0 ustar 00root root 0000000 0000000 import Distribution.Simple main = defaultMain pandoc-sidenote-0.23.0/package.yaml 0000664 0000000 0000000 00000002145 14433757572 0017152 0 ustar 00root root 0000000 0000000 name: pandoc-sidenote version: 0.23.0.0 github: jez/pandoc-sidenote license: MIT license-file: LICENSE author: Jake Zimmerman maintainer: zimmerman.jake@gmail.com copyright: 2016 Jake Zimmerman extra-source-files: - README.md - LICENSE # Metadata used when publishing your package synopsis: Convert Pandoc Markdown-style footnotes into sidenotes description: > This is a simple Pandoc filter to convert footnotes into a format that can be consumed by Tufte CSS. On the whole, this project weighs in at well under 100 lines of code. Check out SideNote.hs if you're curious how it works. category: CommandLine ghc-options: - -Wall - -Wcompat - -Wmissing-signatures - -Werror - -funbox-strict-fields dependencies: - base >= 4.7 && < 5 - mtl - pandoc-types >= 1.22 - text library: source-dirs: src executables: pandoc-sidenote: main: Main.hs source-dirs: ./ ghc-options: - -threaded - -rtsopts - -with-rtsopts=-N dependencies: - pandoc-sidenote pandoc-sidenote-0.23.0/pandoc-sidenote.cabal 0000664 0000000 0000000 00000003324 14433757572 0020733 0 ustar 00root root 0000000 0000000 cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack -- -- hash: f11dcb166b764b1edc49c4459b29102aa2e14ea287b6d86053107712cd3accb5 name: pandoc-sidenote version: 0.23.0.0 synopsis: Convert Pandoc Markdown-style footnotes into sidenotes description: This is a simple Pandoc filter to convert footnotes into a format that can be consumed by Tufte CSS. On the whole, this project weighs in at well under 100 lines of code. Check out SideNote.hs if you're curious how it works. category: CommandLine homepage: https://github.com/jez/pandoc-sidenote#readme bug-reports: https://github.com/jez/pandoc-sidenote/issues author: Jake Zimmerman maintainer: zimmerman.jake@gmail.com copyright: 2016 Jake Zimmerman license: MIT license-file: LICENSE build-type: Simple extra-source-files: README.md LICENSE source-repository head type: git location: https://github.com/jez/pandoc-sidenote library exposed-modules: Text.Pandoc.SideNote other-modules: Paths_pandoc_sidenote hs-source-dirs: src ghc-options: -Wall -Wcompat -Wmissing-signatures -Werror -funbox-strict-fields build-depends: base >=4.7 && <5 , mtl , pandoc-types >=1.22 , text default-language: Haskell2010 executable pandoc-sidenote main-is: Main.hs other-modules: Paths_pandoc_sidenote hs-source-dirs: ./ ghc-options: -Wall -Wcompat -Wmissing-signatures -Werror -funbox-strict-fields -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 , mtl , pandoc-sidenote , pandoc-types >=1.22 , text default-language: Haskell2010 pandoc-sidenote-0.23.0/src/ 0000775 0000000 0000000 00000000000 14433757572 0015460 5 ustar 00root root 0000000 0000000 pandoc-sidenote-0.23.0/src/Text/ 0000775 0000000 0000000 00000000000 14433757572 0016404 5 ustar 00root root 0000000 0000000 pandoc-sidenote-0.23.0/src/Text/Pandoc/ 0000775 0000000 0000000 00000000000 14433757572 0017610 5 ustar 00root root 0000000 0000000 pandoc-sidenote-0.23.0/src/Text/Pandoc/SideNote.hs 0000664 0000000 0000000 00000007206 14433757572 0021663 0 ustar 00root root 0000000 0000000 {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.SideNote (usingSideNotes) where import Data.List (intercalate) import Data.Text (append, pack) import Control.Monad.State import Text.Pandoc.JSON import Text.Pandoc.Walk (walk, walkM) data NoteType = SideNote | MarginNote | FootNote deriving (Show, Eq) getFirstStr :: [Block] -> (NoteType, [Block]) getFirstStr blocks@(block:blocks') = case block of Plain ((Str "{-}"):Space:rest) -> (MarginNote, (Plain rest):blocks') Plain ((Str "{.}"):Space:rest) -> (FootNote, (Plain rest):blocks') Para ((Str "{-}"):Space:rest) -> (MarginNote, (Para rest):blocks') Para ((Str "{.}"):Space:rest) -> (FootNote, (Para rest):blocks') LineBlock (((Str "{-}"):Space:rest):rest') -> (MarginNote, (LineBlock (rest:rest')):blocks') LineBlock (((Str "{.}"):Space:rest):rest') -> (FootNote, (LineBlock (rest:rest')):blocks') _ -> (SideNote, blocks) getFirstStr blocks = (SideNote, blocks) newline :: [Inline] newline = [LineBreak, LineBreak] -- This could be implemented more concisely, but I think this is more clear. getThenIncr :: State Int Int getThenIncr = do i <- get put (i + 1) return i -- Extract inlines from blocks. Note has a [Block], but Span needs [Inline]. coerceToInline :: [Block] -> [Inline] coerceToInline = concatMap deBlock . walk deNote where deBlock :: Block -> [Inline] deBlock (Plain ls ) = ls -- Simulate paragraphs with double LineBreak deBlock (Para ls ) = ls ++ newline -- See extension: line_blocks deBlock (LineBlock lss ) = intercalate [LineBreak] lss ++ newline -- Pretend RawBlock is RawInline (might not work!) -- Consider: raw