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
196 | PlainBreak -- ^ Line break (\n)
198 | PlainNote { number :: Maybe Nat1
206 { posAncestors :: PosPath
207 , posAncestorsWithFigureNames :: PosPath
208 , posPrecedingsSiblings :: Map XmlName Rank
210 instance Ord Pos where
211 compare = compare `on` posAncestors
212 instance Default Pos where
213 def = Pos mempty mempty mempty
215 -- *** Type 'PosPath'
216 type PosPath = Seq (XmlName,Rank)
218 posParent :: PosPath -> Maybe PosPath
224 -- * Type 'CommonAttrs'
228 , classes :: [TL.Text]
230 instance Default CommonAttrs where
241 } deriving (Eq,Ord,Show)
244 newtype Title = Title { unTitle :: Plain }
245 deriving (Eq,Show,Semigroup,Monoid,Default)
260 , org :: Maybe Entity
262 instance Default Entity where
276 instance Semigroup Entity where
284 instance Default Include where
289 -- * Type 'Reference'
295 reference :: Ident -> Reference
301 instance Default Reference where
308 , month :: Maybe Nat1
311 instance Default Date where
314 , month = Just (Nat1 01)
315 , day = Just (Nat1 01)
317 instance Semigroup Date where
326 , type_ :: Maybe TL.Text
329 instance Default Link where
343 instance Default Alias where
354 instance Default Serie where
360 -- | Builtins 'URL' recognized from |Serie|'s 'name'.
361 urlSerie :: Serie -> Maybe URL
362 urlSerie Serie{id=id_, name} =
364 "RFC" | TL.all Char.isDigit id_ ->
365 Just $ URL $ "https://tools.ietf.org/html/rfc"<>id_
366 "DOI" -> Just $ URL $ "https://dx.doi.org/"<>id_
373 type Words = [WordOrSpace]
375 -- *** Type 'WordOrSpace'
379 deriving (Eq,Ord,Show)
382 type Aliases = [Words]
385 type Terms = [Aliases]