Fix Reference.
authorJulien Moutinho <julm+hdoc@autogeree.net>
Mon, 25 Dec 2017 08:05:37 +0000 (09:05 +0100)
committerJulien Moutinho <julm+hdoc@autogeree.net>
Mon, 25 Dec 2017 08:05:37 +0000 (09:05 +0100)
Language/DTC/Document.hs
Language/DTC/Sym.hs
Language/DTC/Write/HTML5.hs
Language/DTC/Write/Plain.hs
Language/TCT/Write/XML.hs

index bdee41a9704eb9c525d894534d6e1678a8a5efd2..2a479167fdcd5d3c6419b8632ea8372c0a7a5832 100644 (file)
@@ -19,7 +19,7 @@ import Data.Ord (Ord(..))
 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
@@ -237,7 +237,7 @@ data LineValue
 
 -- * Type 'Title'
 newtype Title = Title { unTitle :: Para }
- deriving (Eq,Show,Default)
+ deriving (Eq,Show,Semigroup,Monoid,Default)
 
 -- ** Type 'Entity'
 data Entity
@@ -252,6 +252,7 @@ data Entity
  ,   tel     :: Text
  ,   fax     :: Text
  ,   url     :: Maybe URL
+ ,   org     :: Maybe Entity
  } deriving (Eq,Show)
 instance Default Entity where
        def = Entity
@@ -265,6 +266,7 @@ instance Default Entity where
         , tel     = def
         , fax     = def
         , url     = def
+        , org     = def
         }
 instance Semigroup Entity where
        _x <> y = y
index 51d185d51d04475e4de0a781371020d6d9e04ed2..fae7c86c509ff6dca8cd71d37b75a9420ad5d243 100644 (file)
@@ -236,7 +236,7 @@ class RNC.Sym_RNC repr => Sym_DTC repr where
        entity = rule "entity" $
                interleaved $
                DTC.Entity
-                <$?> (def, attribute "name"    text)
+                <$?> (def, name)
                 <|?> (def, attribute "street"  text)
                 <|?> (def, attribute "zipcode" text)
                 <|?> (def, attribute "city"    text)
@@ -246,17 +246,18 @@ class RNC.Sym_RNC repr => Sym_DTC repr where
                 <|?> (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
index 2ee0a77416ae8304c3cb6b9daa124ac151fc6e2a..b43b36248a2f19a25c26119c39514ec9e7266182 100644 (file)
@@ -41,6 +41,7 @@ import Text.Blaze ((!))
 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
@@ -276,7 +277,6 @@ html5BodyValue z = \case
                                                                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
@@ -507,31 +507,52 @@ instance Html5ify DTC.Date where
 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
index 3b516f5f7359f8ae1a51ac9960d8eef15667eab2..0561da59250cb43952ff443c5a8e0a12f3520e4e 100644 (file)
@@ -147,7 +147,7 @@ instance Plainify L10n where
 instance LocalizeIn FR Plain L10n where
        localizeIn _ = \case
         L10n_Table_of_Contents -> "Sommaire"
-        L10n_Colon -> " :"
+        L10n_Colon -> " : "
         L10n_QuoteOpen{..} ->
                case DTC.unNat depth `mod` 3 of
                 0 -> "« "
@@ -185,7 +185,7 @@ instance LocalizeIn FR Plain L10n where
 instance LocalizeIn EN Plain L10n where
        localizeIn _ = \case
         L10n_Table_of_Contents -> "Summary"
-        L10n_Colon -> ":"
+        L10n_Colon -> ": "
         L10n_QuoteOpen{..} ->
                case DTC.unNat depth `mod` 3 of
                 0 -> "“"
index 69c7d6584f76ac3b07c876a333180d09e42d7359..f117151a72d36c4dd04b121015ac127968d2dab6 100644 (file)
@@ -171,8 +171,10 @@ xmlTCT inh tr =
                        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
@@ -230,7 +232,7 @@ xmlKey inh (Cell bp ep key) attrs ts =
                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")] <>