@@ -100,20 +100,17 @@ module Text.Pandoc.Definition ( Pandoc(..)
100100 ) where
101101
102102import Data.Generics (Data , Typeable )
103- import Data.Ord (comparing )
104103import Data.Aeson hiding (Null )
105104import Data.Aeson.TH (deriveJSON )
106105import qualified Data.Aeson.Types as Aeson
107106import qualified Data.Map as M
108107import Data.Text (Text )
109- import qualified Data.Text as T
110108import GHC.Generics (Generic )
111- import Data.String
112109import Control.DeepSeq
113- import Paths_pandoc_types (version )
114- import Data.Version (Version , versionBranch )
110+ import Data.Version (versionBranch )
115111import Data.Semigroup (Semigroup (.. ))
116- import Control.Arrow (second )
112+
113+ import Text.Pandoc.Definition.Functors
117114
118115data Pandoc = Pandoc Meta [Block ]
119116 deriving (Eq , Ord , Read , Show , Typeable , Data , Generic )
@@ -141,15 +138,6 @@ newtype MetaValue = MetaValue
141138 { unMetaValue :: MetaValueF Inline Block MetaValue }
142139 deriving (Eq , Ord , Show , Read , Typeable , Data , Generic )
143140
144- data MetaValueF inline block metaValue
145- = MetaMap (M. Map Text metaValue )
146- | MetaList [metaValue ]
147- | MetaBool Bool
148- | MetaString Text
149- | MetaInlines [inline ]
150- | MetaBlocks [block ]
151- deriving (Eq , Ord , Show , Read , Typeable , Data , Generic )
152-
153141nullMeta :: Meta
154142nullMeta = Meta M. empty
155143
@@ -195,247 +183,40 @@ docDate meta =
195183 Just (MetaBlocks [Block (Para ils)]) -> ils
196184 _ -> []
197185
198- -- | List attributes. The first element of the triple is the
199- -- start number of the list.
200- type ListAttributes = (Int , ListNumberStyle , ListNumberDelim )
201-
202- -- | Style of list numbers.
203- data ListNumberStyle = DefaultStyle
204- | Example
205- | Decimal
206- | LowerRoman
207- | UpperRoman
208- | LowerAlpha
209- | UpperAlpha deriving (Eq , Ord , Show , Read , Typeable , Data , Generic )
210-
211- -- | Delimiter of list numbers.
212- data ListNumberDelim = DefaultDelim
213- | Period
214- | OneParen
215- | TwoParens deriving (Eq , Ord , Show , Read , Typeable , Data , Generic )
216-
217- -- | Attributes: identifier, classes, key-value pairs
218- type Attr = (Text , [Text ], [(Text , Text )])
219-
220- nullAttr :: Attr
221- nullAttr = (" " ,[] ,[] )
222-
223- -- | Formats for raw blocks
224- newtype Format = Format Text
225- deriving (Read , Show , Typeable , Data , Generic , ToJSON , FromJSON )
226-
227- instance IsString Format where
228- fromString f = Format $ T. toCaseFold $ T. pack f
229-
230- instance Eq Format where
231- Format x == Format y = T. toCaseFold x == T. toCaseFold y
232-
233- instance Ord Format where
234- compare (Format x) (Format y) = compare (T. toCaseFold x) (T. toCaseFold y)
235-
236- -- | The number of columns taken up by the row head of each row of a
237- -- 'TableBody'. The row body takes up the remaining columns.
238- newtype RowHeadColumns = RowHeadColumns Int
239- deriving (Eq , Ord , Show , Read , Typeable , Data , Generic , Num , Enum , ToJSON , FromJSON )
240-
241- -- | Alignment of a table column.
242- data Alignment = AlignLeft
243- | AlignRight
244- | AlignCenter
245- | AlignDefault deriving (Eq , Ord , Show , Read , Typeable , Data , Generic )
246-
247- -- | The width of a table column, as a percentage of the text width.
248- data ColWidth = ColWidth Double
249- | ColWidthDefault deriving (Eq , Ord , Show , Read , Typeable , Data , Generic )
250-
251- -- | The specification for a single table column.
252- type ColSpec = (Alignment , ColWidth )
253-
254186-- | A table row.
255187type Row = RowF Block
256- data RowF block = Row Attr [CellF block ]
257- deriving ( Eq , Ord , Show , Read , Typeable , Data , Generic
258- , Functor , Foldable , Traversable
259- )
260188
261189-- | The head of a table.
262190type TableHead = TableHeadF Block
263- data TableHeadF block = TableHead Attr [RowF block ]
264- deriving ( Eq , Ord , Show , Read , Typeable , Data , Generic
265- , Functor , Foldable , Traversable
266- )
267191
268192-- | A body of a table, with an intermediate head, intermediate body,
269193-- and the specified number of row header columns in the intermediate
270194-- body.
271195type TableBody = TableBodyF Block
272- data TableBodyF block = TableBody Attr RowHeadColumns [RowF block ] [RowF block ]
273- deriving ( Eq , Ord , Show , Read , Typeable , Data , Generic
274- , Functor , Foldable , Traversable
275- )
276196
277197-- | The foot of a table.
278198type TableFoot = TableFootF Block
279- data TableFootF block = TableFoot Attr [RowF block ]
280- deriving ( Eq , Ord , Show , Read , Typeable , Data , Generic
281- , Functor , Foldable , Traversable
282- )
283199
284200-- | A short caption, for use in, for instance, lists of figures.
285- type ShortCaption = [Inline ]
286- type ShortCaptionF inline = [inline ]
201+ type ShortCaption = ShortCaptionF Inline
287202
288203-- | The caption of a table, with an optional short caption.
289204type Caption = CaptionF Inline Block
290- data CaptionF inline block = Caption (Maybe (ShortCaptionF inline )) [block ]
291- deriving ( Eq , Ord , Show , Read , Typeable , Data , Generic
292- , Functor , Foldable , Traversable
293- )
294205
295206-- | A table cell.
296207type Cell = CellF Block
297- data CellF block = Cell Attr Alignment RowSpan ColSpan [block ]
298- deriving ( Eq , Ord , Show , Read , Typeable , Data , Generic
299- , Functor , Foldable , Traversable
300- )
301-
302- -- | The number of rows occupied by a cell; the height of a cell.
303- newtype RowSpan = RowSpan Int
304- deriving (Eq , Ord , Show , Read , Typeable , Data , Generic , Num , Enum , ToJSON , FromJSON )
305-
306- -- | The number of columns occupied by a cell; the width of a cell.
307- newtype ColSpan = ColSpan Int
308- deriving (Eq , Ord , Show , Read , Typeable , Data , Generic , Num , Enum , ToJSON , FromJSON )
309208
310209-- | Block element.
311210newtype Block = Block { unBlock :: BlockF Inline Block }
312211 deriving (Eq , Ord , Read , Show , Typeable , Data , Generic )
313212
314- -- | Block element functor
315- data BlockF inline block
316- -- | Plain text, not a paragraph
317- = Plain [inline ]
318- -- | Paragraph
319- | Para [inline ]
320- -- | Multiple non-breaking lines
321- | LineBlock [[inline ]]
322- -- | Code block (literal) with attributes
323- | CodeBlock Attr Text
324- -- | Raw block
325- | RawBlock Format Text
326- -- | Block quote (list of blocks)
327- | BlockQuote [block ]
328- -- | Ordered list (attributes and a list of items, each a list of
329- -- blocks)
330- | OrderedList ListAttributes [[block ]]
331- -- | Bullet list (list of items, each a list of blocks)
332- | BulletList [[block ]]
333- -- | Definition list. Each list item is a pair consisting of a
334- -- term (a list of inlines) and one or more definitions (each a
335- -- list of blocks)
336- | DefinitionList [([inline ],[[block ]])]
337- -- | Header - level (integer) and text (inlines)
338- | Header Int Attr [inline ]
339- -- | Horizontal rule
340- | HorizontalRule
341- -- | Table, with attributes, caption, optional short caption,
342- -- column alignments and widths (required), table head, table
343- -- bodies, and table foot
344- | Table Attr (CaptionF inline block ) [ColSpec ] (TableHeadF block ) [TableBodyF block ] (TableFootF block )
345- -- | Generic block container with attributes
346- | Div Attr [block ]
347- -- | Nothing
348- | Null
349- deriving ( Eq , Ord , Read , Show , Typeable , Data , Generic
350- , Functor , Foldable , Traversable
351- )
352-
353- -- | Type of quotation marks to use in Quoted inline.
354- data QuoteType = SingleQuote | DoubleQuote deriving (Show , Eq , Ord , Read , Typeable , Data , Generic )
355-
356- -- | Link target (URL, title).
357- type Target = (Text , Text )
358-
359- isFigureTarget :: Target -> Maybe Target
360- isFigureTarget tgt
361- | (src, Just tit) <- second (T. stripPrefix " fig:" ) tgt = Just (src, tit)
362- | otherwise = Nothing
363-
364- -- | Bidirectional patter synonym
365- --
366- -- It can pass as a Block constructor
367- --
368- -- >>> SimpleFigure nullAttr [] (T.pack "", T.pack "title")
369- -- Para [Image ("",[],[]) [] ("","fig:title")]
370- --
371- --
372- -- It can be used to pattern match
373- -- >>> let img = Para [Image undefined undefined (undefined, T.pack "title")]
374- -- >>> case img of { SimpleFigure _ _ _ -> True; _ -> False }
375- -- False
376- -- >>> let fig = Para [Image undefined undefined (undefined, T.pack "fig:title")]
377- -- >>> case fig of { SimpleFigure _ _ tit -> snd tit; _ -> T.pack "" }
378- -- "title"
379- pattern SimpleFigure :: Attr -> [inline ] -> Target -> BlockF (InlineF block inline ) block
380- pattern SimpleFigure attr figureCaption tgt <-
381- Para [Image attr figureCaption
382- (isFigureTarget -> Just tgt)] where
383- SimpleFigure attr figureCaption tgt =
384- Para [Image attr figureCaption (second (" fig:" <> ) tgt)]
385-
386-
387- -- | Type of math element (display or inline).
388- data MathType = DisplayMath | InlineMath deriving (Show , Eq , Ord , Read , Typeable , Data , Generic )
389213
390214-- | Inline elements.
391215newtype Inline = Inline { unInline :: InlineF Block Inline }
392216 deriving (Show , Eq , Ord , Read , Typeable , Data , Generic )
393217
394- data InlineF block inline
395- = Str Text -- ^ Text (string)
396- | Emph [inline ] -- ^ Emphasized text (list of inlines)
397- | Underline [inline ] -- ^ Underlined text (list of inlines)
398- | Strong [inline ] -- ^ Strongly emphasized text (list of inlines)
399- | Strikeout [inline ] -- ^ Strikeout text (list of inlines)
400- | Superscript [inline ] -- ^ Superscripted text (list of inlines)
401- | Subscript [inline ] -- ^ Subscripted text (list of inlines)
402- | SmallCaps [inline ] -- ^ Small caps text (list of inlines)
403- | Quoted QuoteType [inline ] -- ^ Quoted text (list of inlines)
404- | Cite [CitationF inline ] [inline ] -- ^ Citation (list of inlines)
405- | Code Attr Text -- ^ Inline code (literal)
406- | Space -- ^ Inter-word space
407- | SoftBreak -- ^ Soft line break
408- | LineBreak -- ^ Hard line break
409- | Math MathType Text -- ^ TeX math (literal)
410- | RawInline Format Text -- ^ Raw inline
411- | Link Attr [inline ] Target -- ^ Hyperlink: alt text (list of inlines), target
412- | Image Attr [inline ] Target -- ^ Image: alt text (list of inlines), target
413- | Note [block ] -- ^ Footnote or endnote
414- | Span Attr [inline ] -- ^ Generic inline container with attributes
415- deriving ( Show , Eq , Ord , Read , Typeable , Data , Generic
416- , Functor , Foldable , Traversable
417- )
418-
419218type Citation = CitationF Inline
420219
421- data CitationF inline = Citation
422- { citationId :: Text
423- , citationPrefix :: [inline ]
424- , citationSuffix :: [inline ]
425- , citationMode :: CitationMode
426- , citationNoteNum :: Int
427- , citationHash :: Int
428- }
429- deriving ( Show , Eq , Read , Typeable , Data , Generic
430- , Functor , Foldable , Traversable
431- )
432-
433- instance Eq inline => Ord (CitationF inline ) where
434- compare = comparing citationHash
435-
436- data CitationMode = AuthorInText | SuppressAuthor | NormalCitation
437- deriving (Show , Eq , Ord , Read , Typeable , Data , Generic )
438-
439220
440221-- ToJSON/FromJSON instances. Some are defined by hand so that we have
441222-- more control over the format.
@@ -446,24 +227,7 @@ $(let jsonOpts = defaultOptions
446227 }
447228 in fmap concat $ traverse (deriveJSON jsonOpts)
448229 [ ''MetaValue
449- , ''MetaValueF
450- , ''CitationMode
451- , ''CitationF
452- , ''QuoteType
453- , ''MathType
454- , ''ListNumberStyle
455- , ''ListNumberDelim
456- , ''Alignment
457- , ''ColWidth
458- , ''RowF
459- , ''CaptionF
460- , ''TableHeadF
461- , ''TableBodyF
462- , ''TableFootF
463- , ''CellF
464- , ''InlineF
465230 , ''Inline
466- , ''BlockF
467231 , ''Block
468232 ])
469233
@@ -506,30 +270,6 @@ instance ToJSON Pandoc where
506270-- Instances for deepseq
507271instance NFData Meta
508272instance NFData MetaValue
509- instance (NFData block , NFData inline , NFData metaValue ) => NFData (MetaValueF inline block metaValue )
510- instance NFData inline => NFData (CitationF inline )
511- instance NFData Alignment
512- instance NFData RowSpan
513- instance NFData ColSpan
514- instance NFData block => NFData (CellF block )
515- instance NFData block => NFData (RowF block )
516- instance NFData block => NFData (TableHeadF block )
517- instance NFData block => NFData (TableBodyF block )
518- instance NFData block => NFData (TableFootF block )
519- instance (NFData block , NFData inline ) => NFData (CaptionF block inline )
520- instance (NFData block , NFData inline ) => NFData (InlineF block inline )
521273instance NFData Inline
522- instance NFData MathType
523- instance NFData Format
524- instance NFData CitationMode
525- instance NFData QuoteType
526- instance NFData ListNumberDelim
527- instance NFData ListNumberStyle
528- instance NFData ColWidth
529- instance NFData RowHeadColumns
530- instance (NFData inline , NFData block ) => NFData (BlockF inline block )
531274instance NFData Block
532275instance NFData Pandoc
533-
534- pandocTypesVersion :: Version
535- pandocTypesVersion = version
0 commit comments