import Data.Semigroup (Semigroup(..))
import Data.Sequence (Seq)
import Data.Text (Text)
-import Data.TreeSeq.Strict (Tree, Trees)
+import Data.TreeSeq.Strict (Tree(..), Trees)
import Text.Show (Show)
import Language.XML
-- * Type 'Title'
newtype Title = Title { unTitle :: Para }
- deriving (Eq,Show,Default)
+ deriving (Eq,Show,Semigroup,Monoid,Default)
-- ** Type 'Entity'
data Entity
, tel :: Text
, fax :: Text
, url :: Maybe URL
+ , org :: Maybe Entity
} deriving (Eq,Show)
instance Default Entity where
def = Entity
, tel = def
, fax = def
, url = def
+ , org = def
}
instance Semigroup Entity where
_x <> y = y
entity = rule "entity" $
interleaved $
DTC.Entity
- <$?> (def, attribute "name" text)
+ <$?> (def, name)
<|?> (def, attribute "street" text)
<|?> (def, attribute "zipcode" text)
<|?> (def, attribute "city" text)
<|?> (def, attribute "tel" text)
<|?> (def, attribute "fax" text)
<|?> (def, Just <$> attribute "url" url)
+ <|?> (def, Just <$> attribute "org" entity)
serie = rule "serie" $
element "serie" $
interleaved $
DTC.Serie
- <$?> (def, attribute "name" text)
- <|?> (def, attribute "key" text)
+ <$?> (def, name)
+ <|?> (def, attribute "key" text)
link = rule "link" $
element "link" $
interleaved $
(\n h r ls -> DTC.Link n h r (Seq.fromList ls))
- <$?> (def, attribute "name" text)
+ <$?> (def, name)
<|?> (def, attribute "href" url)
<|?> (def, attribute "rel" text)
<|*> lines
import Text.Blaze.Html (Html)
import Text.Show (Show(..))
import qualified Control.Monad.Trans.State as S
+import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import qualified Data.Sequence as Seq
html5ify type_
html5ify $ DTC.posAncestors pos
html5ify $ Plain.L10n_Colon
- " "
H.td ! HA.class_ "figure-name" $$
html5ify title
H.div ! HA.class_ "figure-content" $$ do
instance Html5ify DTC.About where
html5ify DTC.About{..} =
html5CommasDot $ concat $
- [ (<$> List.take 1 titles) $ \(DTC.Title title) ->
- html5ify $ TreeN DTC.Q $
- case url of
- Nothing -> title
- Just u -> pure $ TreeN (DTC.Eref u) title
+ [ html5Titles titles
, html5Entity <$> authors
- , html5ify <$> maybeToList date
+ , html5ify <$> maybeToList date
, html5Entity <$> maybeToList editor
- , html5Serie <$> series
+ , html5Serie <$> series
]
where
+ html5Titles :: [DTC.Title] -> [Html5]
+ html5Titles ts | null ts = []
+ html5Titles ts = [html5Title $ fold $ List.intersperse (DTC.Title " — ") $ toList ts]
+ html5Title (DTC.Title title) =
+ html5ify $ TreeN DTC.Q $
+ case url of
+ Nothing -> title
+ Just u -> pure $ TreeN (DTC.Eref u) title
+ html5SerieHref href DTC.Serie{..} = do
+ sp <- liftStateMarkup $ S.gets state_plainify
+ html5ify $
+ TreeN DTC.Eref{href} $
+ Seq.fromList
+ [ Tree0 $ DTC.Plain $ name
+ , Tree0 $ DTC.Plain $ TL.toStrict $ Plain.text sp Plain.L10n_Colon
+ , Tree0 $ DTC.Plain key
+ ]
+ html5Serie s@DTC.Serie{name="RFC", key} | Text.all Char.isDigit key =
+ html5SerieHref (DTC.URL $ "https://tools.ietf.org/html/rfc"<>key) s
+ html5Serie s@DTC.Serie{name="DOI", key} =
+ html5SerieHref (DTC.URL $ "https://dx.doi.org/"<>key) s
html5Serie DTC.Serie{..} = do
- html5ify key
- html5ify Plain.L10n_Colon
html5ify name
- html5Entity DTC.Entity{url=mu, ..} =
+ html5ify Plain.L10n_Colon
+ html5ify key
+ html5Entity DTC.Entity{url=mu, ..} = do
html5ify @DTC.Lines $
- case () of
- _ | not (Text.null email) ->
- TreeN (DTC.Eref $ DTC.URL $ "mailto:"<>email) $
- pure $ Tree0 $ DTC.Plain name
- _ | Just u <- mu ->
- TreeN (DTC.Eref u) $
- pure $ Tree0 $ DTC.Plain name
- _ -> Tree0 $ DTC.Plain name
+ case () of
+ _ | not (Text.null email) ->
+ TreeN (DTC.Eref $ DTC.URL $ "mailto:"<>email) $
+ pure $ Tree0 $ DTC.Plain name
+ _ | Just u <- mu ->
+ TreeN (DTC.Eref u) $
+ pure $ Tree0 $ DTC.Plain name
+ _ -> Tree0 $ DTC.Plain name
+ forM_ org $ \o -> do
+ " ("::Html5
+ html5Entity o
+ ")"::Html5
instance Html5ify DTC.Reference where
html5ify DTC.Reference{id=id_, ..} =
H.tr $$ do
case kn of
"about" -> xmlTitle : xmlTitle : List.repeat xmlPara
"reference" -> xmlTitle : xmlTitle : List.repeat xmlPara
+ "serie" -> List.repeat xmlName
"author" -> List.repeat xmlName
"editor" -> List.repeat xmlName
+ "org" -> List.repeat xmlName
_ -> []
} in
case () of
let (attrs',body) = partitionAttributesChildren ts in
TreeN (cell "reference") $
xmlAttrs (setXmlAttr (Cell ep ep ("id", ident)) (attrs<>attrs')) <>
- xmlTCTs inh' body
+ xmlTCTs inh'{inh_tree0 = xmlTitle : xmlTitle : List.repeat xmlPara} body
KeyDotSlash p ->
TreeN (cell "include") $
xmlAttrs [cell ("href", Text.pack $ FP.replaceExtension p "dtc")] <>