pandoc-3.10: Conversion between markup formats

Copyright | Copyright (C) 2022-2024 John MacFarlane
License | GNU GPL, version 2 or above
Maintainer | John MacFarlane <jgm@berkeley.edu>
Stability | alpha
Portability | portable
Safe Haskell | None
Language | Haskell2010

Text.Pandoc.Chunks

Description

Functions and types for splitting a Pandoc into subdocuments, e.g. for conversion into a set of HTML pages.

Synopsis

- data Chunk = Chunk {
  - chunkHeading :: [Inline]
  - chunkId :: Text
  - chunkLevel :: Int
  - chunkNumber :: Int
  - chunkSectionNumber :: Maybe Text
  - chunkPath :: FilePath
  - chunkUp :: Maybe Chunk
  - chunkPrev :: Maybe Chunk
  - chunkNext :: Maybe Chunk
  - chunkUnlisted :: Bool
  - chunkContents :: [Block]
  }
- data ChunkedDoc = ChunkedDoc {
  - chunkedMeta :: Meta
  - chunkedTOC :: Tree SecInfo
  - chunkedChunks :: [Chunk]
  }
- newtype PathTemplate = PathTemplate {
  - unPathTemplate :: Text
  }
- splitIntoChunks :: PathTemplate -> Bool -> Maybe Int -> Int -> Pandoc -> ChunkedDoc
- toTOCTree :: [Block] -> Tree SecInfo
- tocToList :: Bool -> Int -> Tree SecInfo -> Block
- data SecInfo = SecInfo {
  - secTitle :: [Inline]
  - secNumber :: Maybe Text
  - secId :: Text
  - secPath :: Text
  - secLevel :: Int
  }

# Documentation

data Chunk Source #

A part of a document (typically a chapter or section, or the part of a section before its subsections).

Constructors

Chunk |

Fields

- chunkHeading :: [Inline]
- chunkId :: Text
- chunkLevel :: Int
- chunkNumber :: Int
- chunkSectionNumber :: Maybe Text
- chunkPath :: FilePath
- chunkUp :: Maybe Chunk
- chunkPrev :: Maybe Chunk
- chunkNext :: Maybe Chunk
- chunkUnlisted :: Bool
- chunkContents :: [Block]

#### Instances

Instances details

Generic Chunk Source # |

Instance details

Defined in Text.Pandoc.Chunks

Associated Types

type Rep Chunk |

Instance details

Defined in Text.Pandoc.Chunks

type Rep Chunk = D1 ('MetaData "Chunk" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'False) (C1 ('MetaCons "Chunk" 'PrefixI 'True) (((S1 ('MetaSel ('Just "chunkHeading") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Inline]) :*: S1 ('MetaSel ('Just "chunkId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "chunkLevel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: (S1 ('MetaSel ('Just "chunkNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "chunkSectionNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))))) :*: ((S1 ('MetaSel ('Just "chunkPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FilePath) :*: (S1 ('MetaSel ('Just "chunkUp") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Chunk)) :*: S1 ('MetaSel ('Just "chunkPrev") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Chunk)))) :*: (S1 ('MetaSel ('Just "chunkNext") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Chunk)) :*: (S1 ('MetaSel ('Just "chunkUnlisted") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "chunkContents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Block]))))))

Methods

from :: Chunk -> Rep Chunk x Source #

to :: Rep Chunk x -> Chunk Source #

Show Chunk Source # |
Instance details Defined in Text.Pandoc.Chunks Methods showsPrec :: Int -> Chunk -> ShowS Source # show :: Chunk -> String Source # showList :: [Chunk] -> ShowS Source #
Eq Chunk Source # |
Instance details Defined in Text.Pandoc.Chunks Methods (==) :: Chunk -> Chunk -> Bool Source # (/=) :: Chunk -> Chunk -> Bool Source #
Walkable Block Chunk Source # |
Instance details Defined in Text.Pandoc.Chunks Methods walk :: (Block -> Block) -> Chunk -> Chunk Source # walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> Chunk -> m Chunk Source # query :: Monoid c => (Block -> c) -> Chunk -> c Source #
Walkable Inline Chunk Source # |
Instance details Defined in Text.Pandoc.Chunks Methods walk :: (Inline -> Inline) -> Chunk -> Chunk Source # walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> Chunk -> m Chunk Source # query :: Monoid c => (Inline -> c) -> Chunk -> c Source #
type Rep Chunk Source # |

Instance details

Defined in Text.Pandoc.Chunks

type Rep Chunk = D1 ('MetaData "Chunk" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'False) (C1 ('MetaCons "Chunk" 'PrefixI 'True) (((S1 ('MetaSel ('Just "chunkHeading") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Inline]) :*: S1 ('MetaSel ('Just "chunkId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "chunkLevel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: (S1 ('MetaSel ('Just "chunkNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int) :*: S1 ('MetaSel ('Just "chunkSectionNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))))) :*: ((S1 ('MetaSel ('Just "chunkPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FilePath) :*: (S1 ('MetaSel ('Just "chunkUp") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Chunk)) :*: S1 ('MetaSel ('Just "chunkPrev") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Chunk)))) :*: (S1 ('MetaSel ('Just "chunkNext") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Chunk)) :*: (S1 ('MetaSel ('Just "chunkUnlisted") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "chunkContents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Block]))))))

data ChunkedDoc Source #

A `Pandoc` broken into `Chunk`s for writing to separate files.

Constructors

ChunkedDoc |

Fields

- chunkedMeta :: Meta
- chunkedTOC :: Tree SecInfo
- chunkedChunks :: [Chunk]

#### Instances

Instances details

Generic ChunkedDoc Source # |

Instance details

Defined in Text.Pandoc.Chunks

Associated Types

type Rep ChunkedDoc |

Instance details

Defined in Text.Pandoc.Chunks

type Rep ChunkedDoc = D1 ('MetaData "ChunkedDoc" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'False) (C1 ('MetaCons "ChunkedDoc" 'PrefixI 'True) (S1 ('MetaSel ('Just "chunkedMeta") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Meta) :*: (S1 ('MetaSel ('Just "chunkedTOC") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Tree SecInfo)) :*: S1 ('MetaSel ('Just "chunkedChunks") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Chunk]))))

Methods

from :: ChunkedDoc -> Rep ChunkedDoc x Source #

to :: Rep ChunkedDoc x -> ChunkedDoc Source #

Show ChunkedDoc Source # |
Instance details Defined in Text.Pandoc.Chunks Methods showsPrec :: Int -> ChunkedDoc -> ShowS Source # show :: ChunkedDoc -> String Source # showList :: [ChunkedDoc] -> ShowS Source #
Eq ChunkedDoc Source # |
Instance details Defined in Text.Pandoc.Chunks Methods (==) :: ChunkedDoc -> ChunkedDoc -> Bool Source # (/=) :: ChunkedDoc -> ChunkedDoc -> Bool Source #
Walkable Block ChunkedDoc Source # |
Instance details Defined in Text.Pandoc.Chunks Methods walk :: (Block -> Block) -> ChunkedDoc -> ChunkedDoc Source # walkM :: (Monad m, Applicative m, Functor m) => (Block -> m Block) -> ChunkedDoc -> m ChunkedDoc Source # query :: Monoid c => (Block -> c) -> ChunkedDoc -> c Source #
Walkable Inline ChunkedDoc Source # |
Instance details Defined in Text.Pandoc.Chunks Methods walk :: (Inline -> Inline) -> ChunkedDoc -> ChunkedDoc Source # walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> ChunkedDoc -> m ChunkedDoc Source # query :: Monoid c => (Inline -> c) -> ChunkedDoc -> c Source #
type Rep ChunkedDoc Source # |

Instance details

Defined in Text.Pandoc.Chunks

type Rep ChunkedDoc = D1 ('MetaData "ChunkedDoc" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'False) (C1 ('MetaCons "ChunkedDoc" 'PrefixI 'True) (S1 ('MetaSel ('Just "chunkedMeta") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Meta) :*: (S1 ('MetaSel ('Just "chunkedTOC") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Tree SecInfo)) :*: S1 ('MetaSel ('Just "chunkedChunks") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Chunk]))))

newtype PathTemplate Source #

A `PathTemplate` is a FilePath in which certain codes will be substituted with information from a `Chunk`. `%n` will be replaced with the chunk number (padded with leading 0s to 3 digits), `%s` with the section number of the heading, `%h` with the (stringified) heading text, `%i` with the section identifier. For example, `"section-%s-%i.html"` might be resolved to `"section-1.2-introduction.html"`.

Constructors

PathTemplate |

Fields

- unPathTemplate :: Text

#### Instances

Instances details

FromJSON PathTemplate Source # |
Instance details Defined in Text.Pandoc.Chunks Methods parseJSON :: Value -> Parser PathTemplate Source # parseJSONList :: Value -> Parser [PathTemplate] Source # omittedField :: Maybe PathTemplate Source #
ToJSON PathTemplate Source # |
Instance details Defined in Text.Pandoc.Chunks Methods toJSON :: PathTemplate -> Value Source # toEncoding :: PathTemplate -> Encoding Source # toJSONList :: [PathTemplate] -> Value Source # toEncodingList :: [PathTemplate] -> Encoding Source # omitField :: PathTemplate -> Bool Source #
Data PathTemplate Source # |

Instance details

Defined in Text.Pandoc.Chunks

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PathTemplate -> c PathTemplate Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PathTemplate Source #

toConstr :: PathTemplate -> Constr Source #

dataTypeOf :: PathTemplate -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PathTemplate) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PathTemplate) Source #

gmapT :: (forall b. Data b => b -> b) -> PathTemplate -> PathTemplate Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PathTemplate -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PathTemplate -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> PathTemplate -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> PathTemplate -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> PathTemplate -> m PathTemplate Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PathTemplate -> m PathTemplate Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PathTemplate -> m PathTemplate Source #

IsString PathTemplate Source # |
Instance details Defined in Text.Pandoc.Chunks Methods fromString :: String -> PathTemplate Source #
Generic PathTemplate Source # |

Instance details

Defined in Text.Pandoc.Chunks

Associated Types

type Rep PathTemplate |
Instance details Defined in Text.Pandoc.Chunks type Rep PathTemplate = D1 ('MetaData "PathTemplate" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'True) (C1 ('MetaCons "PathTemplate" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPathTemplate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))

Methods

from :: PathTemplate -> Rep PathTemplate x Source #

to :: Rep PathTemplate x -> PathTemplate Source #

Show PathTemplate Source # |
Instance details Defined in Text.Pandoc.Chunks Methods showsPrec :: Int -> PathTemplate -> ShowS Source # show :: PathTemplate -> String Source # showList :: [PathTemplate] -> ShowS Source #
type Rep PathTemplate Source # |
Instance details Defined in Text.Pandoc.Chunks type Rep PathTemplate = D1 ('MetaData "PathTemplate" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'True) (C1 ('MetaCons "PathTemplate" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPathTemplate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))

splitIntoChunks Source #

Arguments

:: PathTemplate | Template for filepath
-> Bool | Number sections
-> Maybe Int | Base heading level
-> Int | Chunk level -- level of section to split at
-> Pandoc |
-> ChunkedDoc |

Split `Pandoc` into `Chunk`s, e.g. for conversion into a set of HTML pages or EPUB chapters.

toTOCTree :: [Block] -> Tree SecInfo Source #

Create tree of sections with titles, links, and numbers, in a form that can be turned into a table of contents. Presupposes that the '[Block]' is the output of `makeSections`.

tocToList :: Bool -> Int -> Tree SecInfo -> Block Source #

Generate a table of contents of the given depth.

data SecInfo Source #

Data for a section in a hierarchical document.

Constructors

SecInfo |

Fields

- secTitle :: [Inline]
- secNumber :: Maybe Text
- secId :: Text
- secPath :: Text
- secLevel :: Int

#### Instances

Instances details

Generic SecInfo Source # |

Instance details

Defined in Text.Pandoc.Chunks

Associated Types

type Rep SecInfo |

Instance details

Defined in Text.Pandoc.Chunks

type Rep SecInfo = D1 ('MetaData "SecInfo" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'False) (C1 ('MetaCons "SecInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "secTitle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Inline]) :*: S1 ('MetaSel ('Just "secNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))) :*: (S1 ('MetaSel ('Just "secId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "secPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "secLevel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))))

Methods

from :: SecInfo -> Rep SecInfo x Source #

to :: Rep SecInfo x -> SecInfo Source #

Show SecInfo Source # |
Instance details Defined in Text.Pandoc.Chunks Methods showsPrec :: Int -> SecInfo -> ShowS Source # show :: SecInfo -> String Source # showList :: [SecInfo] -> ShowS Source #
Eq SecInfo Source # |
Instance details Defined in Text.Pandoc.Chunks Methods (==) :: SecInfo -> SecInfo -> Bool Source # (/=) :: SecInfo -> SecInfo -> Bool Source #
Walkable Inline SecInfo Source # |
Instance details Defined in Text.Pandoc.Chunks Methods walk :: (Inline -> Inline) -> SecInfo -> SecInfo Source # walkM :: (Monad m, Applicative m, Functor m) => (Inline -> m Inline) -> SecInfo -> m SecInfo Source # query :: Monoid c => (Inline -> c) -> SecInfo -> c Source #
type Rep SecInfo Source # |

Instance details

Defined in Text.Pandoc.Chunks

type Rep SecInfo = D1 ('MetaData "SecInfo" "Text.Pandoc.Chunks" "pandoc-3.10-HDtgLHV36vi9t4gfnv8HSy" 'False) (C1 ('MetaCons "SecInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "secTitle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Inline]) :*: S1 ('MetaSel ('Just "secNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))) :*: (S1 ('MetaSel ('Just "secId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "secPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "secLevel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))))