pandoc-sidenote-0.19.0.0/0000755000000000000000000000000013144145446013207 5ustar0000000000000000pandoc-sidenote-0.19.0.0/LICENSE0000644000000000000000000000207213144145446014215 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.19.0.0/Main.hs0000644000000000000000000000023113144145446014423 0ustar0000000000000000module Main where import Text.Pandoc.SideNote (usingSideNotes) import Text.Pandoc.JSON (toJSONFilter) main :: IO () main = toJSONFilter usingSideNotes pandoc-sidenote-0.19.0.0/pandoc-sidenote.cabal0000644000000000000000000000225413144145446017252 0ustar0000000000000000name: pandoc-sidenote version: 0.19.0.0 synopsis: Convert Pandoc Markdown-style footnotes into sidenotes description: Convert Pandoc Markdown-style footnotes into sidenotes homepage: https://github.com/jez/pandoc-sidenote#readme license: MIT license-file: LICENSE author: Jake Zimmerman maintainer: zimmerman.jake@gmail.com copyright: 2016 Jake Zimmerman category: CommandLine build-type: Simple -- extra-source-files: cabal-version: >=1.10 Library Exposed-modules: Text.Pandoc.SideNote hs-source-dirs: src build-depends: base < 5 , monad-gen , pandoc , pandoc-types default-language: Haskell2010 executable pandoc-sidenote hs-source-dirs: ./ main-is: Main.hs ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: base < 5 , pandoc-sidenote , pandoc-types default-language: Haskell2010 source-repository head type: git location: https://github.com/jez/pandoc-sidenote pandoc-sidenote-0.19.0.0/Setup.hs0000644000000000000000000000005613144145446014644 0ustar0000000000000000import Distribution.Simple main = defaultMain pandoc-sidenote-0.19.0.0/src/0000755000000000000000000000000013144145446013776 5ustar0000000000000000pandoc-sidenote-0.19.0.0/src/Text/0000755000000000000000000000000013144145446014722 5ustar0000000000000000pandoc-sidenote-0.19.0.0/src/Text/Pandoc/0000755000000000000000000000000013144145446016126 5ustar0000000000000000pandoc-sidenote-0.19.0.0/src/Text/Pandoc/SideNote.hs0000644000000000000000000000456513144145446020206 0ustar0000000000000000{-# LANGUAGE FlexibleContexts #-} module Text.Pandoc.SideNote (usingSideNotes) where import Data.List (intercalate) import Control.Monad.Gen import Text.Pandoc.Walk (walk, walkM) import Text.Pandoc.JSON getFirstStr :: [Inline] -> Maybe String getFirstStr [] = Nothing getFirstStr (Str text : _) = Just text getFirstStr (_ : inlines) = getFirstStr inlines newline :: [Inline] newline = [LineBreak, LineBreak] -- 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 -> Gen Int Inline filterInline (Note blocks) = do -- Generate a unique number for the 'for=' attribute i <- gen -- 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" ++ (if nonu then "" else " sidenote-number") let labelSym = if nonu then "⊕" else "" let labelHTML = "" let label = RawInline (Format "html") labelHTML let inputHTML = "" 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 nullAttr [label, input, note] filterInline inline = return inline usingSideNotes :: Pandoc -> Pandoc usingSideNotes (Pandoc meta blocks) = Pandoc meta (runGen (walkM filterInline blocks))