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
57 , version :: Maybe TL.Text
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
153 -- *** Type 'ListItem'
155 = ListItem { name :: TL.Text
161 type Plain = Trees PlainNode
163 -- ** Type 'PlainNode'
167 | PlainCode -- ^ Code (monospaced)
168 | PlainDel -- ^ Deleted (crossed-over)
170 | PlainGroup -- ^ Group subTrees (neutral)
172 | PlainSC -- ^ Small Caps
173 | PlainSub -- ^ Subscript
174 | PlainSup -- ^ Superscript
175 | PlainU -- ^ Underlined
176 | PlainEref { href :: URL } -- ^ External reference
177 | PlainIref { anchor :: Maybe Anchor
179 } -- ^ Index reference
180 | PlainRef { to :: Ident }
182 | PlainRref { anchor :: Maybe Anchor
184 } -- ^ Reference reference
186 | PlainBR -- ^ Line break (\n)
188 | PlainNote { number :: Maybe Nat1
196 { posAncestors :: PosPath
197 , posAncestorsWithFigureNames :: PosPath
198 , posPrecedingsSiblings :: Map XmlName Rank
200 instance Ord Pos where
201 compare = compare `on` posAncestors
202 instance Default Pos where
203 def = Pos mempty mempty mempty
205 -- *** Type 'PosPath'
206 type PosPath = Seq (XmlName,Rank)
208 posParent :: PosPath -> Maybe PosPath
214 -- * Type 'CommonAttrs'
218 , classes :: [TL.Text]
220 instance Default CommonAttrs where
231 } deriving (Eq,Ord,Show)
234 newtype Title = Title { unTitle :: Plain }
235 deriving (Eq,Show,Semigroup,Monoid,Default)
250 , org :: Maybe Entity
252 instance Default Entity where
266 instance Semigroup Entity where
274 instance Default Include where
279 -- * Type 'Reference'
285 reference :: Ident -> Reference
291 instance Default Reference where
298 , month :: Maybe Nat1
301 instance Default Date where
304 , month = Just (Nat1 01)
305 , day = Just (Nat1 01)
307 instance Semigroup Date where
318 instance Default Link where
331 instance Default Alias where
342 instance Default Serie where
352 type Words = [WordOrSpace]
354 -- *** Type 'WordOrSpace'
358 deriving (Eq,Ord,Show)
361 type Aliases = [Words]
364 type Terms = [Aliases]