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
57 , editor :: Maybe Entity
59 , version :: Maybe TL.Text
60 , keywords :: [TL.Text]
63 , includes :: [Include]
65 instance Default About where
78 instance Semigroup About where
80 { titles = titles x <> titles y
81 , url = url (x::About) <> url (y::About)
82 , authors = authors x <> authors y
83 , editor = editor x <> editor y
84 , date = date x <> date y
85 , version = version x <> version y
86 , keywords = keywords x <> keywords y
87 , links = links x <> links y
88 , series = series x <> series y
89 , includes = includes x <> includes y
93 type Body = Trees BodyNode
97 = BodySection { pos :: Pos
98 , attrs :: CommonAttrs
102 | BodyBlock Block -- ^ leaf
108 | BlockToC { pos :: Pos
109 , attrs :: CommonAttrs
112 | BlockToF { pos :: Pos
113 , attrs :: CommonAttrs
116 | BlockFigure { pos :: Pos
117 , attrs :: CommonAttrs
119 , mayTitle :: Maybe Title
122 | BlockIndex { pos :: Pos
123 , attrs :: CommonAttrs
126 | BlockReferences { pos :: Pos
127 , attrs :: CommonAttrs
128 , refs :: [Reference]
134 = ParaItem { item :: ParaItem }
135 | ParaItems { pos :: Pos
136 , attrs :: CommonAttrs
137 , items :: [ParaItem]
141 -- ** Type 'ParaItem'
144 | ParaComment TL.Text
147 | ParaQuote { type_ :: TL.Text
150 | ParaArtwork { type_ :: TL.Text
155 -- *** Type 'ListItem'
157 = ListItem { name :: TL.Text
163 type Plain = Trees PlainNode
165 -- ** Type 'PlainNode'
169 | PlainCode -- ^ Code (monospaced)
170 | PlainDel -- ^ Deleted (crossed-over)
172 | PlainGroup -- ^ Group subTrees (neutral)
174 | PlainSC -- ^ Small Caps
175 | PlainSub -- ^ Subscript
176 | PlainSup -- ^ Superscript
177 | PlainU -- ^ Underlined
178 | PlainEref { href :: URL } -- ^ External reference
179 | PlainIref { anchor :: Maybe Anchor
181 } -- ^ Index reference
182 | PlainRef { to :: Ident }
184 | PlainRref { anchor :: Maybe Anchor
186 } -- ^ Reference reference
188 | PlainBR -- ^ Line break (\n)
190 | PlainNote { number :: Maybe Nat1
198 { posAncestors :: PosPath
199 , posAncestorsWithFigureNames :: PosPath
200 , posPrecedingsSiblings :: Map XmlName Rank
202 instance Ord Pos where
203 compare = compare `on` posAncestors
204 instance Default Pos where
205 def = Pos mempty mempty mempty
207 -- *** Type 'PosPath'
208 type PosPath = Seq (XmlName,Rank)
210 posParent :: PosPath -> Maybe PosPath
216 -- * Type 'CommonAttrs'
220 , classes :: [TL.Text]
222 instance Default CommonAttrs where
233 } deriving (Eq,Ord,Show)
236 newtype Title = Title { unTitle :: Plain }
237 deriving (Eq,Show,Semigroup,Monoid,Default)
252 , org :: Maybe Entity
254 instance Default Entity where
268 instance Semigroup Entity where
276 instance Default Include where
281 -- * Type 'Reference'
287 reference :: Ident -> Reference
293 instance Default Reference where
300 , month :: Maybe Nat1
303 instance Default Date where
306 , month = Just (Nat1 01)
307 , day = Just (Nat1 01)
309 instance Semigroup Date where
320 instance Default Link where
333 instance Default Alias where
344 instance Default Serie where
350 -- | Builtins 'URL' recognized from |Serie|'s 'name'.
351 urlSerie :: Serie -> Maybe URL
352 urlSerie Serie{id=id_, name} =
354 "RFC" | TL.all Char.isDigit id_ ->
355 Just $ URL $ "https://tools.ietf.org/html/rfc"<>id_
356 "DOI" -> Just $ URL $ "https://dx.doi.org/"<>id_
363 type Words = [WordOrSpace]
365 -- *** Type 'WordOrSpace'
369 deriving (Eq,Ord,Show)
372 type Aliases = [Words]
375 type Terms = [Aliases]