pandoc-sidenote 0.22.1.0 → 0.22.2.0
raw patch · 3 files changed
+65/−37 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Pandoc.SideNote: instance GHC.Classes.Eq Text.Pandoc.SideNote.NoteType
+ Text.Pandoc.SideNote: instance GHC.Show.Show Text.Pandoc.SideNote.NoteType
Files
- README.md +31/−18
- pandoc-sidenote.cabal +3/−3
- src/Text/Pandoc/SideNote.hs +31/−16
README.md view
@@ -3,8 +3,9 @@ > 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.+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@@ -18,12 +19,12 @@ `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 |+| pandoc | pandoc-sidenote |+| ------ | --------------- |+| 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.@@ -47,16 +48,6 @@ 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@@ -75,6 +66,27 @@ 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)@@ -84,3 +96,4 @@ [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.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack ----- hash: 3254d38cc2ede0c149f9fb2b31e4d3c4e6a8405ceca46977c999a22ebe309b38+-- hash: e712e01510e2d82b850389e6edbfb9aeb4d179bc41dea50152b5ccd7f82012bc name: pandoc-sidenote-version: 0.22.1.0+version: 0.22.2.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
src/Text/Pandoc/SideNote.hs view
@@ -4,18 +4,31 @@ module Text.Pandoc.SideNote (usingSideNotes) where import Data.List (intercalate)-import Data.Text (Text, append, pack)+import Data.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+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] @@ -26,7 +39,7 @@ put (i + 1) return i --- Extract inlines from blocks+-- Extract inlines from blocks. Note has a [Block], but Span needs [Inline]. coerceToInline :: [Block] -> [Inline] coerceToInline = concatMap deBlock . walk deNote where@@ -46,18 +59,11 @@ deNote (Note _) = Str "" deNote x = x -filterInline :: Inline -> State Int Inline-filterInline (Note blocks) = do+filterNote :: Bool -> [Inline] -> State Int Inline+filterNote nonu content = 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 ""@@ -82,9 +88,18 @@ let (ident, _, attrs) = nullAttr let noteTypeCls = if nonu then "marginnote" else "sidenote"- let note = Span (ident, [noteTypeCls], attrs) content'+ 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