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