{-# 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