1 {-# LANGUAGE DisambiguateRecordFields #-}
2 {-# LANGUAGE DuplicateRecordFields #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 {-# LANGUAGE OverloadedStrings #-}
6 module Language.DTC.Document
7 ( module Language.DTC.Document
11 import Data.Default.Class (Default(..))
12 import Data.Default.Instances.Containers ()
14 import Data.Function (on, ($))
16 import Data.Map.Strict (Map)
17 import Data.Maybe (Maybe(..))
18 import Data.Monoid (Monoid(..))
19 import Data.Ord (Ord(..))
20 import Data.Semigroup (Semigroup(..))
21 import Data.Sequence (Seq, ViewR(..), viewr)
22 import Data.TreeSeq.Strict (Trees)
23 import Text.Show (Show)
24 import qualified Data.Char as Char
25 import qualified Data.Text.Lazy as TL
35 instance Default Document where
46 instance Default Head where
58 , editor :: Maybe Entity
63 , includes :: [Include]
65 instance Default About where
78 instance Semigroup About where
80 { headers = headers x <> headers y
81 , titles = titles x <> titles y
82 , url = url (x::About) <> url (y::About)
83 , authors = authors x <> authors y
84 , editor = editor x <> editor y
85 , date = date x <> date y
86 , tags = tags x <> tags y
87 , links = links x <> links y
88 , series = series x <> series y
89 , includes = includes x <> includes y
100 type Body = Trees BodyNode
102 -- ** Type 'BodyNode'
104 = BodySection { pos :: Pos
105 , attrs :: CommonAttrs
109 | BodyBlock Block -- ^ leaf
115 | BlockBreak { attrs :: CommonAttrs }
116 | BlockToC { pos :: Pos
117 , attrs :: CommonAttrs
120 | BlockToF { pos :: Pos
121 , attrs :: CommonAttrs
124 | BlockFigure { pos :: Pos
125 , attrs :: CommonAttrs
127 , mayTitle :: Maybe Title
130 | BlockIndex { pos :: Pos
131 , attrs :: CommonAttrs
134 | BlockReferences { pos :: Pos
135 , attrs :: CommonAttrs
136 , refs :: [Reference]
142 = ParaItem { item :: ParaItem }
143 | ParaItems { pos :: Pos
144 , attrs :: CommonAttrs
145 , items :: [ParaItem]
149 -- ** Type 'ParaItem'
152 | ParaComment TL.Text
155 | ParaQuote { type_ :: TL.Text
158 | ParaArtwork { type_ :: TL.Text
163 -- *** Type 'ListItem'
165 = ListItem { name :: TL.Text
171 type Plain = Trees PlainNode
173 -- ** Type 'PlainNode'
177 | PlainCode -- ^ Code (monospaced)
178 | PlainDel -- ^ Deleted (crossed-over)
180 | PlainGroup -- ^ Group subTrees (neutral)
182 | PlainSC -- ^ Small Caps
183 | PlainSub -- ^ Subscript
184 | PlainSup -- ^ Superscript
185 | PlainU -- ^ Underlined
186 | PlainEref { href :: URL } -- ^ External reference
187 | PlainIref { anchor :: Maybe Anchor
189 } -- ^ Index reference
190 | PlainRef { to :: Ident }
192 | PlainRref { anchor :: Maybe Anchor
194 } -- ^ Reference reference
195 | PlainSpan { attrs :: CommonAttrs } -- ^ Neutral node
197 | PlainBreak -- ^ Line break (\n)
199 | PlainNote { number :: Maybe Nat1
207 { posAncestors :: PosPath
208 , posAncestorsWithFigureNames :: PosPath
209 , posPrecedingsSiblings :: Map XmlName Rank
211 instance Ord Pos where
212 compare = compare `on` posAncestors
213 instance Default Pos where
214 def = Pos mempty mempty mempty
216 -- *** Type 'PosPath'
217 type PosPath = Seq (XmlName,Rank)
219 posParent :: PosPath -> Maybe PosPath
225 -- * Type 'CommonAttrs'
229 , classes :: [TL.Text]
231 instance Default CommonAttrs where
242 } deriving (Eq,Ord,Show)
245 newtype Title = Title { unTitle :: Plain }
246 deriving (Eq,Show,Semigroup,Monoid,Default)
261 , org :: Maybe Entity
263 instance Default Entity where
277 instance Semigroup Entity where
285 instance Default Include where
290 -- * Type 'Reference'
296 reference :: Ident -> Reference
302 instance Default Reference where
309 , month :: Maybe Nat1
312 instance Default Date where
315 , month = Just (Nat1 01)
316 , day = Just (Nat1 01)
318 instance Semigroup Date where
327 , type_ :: Maybe TL.Text
330 instance Default Link where
344 instance Default Alias where
355 instance Default Serie where
361 -- | Builtins 'URL' recognized from |Serie|'s 'name'.
362 urlSerie :: Serie -> Maybe URL
363 urlSerie Serie{id=id_, name} =
365 "RFC" | TL.all Char.isDigit id_ ->
366 Just $ URL $ "https://tools.ietf.org/html/rfc"<>id_
367 "DOI" -> Just $ URL $ "https://dx.doi.org/"<>id_
374 type Words = [WordOrSpace]
376 -- *** Type 'WordOrSpace'
380 deriving (Eq,Ord,Show)
383 type Aliases = [Words]
386 type Terms = [Aliases]