module Language.Drasil.JSON.Print(genJSON) where
import Prelude hiding (print, (<>))
import Text.PrettyPrint hiding (Str)
import Numeric (showEFloat)
import qualified Language.Drasil as L
import Language.Drasil.Format (DocType(Jupyter))
import Language.Drasil.Printing.Import (makeDocument)
import Language.Drasil.Printing.AST (Spec, ItemType(Flat, Nested),
ListType(Ordered, Unordered, Definitions, Desc, Simple), Expr,
Ops(..), Expr(..), Spec(Quote, EmptyS, Ref, HARDNL, Sp, S, E, (:+:)),
Fonts(Bold), OverSymb(Hat), Label, LinkType(Internal, Cite2, External))
import Language.Drasil.Printing.Citation (BibRef)
import Language.Drasil.Printing.LayoutObj (Document(Document), LayoutObj(..))
import Language.Drasil.Printing.Helpers (sqbrac, unders, hat)
import Language.Drasil.Printing.PrintingInformation (PrintingInformation)
import qualified Language.Drasil.TeX.Print as TeX (spec, pExpr)
import Language.Drasil.TeX.Monad (runPrint, MathContext(Math), D, toMath, PrintLaTeX(PL))
import Language.Drasil.HTML.Monad (unPH)
import Language.Drasil.HTML.Helpers (th, bold, reflinkInfo)
import Language.Drasil.HTML.Print(renderCite, OpenClose(Open, Close), fence)
import Language.Drasil.JSON.Helpers (makeMetadata, h, stripnewLine, nbformat, codeformat,
tr, td, image, li, pa, ba, table, refwrap, refID, reflink, reflinkURI, mkDiv,
markdownB, markdownB', markdownE, markdownE', markdownCell, codeCell)
genJSON :: PrintingInformation -> DocType -> L.Document -> Doc
genJSON :: PrintingInformation -> DocType -> Document -> Doc
genJSON PrintingInformation
sm DocType
Jupyter Document
doc = Document -> Doc
build (PrintingInformation -> Document -> Document
makeDocument PrintingInformation
sm Document
doc)
genJSON PrintingInformation
sm DocType
_ Document
doc = Document -> Doc
build' (PrintingInformation -> Document -> Document
makeDocument PrintingInformation
sm Document
doc)
build :: Document -> Doc
build :: Document -> Doc
build (Document Title
t Title
a [LayoutObj]
c) =
Doc
markdownB Doc -> Doc -> Doc
$$
Doc -> Doc
nbformat (String -> Doc
text String
"# " Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
t) Doc -> Doc -> Doc
$$
Doc -> Doc
nbformat (String -> Doc
text String
"## " Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
a) Doc -> Doc -> Doc
$$
Doc
markdownE Doc -> Doc -> Doc
$$
[LayoutObj] -> Doc
print' [LayoutObj]
c Doc -> Doc -> Doc
$$
Doc
markdownB' Doc -> Doc -> Doc
$$
Doc
markdownE' Doc -> Doc -> Doc
$$
Doc
makeMetadata Doc -> Doc -> Doc
$$
String -> Doc
text String
"}"
build' :: Document -> Doc
build' :: Document -> Doc
build' (Document Title
t Title
a [LayoutObj]
c) =
Doc
markdownB Doc -> Doc -> Doc
$$
Doc -> Doc
nbformat (String -> Doc
text String
"# " Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
t) Doc -> Doc -> Doc
$$
Doc -> Doc
nbformat (String -> Doc
text String
"## " Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
a) Doc -> Doc -> Doc
$$
Doc
markdownE Doc -> Doc -> Doc
$$
Doc
markdownB' Doc -> Doc -> Doc
$$
[LayoutObj] -> Doc
print [LayoutObj]
c Doc -> Doc -> Doc
$$
Doc
markdownE' Doc -> Doc -> Doc
$$
Doc
makeMetadata Doc -> Doc -> Doc
$$
String -> Doc
text String
"}"
printMath :: D -> Doc
printMath :: D -> Doc
printMath = (forall a. PrintLaTeX a -> MathContext -> a
`runPrint` MathContext
Math)
printLO :: LayoutObj -> Doc
printLO :: LayoutObj -> Doc
printLO (Header Int
n Title
contents Title
l) = Doc -> Doc
nbformat Doc
empty Doc -> Doc -> Doc
$$ Doc -> Doc
nbformat (Int -> Doc
h (Int
n forall a. Num a => a -> a -> a
+ Int
1) Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
contents) Doc -> Doc -> Doc
$$ Doc -> Doc
refID (Title -> Doc
pSpec Title
l)
printLO (Cell [LayoutObj]
layoutObs) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map LayoutObj -> Doc
printLO [LayoutObj]
layoutObs)
printLO (HDiv Tags
_ [LayoutObj]
layoutObs Title
_) = [Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map LayoutObj -> Doc
printLO [LayoutObj]
layoutObs)
printLO (Paragraph Title
contents) = Doc -> Doc
nbformat Doc
empty Doc -> Doc -> Doc
$$ Doc -> Doc
nbformat (String -> Doc
stripnewLine (forall a. Show a => a -> String
show(Title -> Doc
pSpec Title
contents)))
printLO (EqnBlock Title
contents) = Doc -> Doc
nbformat Doc
mathEqn
where
toMathHelper :: PrintLaTeX a -> PrintLaTeX a
toMathHelper (PL MathContext -> a
g) = forall a. (MathContext -> a) -> PrintLaTeX a
PL (\MathContext
_ -> MathContext -> a
g MathContext
Math)
mjDelimDisp :: a -> Doc
mjDelimDisp a
d = String -> Doc
text String
"$$" Doc -> Doc -> Doc
<> String -> Doc
stripnewLine (forall a. Show a => a -> String
show a
d) Doc -> Doc -> Doc
<> String -> Doc
text String
"$$"
mathEqn :: Doc
mathEqn = forall {a}. Show a => a -> Doc
mjDelimDisp forall a b. (a -> b) -> a -> b
$ D -> Doc
printMath forall a b. (a -> b) -> a -> b
$ forall {a}. PrintLaTeX a -> PrintLaTeX a
toMathHelper forall a b. (a -> b) -> a -> b
$ Title -> D
TeX.spec Title
contents
printLO (Table Tags
_ [[Title]]
rows Title
r Bool
_ Title
_) = Doc -> Doc
nbformat Doc
empty Doc -> Doc -> Doc
$$ [[Title]] -> Doc -> Doc
makeTable [[Title]]
rows (Title -> Doc
pSpec Title
r)
printLO (Definition DType
dt [(String, [LayoutObj])]
ssPs Title
l) = Doc -> Doc
nbformat (String -> Doc
text String
"<br>") Doc -> Doc -> Doc
$$ DType -> [(String, [LayoutObj])] -> Doc -> Doc
makeDefn DType
dt [(String, [LayoutObj])]
ssPs (Title -> Doc
pSpec Title
l)
printLO (List ListType
t) = Doc -> Doc
nbformat Doc
empty Doc -> Doc -> Doc
$$ ListType -> Bool -> Doc
makeList ListType
t Bool
False
printLO (Figure Title
r Title
c String
f MaxWidthPercent
wp) = Doc -> Doc -> Doc -> MaxWidthPercent -> Doc
makeFigure (Title -> Doc
pSpec Title
r) (Title -> Doc
pSpec Title
c) (String -> Doc
text String
f) MaxWidthPercent
wp
printLO (Bib BibRef
bib) = BibRef -> Doc
makeBib BibRef
bib
printLO Graph{} = Doc
empty
printLO CodeBlock {} = Doc
empty
printLO' :: LayoutObj -> Doc
printLO' :: LayoutObj -> Doc
printLO' (HDiv [String
"equation"] [LayoutObj]
layoutObs Title
_) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map LayoutObj -> Doc
printLO' [LayoutObj]
layoutObs)
printLO' (Header Int
n Title
contents Title
l) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ Doc -> Doc
nbformat (Int -> Doc
h (Int
n forall a. Num a => a -> a -> a
+ Int
1) Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
contents) Doc -> Doc -> Doc
$$ Doc -> Doc
refID (Title -> Doc
pSpec Title
l)
printLO' (Cell [LayoutObj]
layoutObs) = [Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map LayoutObj -> Doc
printLO' [LayoutObj]
layoutObs)
printLO' HDiv {} = Doc
empty
printLO' (Paragraph Title
contents) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ Doc -> Doc
nbformat (String -> Doc
stripnewLine (forall a. Show a => a -> String
show(Title -> Doc
pSpec Title
contents)))
printLO' (EqnBlock Title
contents) = Doc -> Doc
nbformat Doc
mathEqn
where
toMathHelper :: PrintLaTeX a -> PrintLaTeX a
toMathHelper (PL MathContext -> a
g) = forall a. (MathContext -> a) -> PrintLaTeX a
PL (\MathContext
_ -> MathContext -> a
g MathContext
Math)
mjDelimDisp :: a -> Doc
mjDelimDisp a
d = String -> Doc
text String
"$$" Doc -> Doc -> Doc
<> String -> Doc
stripnewLine (forall a. Show a => a -> String
show a
d) Doc -> Doc -> Doc
<> String -> Doc
text String
"$$"
mathEqn :: Doc
mathEqn = forall {a}. Show a => a -> Doc
mjDelimDisp forall a b. (a -> b) -> a -> b
$ D -> Doc
printMath forall a b. (a -> b) -> a -> b
$ forall {a}. PrintLaTeX a -> PrintLaTeX a
toMathHelper forall a b. (a -> b) -> a -> b
$ Title -> D
TeX.spec Title
contents
printLO' (Table Tags
_ [[Title]]
rows Title
r Bool
_ Title
_) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ [[Title]] -> Doc -> Doc
makeTable [[Title]]
rows (Title -> Doc
pSpec Title
r)
printLO' Definition {} = Doc
empty
printLO' (List ListType
t) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ ListType -> Bool -> Doc
makeList ListType
t Bool
False
printLO' (Figure Title
r Title
c String
f MaxWidthPercent
wp) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc -> MaxWidthPercent -> Doc
makeFigure (Title -> Doc
pSpec Title
r) (Title -> Doc
pSpec Title
c) (String -> Doc
text String
f) MaxWidthPercent
wp
printLO' (Bib BibRef
bib) = Doc -> Doc
markdownCell forall a b. (a -> b) -> a -> b
$ BibRef -> Doc
makeBib BibRef
bib
printLO' Graph{} = Doc
empty
printLO' (CodeBlock Title
contents) = Doc -> Doc
codeCell forall a b. (a -> b) -> a -> b
$ Doc -> Doc
codeformat forall a b. (a -> b) -> a -> b
$ Title -> Doc
cSpec Title
contents
print :: [LayoutObj] -> Doc
print :: [LayoutObj] -> Doc
print = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Doc -> Doc -> Doc
($$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayoutObj -> Doc
printLO) Doc
empty
print' :: [LayoutObj] -> Doc
print' :: [LayoutObj] -> Doc
print' = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Doc -> Doc -> Doc
($$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayoutObj -> Doc
printLO') Doc
empty
pSpec :: Spec -> Doc
pSpec :: Title -> Doc
pSpec (E Expr
e) = String -> Doc
text String
"$" Doc -> Doc -> Doc
<> Expr -> Doc
pExpr Expr
e Doc -> Doc -> Doc
<> String -> Doc
text String
"$"
pSpec (Title
a :+: Title
b) = Title -> Doc
pSpec Title
a Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
b
pSpec (S String
s) = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasCallStack => String -> a
error (String -> Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Char -> String
escapeChars) forall a b. (a -> b) -> a -> b
$ String -> String -> Either String String
L.checkValidStr String
s String
invalid
where
invalid :: String
invalid = [Char
'<', Char
'>']
escapeChars :: Char -> String
escapeChars Char
'&' = String
"\\&"
escapeChars Char
c = [Char
c]
pSpec (Sp Special
s) = String -> Doc
text forall a b. (a -> b) -> a -> b
$ PrintHTML -> String
unPH forall a b. (a -> b) -> a -> b
$ forall r. RenderSpecial r => Special -> r
L.special Special
s
pSpec Title
HARDNL = Doc
empty
pSpec (Ref LinkType
Internal String
r Title
a) = String -> Doc -> Doc
reflink String
r forall a b. (a -> b) -> a -> b
$ Title -> Doc
pSpec Title
a
pSpec (Ref (Cite2 Title
n) String
r Title
a) = String -> Doc -> Doc -> Doc
reflinkInfo String
r (Title -> Doc
pSpec Title
a) (Title -> Doc
pSpec Title
n)
pSpec (Ref LinkType
External String
r Title
a) = String -> Doc -> Doc
reflinkURI String
r forall a b. (a -> b) -> a -> b
$ Title -> Doc
pSpec Title
a
pSpec Title
EmptyS = String -> Doc
text String
""
pSpec (Quote Title
q) = Doc -> Doc
doubleQuotes forall a b. (a -> b) -> a -> b
$ Title -> Doc
pSpec Title
q
cSpec :: Spec -> Doc
cSpec :: Title -> Doc
cSpec (E Expr
e) = Expr -> Doc
pExpr Expr
e
cSpec Title
_ = Doc
empty
pExpr :: Expr -> Doc
pExpr :: Expr -> Doc
pExpr (Dbl Double
d) = String -> Doc
text forall a b. (a -> b) -> a -> b
$ forall a. RealFloat a => Maybe Int -> a -> ShowS
showEFloat forall a. Maybe a
Nothing Double
d String
""
pExpr (Int Integer
i) = String -> Doc
text forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Integer
i
pExpr (Str String
s) = Doc -> Doc
doubleQuotes forall a b. (a -> b) -> a -> b
$ String -> Doc
text String
s
pExpr (Div Expr
n Expr
d) = String -> Doc -> Doc -> Doc
mkDiv String
"frac" (Expr -> Doc
pExpr Expr
n) (Expr -> Doc
pExpr Expr
d)
pExpr (Row [Expr]
l) = [Doc] -> Doc
hcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Expr -> Doc
pExpr [Expr]
l
pExpr (Ident String
s) = String -> Doc
text String
s
pExpr (Label String
s) = String -> Doc
text String
s
pExpr (Spec Special
s) = String -> Doc
text forall a b. (a -> b) -> a -> b
$ PrintHTML -> String
unPH forall a b. (a -> b) -> a -> b
$ forall r. RenderSpecial r => Special -> r
L.special Special
s
pExpr (Sub Expr
e) = Doc
unders Doc -> Doc -> Doc
<> Expr -> Doc
pExpr Expr
e
pExpr (Sup Expr
e) = Doc
hat Doc -> Doc -> Doc
<> Expr -> Doc
pExpr Expr
e
pExpr (Over OverSymb
Hat Expr
s) = Expr -> Doc
pExpr Expr
s Doc -> Doc -> Doc
<> String -> Doc
text String
"̂"
pExpr (MO Ops
o) = String -> Doc
text forall a b. (a -> b) -> a -> b
$ Ops -> String
pOps Ops
o
pExpr (Fenced Fence
l Fence
r Expr
e) = String -> Doc
text (OpenClose -> Fence -> String
fence OpenClose
Open Fence
l) Doc -> Doc -> Doc
<> Expr -> Doc
pExpr Expr
e Doc -> Doc -> Doc
<> String -> Doc
text (OpenClose -> Fence -> String
fence OpenClose
Close Fence
r)
pExpr (Font Fonts
Bold Expr
e) = Expr -> Doc
pExpr Expr
e
pExpr Expr
e = D -> Doc
printMath forall a b. (a -> b) -> a -> b
$ D -> D
toMath forall a b. (a -> b) -> a -> b
$ Expr -> D
TeX.pExpr Expr
e
pOps :: Ops -> String
pOps :: Ops -> String
pOps Ops
IsIn = String
" ∈ "
pOps Ops
Integer = String
"ℤ"
pOps Ops
Rational = String
"ℚ"
pOps Ops
Real = String
"ℝ"
pOps Ops
Natural = String
"ℕ"
pOps Ops
Boolean = String
"𝔹"
pOps Ops
Comma = String
","
pOps Ops
Prime = String
"′"
pOps Ops
Log = String
"log"
pOps Ops
Ln = String
"ln"
pOps Ops
Sin = String
"sin"
pOps Ops
Cos = String
"cos"
pOps Ops
Tan = String
"tan"
pOps Ops
Sec = String
"sec"
pOps Ops
Csc = String
"csc"
pOps Ops
Cot = String
"cot"
pOps Ops
Arcsin = String
"arcsin"
pOps Ops
Arccos = String
"arccos"
pOps Ops
Arctan = String
"arctan"
pOps Ops
Not = String
"¬"
pOps Ops
Dim = String
"dim"
pOps Ops
Exp = String
"e"
pOps Ops
Neg = String
"-"
pOps Ops
Cross = String
"⨯"
pOps Ops
VAdd = String
" + "
pOps Ops
VSub = String
" - "
pOps Ops
Dot = String
"⋅"
pOps Ops
Scale = String
""
pOps Ops
Eq = String
" = "
pOps Ops
NEq = String
"≠"
pOps Ops
Lt = String
" < "
pOps Ops
Gt = String
" > "
pOps Ops
LEq = String
" ≤ "
pOps Ops
GEq = String
" ≥ "
pOps Ops
Impl = String
" ⇒ "
pOps Ops
Iff = String
" ⇔ "
pOps Ops
Subt = String
" - "
pOps Ops
And = String
" ∧ "
pOps Ops
Or = String
" ∨ "
pOps Ops
Add = String
" + "
pOps Ops
Mul = String
""
pOps Ops
Summ = String
"&sum"
pOps Ops
Inte = String
"∫"
pOps Ops
Prod = String
"∏"
pOps Ops
Point = String
"."
pOps Ops
Perc = String
"%"
pOps Ops
LArrow = String
" ← "
pOps Ops
RArrow = String
" → "
pOps Ops
ForAll = String
" ForAll "
pOps Ops
Partial = String
"∂"
makeTable :: [[Spec]] -> Doc -> Doc
makeTable :: [[Title]] -> Doc -> Doc
makeTable [] Doc
_ = forall a. HasCallStack => String -> a
error String
"No table to print"
makeTable ([Title]
l:[[Title]]
lls) Doc
r = Doc -> Doc
refID Doc
r Doc -> Doc -> Doc
$$ Doc -> Doc
nbformat Doc
empty Doc -> Doc -> Doc
$$ ([Title] -> Doc
makeHeaderCols [Title]
l Doc -> Doc -> Doc
$$ [[Title]] -> Doc
makeRows [[Title]]
lls) Doc -> Doc -> Doc
$$ Doc -> Doc
nbformat Doc
empty
makeRows :: [[Spec]] -> Doc
makeRows :: [[Title]] -> Doc
makeRows = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Doc -> Doc -> Doc
($$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Title] -> Doc
makeColumns) Doc
empty
makeHeaderCols, makeColumns :: [Spec] -> Doc
[Title]
l = Doc -> Doc
nbformat (String -> Doc
text String
header) Doc -> Doc -> Doc
$$ Doc -> Doc
nbformat (String -> Doc
text forall a b. (a -> b) -> a -> b
$ String
genMDtable forall a. [a] -> [a] -> [a]
++ String
"|")
where header :: String
header = forall a. Show a => a -> String
show(String -> Doc
text String
"|" Doc -> Doc -> Doc
<> [Doc] -> Doc
hcat(Doc -> [Doc] -> [Doc]
punctuate (String -> Doc
text String
"|") (forall a b. (a -> b) -> [a] -> [b]
map Title -> Doc
pSpec [Title]
l)) Doc -> Doc -> Doc
<> String -> Doc
text String
"|")
c :: Int
c = Char -> String -> Int
count Char
'|' String
header
genMDtable :: String
genMDtable = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (forall a. Int -> a -> [a]
replicate (Int
cforall a. Num a => a -> a -> a
-Int
1) String
"|:--- ")
makeColumns :: [Title] -> Doc
makeColumns [Title]
ls = Doc -> Doc
nbformat (String -> Doc
text String
"|" Doc -> Doc -> Doc
<> [Doc] -> Doc
hcat(Doc -> [Doc] -> [Doc]
punctuate (String -> Doc
text String
"|") (forall a b. (a -> b) -> [a] -> [b]
map Title -> Doc
pSpec [Title]
ls)) Doc -> Doc -> Doc
<> String -> Doc
text String
"|")
count :: Char -> String -> Int
count :: Char -> String -> Int
count Char
_ [] = Int
0
count Char
c (Char
x:String
xs)
| Char
c forall a. Eq a => a -> a -> Bool
== Char
x = Int
1 forall a. Num a => a -> a -> a
+ Char -> String -> Int
count Char
c String
xs
| Bool
otherwise = Char -> String -> Int
count Char
c String
xs
makeDefn :: L.DType -> [(String,[LayoutObj])] -> Doc -> Doc
makeDefn :: DType -> [(String, [LayoutObj])] -> Doc -> Doc
makeDefn DType
_ [] Doc
_ = forall a. HasCallStack => String -> a
error String
"L.Empty definition"
makeDefn DType
dt [(String, [LayoutObj])]
ps Doc
l = Doc -> Doc
refID Doc
l Doc -> Doc -> Doc
$$ Tags -> Doc -> Doc
table [DType -> String
dtag DType
dt]
(Doc -> Doc
tr (Doc -> Doc
nbformat (Doc -> Doc
th (String -> Doc
text String
"Refname")) Doc -> Doc -> Doc
$$ Doc -> Doc
td (Doc -> Doc
nbformat(Doc -> Doc
bold Doc
l))) Doc -> Doc -> Doc
$$ [(String, [LayoutObj])] -> Doc
makeDRows [(String, [LayoutObj])]
ps)
where dtag :: DType -> String
dtag DType
L.General = String
"gdefn"
dtag DType
L.Instance = String
"idefn"
dtag DType
L.Theory = String
"tdefn"
dtag DType
L.Data = String
"ddefn"
makeDRows :: [(String,[LayoutObj])] -> Doc
makeDRows :: [(String, [LayoutObj])] -> Doc
makeDRows [] = forall a. HasCallStack => String -> a
error String
"No fields to create defn table"
makeDRows [(String
f,[LayoutObj]
d)] = Doc -> Doc
tr (Doc -> Doc
nbformat (Doc -> Doc
th (String -> Doc
text String
f)) Doc -> Doc -> Doc
$$ Doc -> Doc
td ([Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map LayoutObj -> Doc
printLO [LayoutObj]
d))
makeDRows ((String
f,[LayoutObj]
d):[(String, [LayoutObj])]
ps) = Doc -> Doc
tr (Doc -> Doc
nbformat (Doc -> Doc
th (String -> Doc
text String
f)) Doc -> Doc -> Doc
$$ Doc -> Doc
td ([Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map LayoutObj -> Doc
printLO [LayoutObj]
d)) Doc -> Doc -> Doc
$$ [(String, [LayoutObj])] -> Doc
makeDRows [(String, [LayoutObj])]
ps
makeList :: ListType -> Bool -> Doc
makeList :: ListType -> Bool -> Doc
makeList (Simple [(Title, ItemType, Maybe Title)]
items) Bool
_ = [Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map (\(Title
b,ItemType
e,Maybe Title
l) -> Maybe Title -> Doc -> Doc
mlref Maybe Title
l forall a b. (a -> b) -> a -> b
$ Doc -> Doc
nbformat (Title -> Doc
pSpec Title
b Doc -> Doc -> Doc
<> String -> Doc
text String
": " Doc -> Doc -> Doc
<> ItemType -> Doc
sItem ItemType
e) Doc -> Doc -> Doc
$$ Doc -> Doc
nbformat Doc
empty) [(Title, ItemType, Maybe Title)]
items
makeList (Desc [(Title, ItemType, Maybe Title)]
items) Bool
bl = [Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map (\(Title
b,ItemType
e,Maybe Title
l) -> Doc -> Doc
pa forall a b. (a -> b) -> a -> b
$ Maybe Title -> Doc -> Doc
mlref Maybe Title
l forall a b. (a -> b) -> a -> b
$ Doc -> Doc
ba forall a b. (a -> b) -> a -> b
$ Title -> Doc
pSpec Title
b Doc -> Doc -> Doc
<> String -> Doc
text String
": " Doc -> Doc -> Doc
<> ItemType -> Bool -> Doc
pItem ItemType
e Bool
bl) [(Title, ItemType, Maybe Title)]
items
makeList (Ordered [(ItemType, Maybe Title)]
items) Bool
bl = [Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(ItemType
i,Maybe Title
l) -> Maybe Title -> Doc -> Doc
mlref Maybe Title
l forall a b. (a -> b) -> a -> b
$ ItemType -> Bool -> Doc
pItem ItemType
i Bool
bl) [(ItemType, Maybe Title)]
items
makeList (Unordered [(ItemType, Maybe Title)]
items) Bool
bl = [Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(ItemType
i,Maybe Title
l) -> Maybe Title -> Doc -> Doc
mlref Maybe Title
l forall a b. (a -> b) -> a -> b
$ ItemType -> Bool -> Doc
pItem ItemType
i Bool
bl) [(ItemType, Maybe Title)]
items
makeList (Definitions [(Title, ItemType, Maybe Title)]
items) Bool
_ = [Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(Title
b,ItemType
e,Maybe Title
l) -> Doc -> Doc
nbformat forall a b. (a -> b) -> a -> b
$ Doc -> Doc
li forall a b. (a -> b) -> a -> b
$ Maybe Title -> Doc -> Doc
mlref Maybe Title
l forall a b. (a -> b) -> a -> b
$ Title -> Doc
pSpec Title
b Doc -> Doc -> Doc
<> String -> Doc
text String
" is the" Doc -> Doc -> Doc
<+> ItemType -> Doc
sItem ItemType
e) [(Title, ItemType, Maybe Title)]
items
mlref :: Maybe Label -> Doc -> Doc
mlref :: Maybe Title -> Doc -> Doc
mlref = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a -> a
id forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc
refwrap forall b c a. (b -> c) -> (a -> b) -> a -> c
. Title -> Doc
pSpec
pItem :: ItemType -> Bool -> Doc
pItem :: ItemType -> Bool -> Doc
pItem (Flat Title
s) Bool
b = Doc -> Doc
nbformat forall a b. (a -> b) -> a -> b
$ (if Bool
b then String -> Doc
text String
" - " else String -> Doc
text String
"- ") Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
s
pItem (Nested Title
s ListType
l) Bool
_ = [Doc] -> Doc
vcat [Doc -> Doc
nbformat forall a b. (a -> b) -> a -> b
$ String -> Doc
text String
"- " Doc -> Doc -> Doc
<> Title -> Doc
pSpec Title
s, ListType -> Bool -> Doc
makeList ListType
l Bool
True]
sItem :: ItemType -> Doc
sItem :: ItemType -> Doc
sItem (Flat Title
s) = Title -> Doc
pSpec Title
s
sItem (Nested Title
s ListType
l) = [Doc] -> Doc
vcat [Title -> Doc
pSpec Title
s, ListType -> Bool -> Doc
makeList ListType
l Bool
False]
makeFigure :: Doc -> Doc -> Doc -> L.MaxWidthPercent -> Doc
makeFigure :: Doc -> Doc -> Doc -> MaxWidthPercent -> Doc
makeFigure Doc
r Doc
c Doc
f MaxWidthPercent
wp = Doc -> Doc
refID Doc
r Doc -> Doc -> Doc
$$ Doc -> Doc -> MaxWidthPercent -> Doc
image Doc
f Doc
c MaxWidthPercent
wp
makeRefList :: Doc -> Doc -> Doc -> Doc
makeRefList :: Doc -> Doc -> Doc -> Doc
makeRefList Doc
a Doc
l Doc
i = Doc -> Doc
refID Doc
l Doc -> Doc -> Doc
$$ Doc -> Doc
nbformat (Doc
i Doc -> Doc -> Doc
<> String -> Doc
text String
": " Doc -> Doc -> Doc
<> Doc
a)
makeBib :: BibRef -> Doc
makeBib :: BibRef -> Doc
makeBib = [Doc] -> Doc
vcat forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall a b c. ((a, b) -> c) -> a -> b -> c
curry (\(Doc
x,(Doc
y,Doc
z)) -> Doc -> Doc -> Doc -> Doc
makeRefList Doc
z Doc
y Doc
x))
[String -> Doc
text forall a b. (a -> b) -> a -> b
$ ShowS
sqbrac forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Int
x | Int
x <- [Int
1..] :: [Int]] forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Citation -> (Doc, Doc)
renderCite