pandoc-sidenote (empty) → 0.19.0.0
raw patch · 5 files changed
+134/−0 lines, 5 filesdep +basedep +monad-gendep +pandocsetup-changed
Dependencies added: base, monad-gen, pandoc, pandoc-sidenote, pandoc-types
Files
- LICENSE +21/−0
- Main.hs +7/−0
- Setup.hs +2/−0
- pandoc-sidenote.cabal +36/−0
- src/Text/Pandoc/SideNote.hs +68/−0
+ LICENSE view
@@ -0,0 +1,21 @@+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.
+ Main.hs view
@@ -0,0 +1,7 @@+module Main where++import Text.Pandoc.SideNote (usingSideNotes)+import Text.Pandoc.JSON (toJSONFilter)++main :: IO ()+main = toJSONFilter usingSideNotes
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pandoc-sidenote.cabal view
@@ -0,0 +1,36 @@+name: 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
+ src/Text/Pandoc/SideNote.hs view
@@ -0,0 +1,68 @@+{-# 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 <div> 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 = "<label for=\"sn-" ++ show i ++ "\" class=\"" ++ labelCls ++ "\">" ++ labelSym ++ "</label>"+ let label = RawInline (Format "html") labelHTML++ let inputHTML = "<input type=\"checkbox\" id=\"sn-" ++ show i ++ "\" " ++ "class=\"margin-toggle\"/>"+ 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))