{-# Language TemplateHaskell #-}
module Language.Drasil.Document where
import Language.Drasil.ShortName (HasShortName(..), ShortName, shortname')
import Language.Drasil.Document.Core (UnlabelledContent(UnlblC),
LabelledContent(LblC), RawContent(Figure, Paragraph),
Contents(..), Lbl, Filepath, Author, Title, MaxWidthPercent )
import Language.Drasil.Label.Type (getAdd, prepend, LblType(..),
Referable(..), HasRefAddress(..) )
import Language.Drasil.Misc (repUnd)
import Language.Drasil.Reference (Reference(Reference))
import Language.Drasil.Sentence (Sentence(..))
import Language.Drasil.UID (UID, HasUID(..), (+++.), mkUid, nsUid)
import Control.Lens ((^.), makeLenses, view)
data SecCons = Sub Section
| Con Contents
data Partition = Sections
| Part
| Chapter
data Section = Section
{ Section -> Title
tle :: Title
, Section -> [SecCons]
cons :: [SecCons]
, Section -> Reference
_lab :: Reference
}
makeLenses ''Section
instance HasUID Section where uid :: Lens' Section UID
uid = Lens' Section Reference
lab forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. HasUID c => Lens' c UID
uid
instance Eq Section where Section
a == :: Section -> Section -> Bool
== Section
b = (Section
a forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid) forall a. Eq a => a -> a -> Bool
== (Section
b forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid)
instance HasShortName Section where shortname :: Section -> ShortName
shortname = forall s. HasShortName s => s -> ShortName
shortname forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Lens' Section Reference
lab
instance Referable Section where
refAdd :: Section -> String
refAdd = LblType -> String
getAdd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b. HasRefAddress b => b -> LblType
getRefAdd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Lens' Section Reference
lab
renderRef :: Section -> LblType
renderRef (Section Title
_ [SecCons]
_ Reference
lb) = IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Sec") (LblType -> String
getAdd forall a b. (a -> b) -> a -> b
$ forall b. HasRefAddress b => b -> LblType
getRefAdd Reference
lb)
instance HasRefAddress Section where getRefAdd :: Section -> LblType
getRefAdd (Section Title
_ [SecCons]
_ Reference
lb) = IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Sec") (LblType -> String
getAdd forall a b. (a -> b) -> a -> b
$ forall b. HasRefAddress b => b -> LblType
getRefAdd Reference
lb)
data Document = Document Title Author ShowTableOfContents [Section]
| Notebook Title Author [Section]
data ShowTableOfContents = ToC | NoToC
checkToC :: Document -> Document
checkToC :: Document -> Document
checkToC (Document Title
t Title
a ShowTableOfContents
toC [Section]
sc) =
case ShowTableOfContents
toC of
ShowTableOfContents
ToC -> Title -> Title -> ShowTableOfContents -> [Section] -> Document
Document Title
t Title
a ShowTableOfContents
toC forall a b. (a -> b) -> a -> b
$ forall a. Int -> [a] -> [a]
drop Int
1 [Section]
sc
ShowTableOfContents
_ -> Title -> Title -> ShowTableOfContents -> [Section] -> Document
Document Title
t Title
a ShowTableOfContents
toC [Section]
sc
checkToC (Notebook Title
t Title
a [Section]
sc) = Title -> Title -> [Section] -> Document
Notebook Title
t Title
a [Section]
sc
llcc :: Reference -> RawContent -> LabelledContent
llcc :: Reference -> RawContent -> LabelledContent
llcc = Reference -> RawContent -> LabelledContent
LblC
ulcc :: RawContent -> UnlabelledContent
ulcc :: RawContent -> UnlabelledContent
ulcc = RawContent -> UnlabelledContent
UnlblC
mkParagraph :: Sentence -> Contents
mkParagraph :: Title -> Contents
mkParagraph Title
x = UnlabelledContent -> Contents
UlC forall a b. (a -> b) -> a -> b
$ RawContent -> UnlabelledContent
ulcc forall a b. (a -> b) -> a -> b
$ Title -> RawContent
Paragraph Title
x
mkFig :: Reference -> RawContent -> Contents
mkFig :: Reference -> RawContent -> Contents
mkFig Reference
x RawContent
y = LabelledContent -> Contents
LlC forall a b. (a -> b) -> a -> b
$ Reference -> RawContent -> LabelledContent
llcc Reference
x RawContent
y
mkRawLC :: RawContent -> Reference -> LabelledContent
mkRawLC :: RawContent -> Reference -> LabelledContent
mkRawLC RawContent
x Reference
lb = Reference -> RawContent -> LabelledContent
llcc Reference
lb RawContent
x
section :: Sentence -> [Contents] -> [Section] -> Reference -> Section
section :: Title -> [Contents] -> [Section] -> Reference -> Section
section Title
title [Contents]
intro [Section]
secs = Title -> [SecCons] -> Reference -> Section
Section Title
title (forall a b. (a -> b) -> [a] -> [b]
map Contents -> SecCons
Con [Contents]
intro forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map Section -> SecCons
Sub [Section]
secs)
extractSection :: Document -> [Section]
(Document Title
_ Title
_ ShowTableOfContents
_ [Section]
sec) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [Section]
getSec [Section]
sec
extractSection (Notebook Title
_ Title
_ [Section]
sec) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [Section]
getSec [Section]
sec
getSec :: Section -> [Section]
getSec :: Section -> [Section]
getSec t :: Section
t@(Section Title
_ [SecCons]
sc Reference
_) = Section
t forall a. a -> [a] -> [a]
: forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap SecCons -> [Section]
getSecCons [SecCons]
sc
getSecCons :: SecCons -> [Section]
getSecCons :: SecCons -> [Section]
getSecCons (Sub Section
sec) = Section -> [Section]
getSec Section
sec
getSecCons (Con Contents
_) = []
fig :: Lbl -> Filepath -> RawContent
fig :: Title -> String -> RawContent
fig Title
l String
f = Title -> String -> MaxWidthPercent -> RawContent
Figure Title
l String
f MaxWidthPercent
100
figWithWidth :: Lbl -> Filepath -> MaxWidthPercent -> RawContent
figWithWidth :: Title -> String -> MaxWidthPercent -> RawContent
figWithWidth = Title -> String -> MaxWidthPercent -> RawContent
Figure
docNs :: UID -> UID
docNs :: UID -> UID
docNs = String -> UID -> UID
nsUid String
"doc"
docUid :: String -> UID
docUid :: String -> UID
docUid = UID -> UID
docNs forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> UID
mkUid
makeTabRef :: String -> Reference
makeTabRef :: String -> Reference
makeTabRef String
rs = UID -> LblType -> ShortName -> Reference
Reference (String -> UID
docUid String
rs) (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Tab") (String
"Table:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd String
rs)) (Title -> ShortName
shortname' (String -> Title
S String
rs))
makeFigRef :: String -> Reference
makeFigRef :: String -> Reference
makeFigRef String
rs = UID -> LblType -> ShortName -> Reference
Reference (String -> UID
docUid String
rs) (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Fig") (String
"Figure:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd String
rs)) (Title -> ShortName
shortname' (String -> Title
S String
rs))
makeSecRef :: String -> Sentence -> Reference
makeSecRef :: String -> Title -> Reference
makeSecRef String
r Title
s = UID -> LblType -> ShortName -> Reference
Reference (String -> UID
mkUid forall a b. (a -> b) -> a -> b
$ String
r forall a. [a] -> [a] -> [a]
++ String
"Label") (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Sec") (String
"Sec:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd String
r))
(Title -> ShortName
shortname' Title
s)
makeEqnRef :: String -> Reference
makeEqnRef :: String -> Reference
makeEqnRef String
rs = UID -> LblType -> ShortName -> Reference
Reference (String -> UID
docUid String
rs) (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Eqn") (String
"Equation:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd String
rs)) (Title -> ShortName
shortname' (String -> Title
S String
rs))
makeURI :: String -> String -> ShortName -> Reference
makeURI :: String -> String -> ShortName -> Reference
makeURI String
u String
r = UID -> LblType -> ShortName -> Reference
Reference (String -> UID
mkUid String
u) (String -> LblType
URI String
r)
makeTabRef' :: UID -> Reference
makeTabRef' :: UID -> Reference
makeTabRef' UID
rs = UID -> LblType -> ShortName -> Reference
Reference (UID -> UID
docNs UID
rs) (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Tab") (String
"Table:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd (forall a. Show a => a -> String
show UID
rs))) (Title -> ShortName
shortname' (String -> Title
S forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show UID
rs))
makeFigRef' :: UID -> Reference
makeFigRef' :: UID -> Reference
makeFigRef' UID
rs = UID -> LblType -> ShortName -> Reference
Reference (UID -> UID
docNs UID
rs) (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Fig") (String
"Figure:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd (forall a. Show a => a -> String
show UID
rs))) (Title -> ShortName
shortname' (String -> Title
S forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show UID
rs))
makeSecRef' :: UID -> Sentence -> Reference
makeSecRef' :: UID -> Title -> Reference
makeSecRef' UID
r Title
s = UID -> LblType -> ShortName -> Reference
Reference (UID
r UID -> String -> UID
+++. String
"Label") (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Sec") (String
"Sec:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd (forall a. Show a => a -> String
show UID
r)))
(Title -> ShortName
shortname' Title
s)
makeEqnRef' :: UID -> Reference
makeEqnRef' :: UID -> Reference
makeEqnRef' UID
rs = UID -> LblType -> ShortName -> Reference
Reference (UID -> UID
docNs UID
rs) (IRefProg -> String -> LblType
RP (String -> IRefProg
prepend String
"Eqn") (String
"Equation:" forall a. [a] -> [a] -> [a]
++ String -> String
repUnd (forall a. Show a => a -> String
show UID
rs))) (Title -> ShortName
shortname' (String -> Title
S forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show UID
rs))
makeURI' :: UID -> String -> ShortName -> Reference
makeURI' :: UID -> String -> ShortName -> Reference
makeURI' UID
u String
r = UID -> LblType -> ShortName -> Reference
Reference UID
u (String -> LblType
URI String
r)