pax_global_header00006660000000000000000000000064144337575720014533gustar00rootroot0000000000000052 comment=3fd65bc302838c6bca25e0fd3c78292cf227cfd2 pandoc-sidenote-0.23.0/000077500000000000000000000000001443375757200146715ustar00rootroot00000000000000pandoc-sidenote-0.23.0/.gitignore000066400000000000000000000000431443375757200166560ustar00rootroot00000000000000.*.sw[nop] tags .stack-work *.zip pandoc-sidenote-0.23.0/LICENSE000066400000000000000000000020721443375757200156770ustar00rootroot00000000000000The 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.hs000066400000000000000000000002311443375757200161050ustar00rootroot00000000000000module Main where import Text.Pandoc.SideNote (usingSideNotes) import Text.Pandoc.JSON (toJSONFilter) main :: IO () main = toJSONFilter usingSideNotes pandoc-sidenote-0.23.0/Makefile000066400000000000000000000005631443375757200163350ustar00rootroot00000000000000VERSION := 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.md000066400000000000000000000055201443375757200161520ustar00rootroot00000000000000# 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 [![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 [Pandoc Markdown CSS Theme]: https://github.com/jez/pandoc-markdown-css-theme pandoc-sidenote-0.23.0/Setup.hs000066400000000000000000000000561443375757200163260ustar00rootroot00000000000000import Distribution.Simple main = defaultMain pandoc-sidenote-0.23.0/package.yaml000066400000000000000000000021451443375757200171520ustar00rootroot00000000000000name: 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.cabal000066400000000000000000000033241443375757200207330ustar00rootroot00000000000000cabal-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/000077500000000000000000000000001443375757200154605ustar00rootroot00000000000000pandoc-sidenote-0.23.0/src/Text/000077500000000000000000000000001443375757200164045ustar00rootroot00000000000000pandoc-sidenote-0.23.0/src/Text/Pandoc/000077500000000000000000000000001443375757200176105ustar00rootroot00000000000000pandoc-sidenote-0.23.0/src/Text/Pandoc/SideNote.hs000066400000000000000000000072061443375757200216630ustar00rootroot00000000000000{-# 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
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 filterNote :: Bool -> [Inline] -> State Int Inline filterNote nonu content = do -- Generate a unique number for the 'for=' attribute i <- getThenIncr 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 -> State Int Inline filterInline (Note blocks) = do -- The '{-}' symbol differentiates between margin note and side note -- Also '{.}' indicates whether to leave the footnote untouched (a footnote) case (getFirstStr blocks) of (FootNote, blocks') -> return (Note blocks') (MarginNote, blocks') -> filterNote True (coerceToInline blocks') (SideNote, blocks') -> filterNote False (coerceToInline blocks') filterInline inline = return inline usingSideNotes :: Pandoc -> Pandoc usingSideNotes (Pandoc meta blocks) = Pandoc meta (evalState (walkM filterInline blocks) 0) pandoc-sidenote-0.23.0/stack.yaml000066400000000000000000000001431443375757200166600ustar00rootroot00000000000000flags: {} extra-package-dbs: [] packages: - '.' extra-deps: - pandoc-types-1.23 resolver: lts-18.0 pandoc-sidenote-0.23.0/stack.yaml.lock000066400000000000000000000013201443375757200176050ustar00rootroot00000000000000# This file was autogenerated by Stack. # You should not edit this file by hand. # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files packages: - completed: hackage: pandoc-types-1.23@sha256:bf5eac74d6b805520bd57a7be12af09370edde1a86ebffa9ff83eb9c9d860041,4140 pantry-tree: sha256: 26e9cbed29980acc5fe0dcf5c427d9eb414c044f87d2447c36f588fd73b02dca size: 737 original: hackage: pandoc-types-1.23 snapshots: - completed: sha256: c632012da648385b9fa3c29f4e0afd56ead299f1c5528ee789058be410e883c0 size: 585393 url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/0.yaml original: lts-18.0