Skip to content

Commit

Permalink
Merge pull request #3916 from JacquesCarette/figcaption
Browse files Browse the repository at this point in the history
Added "Figure: " prefix to captions in both HTML and Markdown outputs
  • Loading branch information
JacquesCarette authored Aug 27, 2024
2 parents b504f5d + 3985194 commit 406f560
Show file tree
Hide file tree
Showing 56 changed files with 194 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ traceGCon ex = map LlC (zipWith (traceGraphLC ex) traceGFiles traceGUIDs) ++ [mk

-- | Generates traceability graphs as figures on an SRS document.
traceGraphLC :: String -> FilePath -> UID -> LabelledContent
traceGraphLC ex fp u = llcc (makeFigRef' u) $ fig (S $ show u) $ traceyGraphPath ex fp
traceGraphLC ex fp u = llcc (makeFigRef' u) $ fig (S $ show u) (traceyGraphPath ex fp)

-- | Traceability graph file names.
traceGFiles :: [String]
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-docLang/lib/Drasil/ExtractDocDesc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ getCon EqnBlock{} = []
getCon CodeBlock{} = []
getCon (DerivBlock h d) = h : concatMap getCon d
getCon (Enumeration lst) = getLT lst
getCon (Figure l _ _) = [l]
getCon (Figure l _ _ _) = [l]
getCon (Bib bref) = getBib bref
getCon (Graph [(s1, s2)] _ _ l) = [s1, s2, l]
getCon Graph{} = []
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-example/glassbr/lib/Drasil/GlassBR/Figures.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resourcePath = "../../../../datafiles/glassbr/"
sysCtxFig, physSystFig, traceItemSecsFig, traceReqsItemsFig, traceAssumpsOthersFig, demandVsSDFig, dimlessloadVsARFig :: LabelledContent

sysCtxFig = llcc (makeFigRef "sysCtxDiag") $
fig (titleize sysCont) (resourcePath ++ "SystemContextFigure.png")
fig (titleize sysCont) (resourcePath ++ "SystemContextFigure.png")

physSystFig = llcc (makeFigRef "physSystImage") $ figWithWidth
(atStartNP $ the physicalSystem) (resourcePath ++ "physicalsystimage.png") 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ resourcePath = "../../../datafiles/Projectile/"

figCSandA :: LabelledContent
figCSandA = llcc (makeFigRef "CoordSystAndAssumpts") $ fig (atStartNP $ the coordinateSystem)
(resourcePath ++ "CoordSystAndAssumpts.png")
(resourcePath ++ "CoordSystAndAssumpts.png")
8 changes: 4 additions & 4 deletions code/drasil-lang/lib/Language/Drasil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ module Language.Drasil (
-- Language.Drasil.Document
, Document(..), ShowTableOfContents(..), DType(..), Section(..)
, Contents(..), SecCons(..), ListType(..), ItemType(..), ListTuple
, LabelledContent(..), UnlabelledContent(..), extractSection
, LabelledContent(..), UnlabelledContent(..), HasCaption(..), extractSection
, mkParagraph, mkRawLC, checkToC
, llcc, ulcc
, section, fig, figWithWidth
, section, fig, figNoCap, figWithWidth, figNoCapWithWidth
, MaxWidthPercent
, HasContents(accessContents)
, RawContent(..)
Expand Down Expand Up @@ -314,15 +314,15 @@ import Language.Drasil.ModelExpr.Class (ModelExprC(..))
import Language.Drasil.ModelExpr.Lang (ModelExpr, DerivType, ModelExpr(Spc))
import Language.Drasil.CodeExpr.Lang (CodeExpr)
import Language.Drasil.CodeExpr.Class (CodeExprC(..))
import Language.Drasil.Document (section, fig, figWithWidth
import Language.Drasil.Document (section, fig, figNoCap, figWithWidth, figNoCapWithWidth
, Section(..), SecCons(..) , llcc, ulcc, Document(..)
, mkParagraph, mkFig, mkRawLC, ShowTableOfContents(..), checkToC, extractSection
, makeTabRef, makeFigRef, makeSecRef, makeEqnRef, makeURI
, makeTabRef', makeFigRef', makeSecRef', makeEqnRef', makeURI')
import Language.Drasil.Document.Core (Contents(..), ListType(..), ItemType(..), DType(..)
, RawContent(..), ListTuple, MaxWidthPercent
, HasContents(accessContents)
, LabelledContent(..), UnlabelledContent(..) )
, LabelledContent(..), UnlabelledContent(..), HasCaption(..))
import Language.Drasil.Document.Contents (lbldExpr, unlbldExpr, unlbldCode
, enumBullet, enumBulletU, enumSimple, enumSimpleU, mkEnumSimpleD)
import Language.Drasil.Document.Combinators
Expand Down
18 changes: 13 additions & 5 deletions code/drasil-lang/lib/Language/Drasil/Document.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Language.Drasil.Document where

import Language.Drasil.ShortName (HasShortName(..), ShortName, shortname')
import Language.Drasil.Document.Core (UnlabelledContent(UnlblC),
LabelledContent(LblC), RawContent(Figure, Paragraph),
LabelledContent(LblC), HasCaption(..), RawContent(Figure, Paragraph),
Contents(..), Lbl, Filepath, Author, Title, MaxWidthPercent )
import Language.Drasil.Label.Type (getAdd, prepend, LblType(..),
Referable(..), HasRefAddress(..) )
Expand Down Expand Up @@ -132,13 +132,21 @@ getSecCons :: SecCons -> [Section]
getSecCons (Sub sec) = getSec sec
getSecCons (Con _) = []

-- | 'Figure' smart constructor with a 'Lbl' and a 'Filepath'. Assumes 100% of page width as max width.
-- | 'Figure' smart constructor with a 'Lbl' and a 'Filepath'. Assumes 100% of page width as max width. Defaults to 'WithCaption'.
fig :: Lbl -> Filepath -> RawContent
fig l f = Figure l f 100
fig l f = Figure l f 100 WithCaption

-- | 'Figure' smart constructor that allows for customized max widths.
-- | 'Figure' smart constructor without a caption.
figNoCap :: Lbl -> Filepath -> RawContent
figNoCap l f = Figure l f 100 NoCaption

-- | 'Figure' smart constructor that allows for customized max widths. Defaults to 'WithCaption'.
figWithWidth :: Lbl -> Filepath -> MaxWidthPercent -> RawContent
figWithWidth = Figure
figWithWidth l f wp = Figure l f wp WithCaption

-- | 'Figure' smart constructor with customized max widths and no caption.
figNoCapWithWidth :: Lbl -> Filepath -> MaxWidthPercent -> RawContent
figNoCapWithWidth l f wp = Figure l f wp NoCaption

---------------------------------------------------------------------------
-- * Reference Constructors
Expand Down
7 changes: 6 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Document/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ data DType = General
| Theory
| Data

-- | Indicates whether a figure has a caption or not.
data HasCaption = NoCaption | WithCaption
deriving (Eq)

-- | Types of layout objects we deal with explicitly.
data RawContent =
Table [Sentence] [[Sentence]] Title Bool -- ^ table has: header-row, data(rows), label/caption, and a bool that determines whether or not to show label.
Expand All @@ -70,7 +74,8 @@ data RawContent =
| DerivBlock Sentence [RawContent] -- ^ Grants the ability to label a group of 'RawContent'.
| Enumeration ListType -- ^ For enumerated lists.
| Defini DType [(Identifier, [Contents])] -- ^ Defines something with a type, identifier, and 'Contents'.
| Figure Lbl Filepath MaxWidthPercent -- ^ For creating figures in a document. Should use relative file path.
| Figure Lbl Filepath MaxWidthPercent HasCaption
-- ^ For creating figures in a document includes whether the figure has a caption.
| Bib BibRef -- ^ Grants the ability to reference something.
| Graph [(Sentence, Sentence)] (Maybe Width) (Maybe Height) Lbl -- ^ Contain a graph with coordinates ('Sentence's), maybe a width and height, and a label ('Sentence').
| CodeBlock CodeExpr -- ^ Block for codes
Expand Down
14 changes: 5 additions & 9 deletions code/drasil-printers/lib/Language/Drasil/HTML/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,11 @@ reflinkURI :: String -> Doc -> Doc
reflinkURI rf txt = text ("<a href=\"" ++ rf ++ "\">") <> txt <> text "</a>"

-- | Helper for setting up figures.
image :: Doc -> Doc -> MaxWidthPercent -> Doc
image f c 100 =
figure $ vcat [
img [("src", f), ("alt", c)],
figcaption c]
image f c wp =
figure $ vcat [
img [("src", f), ("alt", c), ("width", text $ show wp ++ "%")],
figcaption c]
image :: Doc -> Maybe Doc -> MaxWidthPercent -> Doc
image f Nothing wp =
figure $ vcat [img $ [("src", f), ("alt", text "")] ++ [("width", text $ show wp ++ "%") | wp /= 100]]
image f (Just c) wp =
figure $ vcat [img $ [("src", f), ("alt", c)] ++ [("width", text $ show wp ++ "%") | wp /= 100], figcaption $ text "Figure: " <> c]

em, sup, sub, bold :: Doc -> Doc
-- | Emphasis (italics) tag.
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-printers/lib/Language/Drasil/HTML/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ printLO (Table ts rows r b t) = makeTable ts rows (pSpec r) b (pSpec t)
printLO (Definition dt ssPs l) = makeDefn dt ssPs (pSpec l)
printLO (Header n contents _) = h (n + 1) $ pSpec contents -- FIXME
printLO (List t) = makeList t
printLO (Figure r c f wp) = makeFigure (pSpec r) (pSpec c) (text f) wp
printLO (Figure r c f wp) = makeFigure (pSpec r) (fmap pSpec c) (text f) wp
printLO (Bib bib) = makeBib bib
printLO Graph{} = empty -- FIXME
printLO Cell{} = empty
Expand Down Expand Up @@ -340,7 +340,7 @@ pItem (Nested s l) = vcat [pSpec s, makeList l]
------------------BEGIN FIGURE PRINTING--------------------------
-----------------------------------------------------------------
-- | Renders figures in HTML.
makeFigure :: Doc -> Doc -> Doc -> L.MaxWidthPercent -> Doc
makeFigure :: Doc -> Maybe Doc -> Doc -> L.MaxWidthPercent -> Doc
makeFigure r c f wp = refwrap r (image f c wp)

-- | Renders assumptions, requirements, likely changes.
Expand Down
12 changes: 6 additions & 6 deletions code/drasil-printers/lib/Language/Drasil/JSON/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ reflink ref txt = text "[" <> txt <> text ("](#" ++ ref ++ ")")
reflinkURI :: String -> Doc -> Doc
reflinkURI ref txt = text ("<a href=\\\"" ++ ref ++ "\\\">") <> txt <> text "</a>"

-- | Helper for setting up figures
image :: Doc -> Doc -> MaxWidthPercent -> Doc
image f c 100 =
-- | Helper for setting up figures.
image :: Doc -> Maybe Doc -> MaxWidthPercent -> Doc
image f Nothing wp =
figure $ vcat [
nbformat $ img [("src", f), ("alt", c)]]
image f c wp =
nbformat $ img $ [("src", f), ("alt", text "")] ++ [("width", text $ show wp ++ "%") | wp /= 100]]
image f (Just c) wp =
figure $ vcat [
nbformat $ img [("src", f), ("alt", c), ("width", text $ show wp ++ "%")]]
nbformat $ img $ [("src", f), ("alt", c)] ++ [("width", text $ show wp ++ "%") | wp /= 100]]

h :: Int -> Doc
h n | n < 1 = error "Illegal header (too small)"
Expand Down
6 changes: 3 additions & 3 deletions code/drasil-printers/lib/Language/Drasil/JSON/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ printLO (EqnBlock contents) = nbformat mathEqn
printLO (Table _ rows r _ _) = nbformat empty $$ makeTable rows (pSpec r)
printLO (Definition dt ssPs l) = nbformat (text "<br>") $$ makeDefn dt ssPs (pSpec l)
printLO (List t) = nbformat empty $$ makeList t False
printLO (Figure r c f wp) = makeFigure (pSpec r) (pSpec c) (text f) wp
printLO (Figure r c f wp) = makeFigure (pSpec r) (fmap pSpec c) (text f) wp
printLO (Bib bib) = makeBib bib
printLO Graph{} = empty
printLO CodeBlock {} = empty
Expand All @@ -101,7 +101,7 @@ printLO' (EqnBlock contents) = nbformat mathEqn
printLO' (Table _ rows r _ _) = markdownCell $ makeTable rows (pSpec r)
printLO' Definition {} = empty
printLO' (List t) = markdownCell $ makeList t False
printLO' (Figure r c f wp) = markdownCell $ makeFigure (pSpec r) (pSpec c) (text f) wp
printLO' (Figure r c f wp) = markdownCell $ makeFigure (pSpec r) (fmap pSpec c) (text f) wp
printLO' (Bib bib) = markdownCell $ makeBib bib
printLO' Graph{} = empty
printLO' (CodeBlock contents) = codeCell $ codeformat $ cSpec contents
Expand Down Expand Up @@ -290,7 +290,7 @@ sItem (Flat s) = pSpec s
sItem (Nested s l) = vcat [pSpec s, makeList l False]

-- | Renders figures in HTML
makeFigure :: Doc -> Doc -> Doc -> L.MaxWidthPercent -> Doc
makeFigure :: Doc -> Maybe Doc -> Doc -> L.MaxWidthPercent -> Doc
makeFigure r c f wp = refID r $$ image f c wp

-- | Renders assumptions, requirements, likely changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ mkTitle sm t = text "\"" <> pSpec empty (spec sm t) <> text "\""
assetMat :: PrintingInformation -> [[Filepath]]
assetMat (PI {_ckdb = cdb}) =
[[fp, "src/assets/" ++ takeFileName fp]
| (LblC { _ctype = Figure _ fp _ }, _) <- elems $ cdb ^. labelledcontentTable
| (LblC { _ctype = Figure _ fp _ _ }, _) <- elems $ cdb ^. labelledcontentTable
]
7 changes: 3 additions & 4 deletions code/drasil-printers/lib/Language/Drasil/Markdown/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ reflinkURI ref txt = if ref == txt then ang ref
else brackets txt <> parens ref

-- | Helper for setting up figures
image :: Doc -> Doc -> Doc
image f c = text "!" <> reflinkURI fp c $^$ bold c
where
fp = text $ "./assets/" ++ takeFileName (show f)
image :: Doc -> Maybe Doc -> Doc
image f Nothing = text "!" <> reflinkURI (text $ "./assets/" ++ takeFileName (show f)) (text "")
image f (Just c) = text "!" <> reflinkURI (text $ "./assets/" ++ takeFileName (show f)) c $^$ bold (text "Figure: " <> c)

-- | Helper for setting up captions
caption :: Doc -> Doc
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-printers/lib/Language/Drasil/Markdown/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ printLO rm (EqnBlock contents) = text "\\\\[" <> rndr contents <> text "\\\\]"
printLO rm (Table _ rows r b t) = makeTable rm rows (pSpec rm r) b (pSpec rm t)
printLO rm (Definition _ ssPs l) = makeDefn rm ssPs (pSpec rm l)
printLO rm (List t) = makeList rm t 0
printLO rm (Figure r c f _) = makeFigure (pSpec rm r) (pSpec rm c) (text f)
printLO rm (Figure r c f _) = makeFigure (pSpec rm r) (fmap (pSpec rm) c) (text f)
printLO rm (Bib bib) = makeBib rm bib
printLO _ Graph {} = empty
printLO _ CodeBlock {} = empty
Expand Down Expand Up @@ -306,7 +306,7 @@ item rm (Nested s l) = vcat [pSpec rm s, makeList rm l 0]
-----------------------------------------------------------------

-- | Renders figures in Markdown
makeFigure :: Doc -> Doc -> Doc -> Doc
makeFigure :: Doc -> Maybe Doc -> Doc -> Doc
makeFigure r c f = centeredDivId r (image f c)

-----------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ layLabelled sm x@(LblC _ (Table hdr lls t b)) = T.Table ["table"]
layLabelled sm x@(LblC _ (EqnBlock c)) = T.HDiv ["equation"]
[T.EqnBlock (P.E (modelExpr c sm))]
(P.S $ getAdd $ getRefAdd x)
layLabelled sm x@(LblC _ (Figure c f wp)) = T.Figure
layLabelled sm x@(LblC _ (Figure c f wp hc)) = T.Figure
(P.S $ getAdd $ getRefAdd x)
(spec sm c) f wp
(if hc == WithCaption then Just (spec sm c) else Nothing)
f wp
layLabelled sm x@(LblC _ (Graph ps w h t)) = T.Graph
(map (bimap (spec sm) (spec sm)) ps) w h (spec sm t)
(P.S $ getAdd $ getRefAdd x)
Expand All @@ -167,7 +168,8 @@ layUnlabelled sm (DerivBlock h d) = T.HDiv ["subsubsubsection"]
(T.Header 3 (spec sm h) refr : map (layUnlabelled sm) d) refr
where refr = P.S "nolabel1"
layUnlabelled sm (Enumeration cs) = T.List $ makeL sm cs
layUnlabelled sm (Figure c f wp) = T.Figure (P.S "nolabel2") (spec sm c) f wp
layUnlabelled sm (Figure c f wp hc) = T.Figure (P.S "nolabel2")
(if hc == WithCaption then Just (spec sm c) else Nothing) f wp
layUnlabelled sm (Graph ps w h t) = T.Graph (map (bimap (spec sm) (spec sm)) ps)
w h (spec sm t) (P.S "nolabel6")
layUnlabelled sm (Defini dtyp pairs) = T.Definition dtyp (layPairs pairs) (P.S "nolabel7")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ data LayoutObj =
| EqnBlock Contents -- ^ Equation block.
| Definition DType [(String,[LayoutObj])] Label -- ^ Definition. Holds the type, contents, and a label.
| List ListType -- ^ List.
| Figure Label Caption Filepath MaxWidthPercent -- ^ Holds all information needed for a figure.
| Figure Label (Maybe Caption) Filepath MaxWidthPercent -- ^ Holds all information needed for a figure.
| Graph [(Spec, Spec)] (Maybe Width) (Maybe Height) Caption Label -- ^ Holds all information needed for a graph.
| CodeBlock Contents -- ^ Code block.
| HDiv Tags [LayoutObj] Label -- ^ Holds tags, more contents, and a label.
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-printers/lib/Language/Drasil/TeX/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ lo (EqnBlock contents) _ = makeEquation contents
lo (Table _ rows r bl t) _ = toText $ makeTable rows (spec r) bl (spec t)
lo (Definition _ ssPs l) sm = toText $ makeDefn sm ssPs $ spec l
lo (List l) _ = toText $ makeList l
lo (Figure r c f wp) _ = toText $ makeFigure (spec r) (spec c) f wp
lo (Figure r c f wp) _ = toText $ makeFigure (spec r) (maybe empty spec c) f wp
lo (Bib bib) sm = toText $ makeBib sm bib
lo (Graph ps w h c l) _ = toText $ makeGraph
(map (bimap spec spec) ps)
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-website/lib/Drasil/Website/Analysis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ graphSecBwPkgs = "The graph displayed below shows the dependencies between the p

-- | Function to create displayable versions of the graphs.
dependencyGraphs :: FilePath -> String -> Contents
dependencyGraphs path pkg = LlC $ llcc (makeFigRef $ "Figure" ++ pkg) $ fig (S $ "Package: " ++ pkg) $ drasilDisplayDepGraphPath path pkg
dependencyGraphs path pkg = LlC $ llcc (makeFigRef $ "Figure" ++ pkg) $ fig (S $ "Package - " ++ pkg) (drasilDisplayDepGraphPath path pkg)

-- | Function to get the paths of graphs we want to display on the website.
drasilDisplayDepGraphPath :: FilePath -> FilePath -> String
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-website/lib/Drasil/Website/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ headerSec =

-- | For the drasil tree image on the website.
imageContent :: LabelledContent
imageContent = llcc (makeFigRef "Drasil") $ figWithWidth EmptyS imagePath 50
imageContent = llcc (makeFigRef "Drasil") $ figNoCapWithWidth EmptyS imagePath 50

-- | Used for the repository link.
gitHubRef :: Reference
Expand Down
9 changes: 4 additions & 5 deletions code/stable-website/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 406f560

Please sign in to comment.