1 {-# LANGUAGE DisambiguateRecordFields #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Language.DTC.Document
6 ( module Language.DTC.Document
10 import Data.Default.Class (Default(..))
11 import Data.Default.Instances.Containers ()
13 import Data.Function (on)
15 import Data.Map.Strict (Map)
16 import Data.Maybe (Maybe(..))
17 import Data.Monoid (Monoid(..))
18 import Data.Ord (Ord(..))
19 import Data.Semigroup (Semigroup(..))
20 import Data.Sequence (Seq, ViewR(..), viewr)
21 import Data.TreeSeq.Strict (Trees)
22 import Text.Show (Show)
23 import qualified Data.Text.Lazy as TL
33 instance Default Document where
44 instance Default Head where
55 , editor :: Maybe Entity
58 , keywords :: [TL.Text]
61 , includes :: [Include]
63 instance Default About where
76 instance Semigroup About where
78 { titles = titles x <> titles y
79 , url = url (x::About) <> url (y::About)
80 , authors = authors x <> authors y
81 , editor = editor x <> editor y
82 , date = date x <> date y
83 , version = version x <> version y
84 , keywords = keywords x <> keywords y
85 , links = links x <> links y
86 , series = series x <> series y
87 , includes = includes x <> includes y
91 type Body = Trees BodyNode
95 = BodySection { pos :: Pos
96 , attrs :: CommonAttrs
100 | BodyBlock Block -- ^ leaf
106 | BlockToC { pos :: Pos
107 , attrs :: CommonAttrs
110 | BlockToF { pos :: Pos
111 , attrs :: CommonAttrs
114 | BlockFigure { pos :: Pos
115 , attrs :: CommonAttrs
117 , mayTitle :: Maybe Title
120 | BlockIndex { pos :: Pos
121 , attrs :: CommonAttrs
124 | BlockReferences { pos :: Pos
125 , attrs :: CommonAttrs
126 , refs :: [Reference]
132 = ParaItem { item :: ParaItem }
133 | ParaItems { pos :: Pos
134 , attrs :: CommonAttrs
135 , items :: [ParaItem]
139 -- ** Type 'ParaItem'
142 | ParaComment TL.Text
145 | ParaQuote { type_ :: TL.Text
148 | ParaArtwork { type_ :: TL.Text
154 type Plain = Trees PlainNode
156 -- ** Type 'PlainNode'
160 | PlainCode -- ^ Code (monospaced)
161 | PlainDel -- ^ Deleted (crossed-over)
163 | PlainGroup -- ^ Group subTrees (neutral)
165 | PlainSC -- ^ Small Caps
166 | PlainSub -- ^ Subscript
167 | PlainSup -- ^ Superscript
168 | PlainU -- ^ Underlined
169 | PlainEref { href :: URL } -- ^ External reference
170 | PlainIref { anchor :: Maybe Anchor
172 } -- ^ Index reference
173 | PlainRef { to :: Ident }
175 | PlainRref { anchor :: Maybe Anchor
177 } -- ^ Reference reference
179 | PlainBR -- ^ Line break (\n)
181 | PlainNote { number :: Maybe Nat1
189 { posAncestors :: PosPath
190 , posAncestorsWithFigureNames :: PosPath
191 , posPrecedingsSiblings :: Map XmlName Rank
193 instance Ord Pos where
194 compare = compare `on` posAncestors
195 instance Default Pos where
196 def = Pos mempty mempty mempty
198 -- *** Type 'PosPath'
199 type PosPath = Seq (XmlName,Rank)
201 posParent :: PosPath -> Maybe PosPath
207 -- * Type 'CommonAttrs'
211 , classes :: [TL.Text]
213 instance Default CommonAttrs where
224 } deriving (Eq,Ord,Show)
227 newtype Title = Title { unTitle :: Plain }
228 deriving (Eq,Show,Semigroup,Monoid,Default)
243 , org :: Maybe Entity
245 instance Default Entity where
259 instance Semigroup Entity where
267 instance Default Include where
272 -- * Type 'Reference'
278 reference :: Ident -> Reference
284 instance Default Reference where
291 , month :: Maybe Nat1
294 instance Default Date where
297 , month = Just (Nat1 01)
298 , day = Just (Nat1 01)
300 instance Semigroup Date where
311 instance Default Link where
324 instance Default Alias where
335 instance Default Serie where
345 type Words = [WordOrSpace]
347 -- *** Type 'WordOrSpace'
351 deriving (Eq,Ord,Show)
354 type Aliases = [Words]
357 type Terms = [Aliases]