pandoc-sidenote-0.22.1.0/src/0000755000000000000000000000000013573133771013775 5ustar0000000000000000pandoc-sidenote-0.22.1.0/src/Text/0000755000000000000000000000000013573134373014720 5ustar0000000000000000pandoc-sidenote-0.22.1.0/src/Text/Pandoc/0000755000000000000000000000000013777474075016140 5ustar0000000000000000pandoc-sidenote-0.22.1.0/src/Text/Pandoc/SideNote.hs0000644000000000000000000000560713777474075020216 0ustar0000000000000000{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.SideNote (usingSideNotes) where import Data.List (intercalate) import Data.Text (Text, append, pack) import Control.Monad.State import Text.Pandoc.JSON import Text.Pandoc.Walk (walk, walkM) getFirstStr :: [Inline] -> Maybe Text getFirstStr [] = Nothing getFirstStr (Str text:_ ) = Just text getFirstStr (_ :inlines) = getFirstStr inlines 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 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
now inside RawInline... what happens? deBlock (RawBlock fmt str) = [RawInline fmt str] -- lists, blockquotes, headers, hrs, and tables are all omitted -- Think they shouldn't be? I'm open to sensible PR's. deBlock _ = [] deNote (Note _) = Str "" deNote x = x filterInline :: Inline -> State Int Inline filterInline (Note blocks) = do -- Generate a unique number for the 'for=' attribute i <- getThenIncr -- Note has a [Block], but Span needs [Inline] let content = coerceToInline blocks -- The '{-}' symbol differentiates between margin note and side note let nonu = getFirstStr content == Just "{-}" let content' = if nonu then tail content else content let labelCls = "margin-toggle" `append` (if nonu then "" else " sidenote-number") let labelSym = if nonu then "⊕" else "" let labelHTML = mconcat [ "" ] let label = RawInline (Format "html") labelHTML let inputHTML = mconcat [ "" ] let input = RawInline (Format "html") inputHTML let (ident, _, attrs) = nullAttr let noteTypeCls = if nonu then "marginnote" else "sidenote" let note = Span (ident, [noteTypeCls], attrs) content' return $ Span ("", ["sidenote-wrapper"], []) [label, input, note] filterInline inline = return inline usingSideNotes :: Pandoc -> Pandoc usingSideNotes (Pandoc meta blocks) = Pandoc meta (evalState (walkM filterInline blocks) 0) pandoc-sidenote-0.22.1.0/Main.hs0000644000000000000000000000023113021656013014405 0ustar0000000000000000module Main where import Text.Pandoc.SideNote (usingSideNotes) import Text.Pandoc.JSON (toJSONFilter) main :: IO () main = toJSONFilter usingSideNotes pandoc-sidenote-0.22.1.0/LICENSE0000644000000000000000000000207213006561452014204 0ustar0000000000000000The 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.22.1.0/Setup.hs0000644000000000000000000000005613006232452014626 0ustar0000000000000000import Distribution.Simple main = defaultMain pandoc-sidenote-0.22.1.0/pandoc-sidenote.cabal0000644000000000000000000000330414007731410017231 0ustar0000000000000000cabal-version: 1.12 -- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack -- -- hash: 3254d38cc2ede0c149f9fb2b31e4d3c4e6a8405ceca46977c999a22ebe309b38 name: pandoc-sidenote version: 0.22.1.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 -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 -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.22.1.0/README.md0000644000000000000000000000477113777473772014514 0ustar0000000000000000# 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]. 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 | | ------ | --------------- | | 2.11 | 0.22.0, 0.22.1 | | 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 ``` Side note: I run this command to generate the zip files attached to releases that are downloaded by the Homebrew formula: ``` make ``` It would be nice to get GitHub Actions set up to build and publish releases for each tagged commit automatically. ### 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 ``` ## License [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](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