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 | BlockToC { pos :: Pos
116 , attrs :: CommonAttrs
119 | BlockToF { pos :: Pos
120 , attrs :: CommonAttrs
123 | BlockFigure { pos :: Pos
124 , attrs :: CommonAttrs
126 , mayTitle :: Maybe Title
129 | BlockIndex { pos :: Pos
130 , attrs :: CommonAttrs
133 | BlockReferences { pos :: Pos
134 , attrs :: CommonAttrs
135 , refs :: [Reference]
141 = ParaItem { item :: ParaItem }
142 | ParaItems { pos :: Pos
143 , attrs :: CommonAttrs
144 , items :: [ParaItem]
148 -- ** Type 'ParaItem'
151 | ParaComment TL.Text
154 | ParaQuote { type_ :: TL.Text
157 | ParaArtwork { type_ :: TL.Text
162 -- *** Type 'ListItem'
164 = ListItem { name :: TL.Text
170 type Plain = Trees PlainNode
172 -- ** Type 'PlainNode'
176 | PlainCode -- ^ Code (monospaced)
177 | PlainDel -- ^ Deleted (crossed-over)
179 | PlainGroup -- ^ Group subTrees (neutral)
181 | PlainSC -- ^ Small Caps
182 | PlainSub -- ^ Subscript
183 | PlainSup -- ^ Superscript
184 | PlainU -- ^ Underlined
185 | PlainEref { href :: URL } -- ^ External reference
186 | PlainIref { anchor :: Maybe Anchor
188 } -- ^ Index reference
189 | PlainRef { to :: Ident }
191 | PlainRref { anchor :: Maybe Anchor
193 } -- ^ Reference reference
195 | PlainBR -- ^ Line break (\n)
197 | PlainNote { number :: Maybe Nat1
205 { posAncestors :: PosPath
206 , posAncestorsWithFigureNames :: PosPath
207 , posPrecedingsSiblings :: Map XmlName Rank
209 instance Ord Pos where
210 compare = compare `on` posAncestors
211 instance Default Pos where
212 def = Pos mempty mempty mempty
214 -- *** Type 'PosPath'
215 type PosPath = Seq (XmlName,Rank)
217 posParent :: PosPath -> Maybe PosPath
223 -- * Type 'CommonAttrs'
227 , classes :: [TL.Text]
229 instance Default CommonAttrs where
240 } deriving (Eq,Ord,Show)
243 newtype Title = Title { unTitle :: Plain }
244 deriving (Eq,Show,Semigroup,Monoid,Default)
259 , org :: Maybe Entity
261 instance Default Entity where
275 instance Semigroup Entity where
283 instance Default Include where
288 -- * Type 'Reference'
294 reference :: Ident -> Reference
300 instance Default Reference where
307 , month :: Maybe Nat1
310 instance Default Date where
313 , month = Just (Nat1 01)
314 , day = Just (Nat1 01)
316 instance Semigroup Date where
325 , type_ :: Maybe TL.Text
328 instance Default Link where
342 instance Default Alias where
353 instance Default Serie where
359 -- | Builtins 'URL' recognized from |Serie|'s 'name'.
360 urlSerie :: Serie -> Maybe URL
361 urlSerie Serie{id=id_, name} =
363 "RFC" | TL.all Char.isDigit id_ ->
364 Just $ URL $ "https://tools.ietf.org/html/rfc"<>id_
365 "DOI" -> Just $ URL $ "https://dx.doi.org/"<>id_
372 type Words = [WordOrSpace]
374 -- *** Type 'WordOrSpace'
378 deriving (Eq,Ord,Show)
381 type Aliases = [Words]
384 type Terms = [Aliases]