Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Check for Invalid Characters in Sentences #1591

Merged
merged 36 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8e69148
Added check for invalid chars in Strings in Sentences
samm82 Jun 19, 2019
f78d371
Removed redundant match in checkValid; added invalidChars to list
samm82 Jun 19, 2019
1a12fd6
Moved checkValidStr to utils
samm82 Jun 21, 2019
e8e633b
Merge branch 'master' into checkInvalidChars
samm82 Jun 21, 2019
9195ca2
Linted
samm82 Jun 21, 2019
fd6810b
Merge branch 'master' into checkInvalidChars
samm82 Jun 24, 2019
9dd86af
Changed checkInvalidStr to Either type
samm82 Jun 24, 2019
8067ae4
Merge branch 'master' into checkInvalidChars
samm82 Jun 27, 2019
20b53e5
Merge branch 'master' into checkInvalidChars
samm82 Jun 28, 2019
8e4206f
Merge branch 'master' into checkInvalidChars
samm82 Jul 4, 2019
da642cd
Merge branch 'master' into checkInvalidChars
samm82 Jul 18, 2019
2c878d0
Merge branch 'master' into checkInvalidChars
samm82 Jul 19, 2019
1c40d83
Removed embedded LaTeX from makeBib
samm82 Jul 19, 2019
23816ca
Changed renderF to output D
samm82 Jul 19, 2019
50665da
Minor clean up in Tex.Print
samm82 Jul 22, 2019
d76a6bc
Used showField for month
samm82 Jul 22, 2019
6c8ef87
Merge branch 'master' into checkInvalidChars
samm82 Jul 23, 2019
5c3955a
Used one consistent page folder from -utils
samm82 Jul 23, 2019
45962fd
Merge branch 'master' into checkInvalidChars
samm82 Jul 23, 2019
4c83768
Linted and minor improvements
samm82 Jul 23, 2019
3eee68e
Merge branch 'master' into checkInvalidChars
samm82 Jul 23, 2019
6383b4d
Created wrapField
samm82 Jul 23, 2019
0bd6b2f
Merge branch 'master' into checkInvalidChars
samm82 Jul 24, 2019
0018f60
Improved showField and friends
samm82 Jul 24, 2019
62b0bf6
Merge branch 'master' into checkInvalidChars
samm82 Jul 25, 2019
98b419b
Merge branch 'specLength' into checkInvalidChars
samm82 Jul 26, 2019
6819bd7
Improved makeGraph
samm82 Jul 26, 2019
886f0df
Added showFieldCom via wrapField
samm82 Jul 26, 2019
857b587
Finished checking invalid characters in TeX
samm82 Jul 26, 2019
3515fc3
Checked for invalid characters in HTML
samm82 Jul 26, 2019
15afdb1
Linted
samm82 Jul 26, 2019
8ddfdf1
Merge branch 'master' into checkInvalidChars
samm82 Jul 31, 2019
a32af35
Added range String parameter to foldNums and numList
samm82 Jul 31, 2019
0779b47
Changed foldlList in HTML.Print to output String
samm82 Jul 31, 2019
946b246
Merge branch 'master' into checkInvalidChars
samm82 Aug 1, 2019
47e8a05
Created foldPages and foldPeople
samm82 Aug 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions code/drasil-data/Data/Drasil/Citations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ koothoor2013 =
parnas1972 = cArticle [dParnas]
"On the Criteria To Be Used in Decomposing Systems into Modules"
"Communications of the ACM" 1972
[pages [1053, 1058]] "dParnas1972"
[pages [1053..1058]] "dParnas1972"
samm82 marked this conversation as resolved.
Show resolved Hide resolved

parnasClements1984 = cInProceedings
[dParnas, pcClements, dmWiess]
"The Modular Structure of Complex Systems"
"ICSE '84: Proceedings of the 7th international conference on Software engineering"
1984 [pages [408, 417]] "parnasClements1984"
1984 [pages [408..417]] "parnasClements1984"

parnasClements1986 = cArticle [dParnas, pcClements]
"A rational design process: How and why to fake it"
"IEEE Transactions on Software Engineering" 1986
[month Feb, volume 12, number 2, pages [251,257], address "Washington, USA"]
[month Feb, volume 12, number 2, pages [251..257], address "Washington, USA"]
"parnasClements1986"

smithLai2005 = cInProceedings [spencerSmith, lLai]
Expand All @@ -51,7 +51,7 @@ smithLai2005 = cInProceedings [spencerSmith, lLai]
"Techniques and Tools to Support Situation-Specific Requirements " ++
"Engineering Processes, SREP'05") 2005
[ editor [pjAgerfalk, nKraiem, jRalyte], address "Paris, France"
, pages [107,121],
, pages [107..121],
note "In conjunction with 13th IEEE International Requirements Engineering Conference,"]
"smithLai2005"

Expand Down
2 changes: 1 addition & 1 deletion code/drasil-example/Drasil/GamePhysics/References.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ citations = [parnas1978, sciComp2013, parnas1972, parnasClements1984,
parnas1978 = cInProceedings [dParnas]
"Designing Software for Ease of Extension and Contraction"
"ICSE '78: Proceedings of the 3rd international conference on Software engineering"
1978 [pages [264,277]] "parnas1978"
1978 [pages [264..277]] "parnas1978"

sciComp2013 = cArticle
[gWilson, daAruliah, cTitus, nChueHong, mDavis, rGuy, shdHaddock,
Expand Down
16 changes: 9 additions & 7 deletions code/drasil-example/Drasil/SSP/References.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ chen2005, fredlund1977, li2010, karchewski2012, huston2008,
--See Language.Drasil.People for all person constructors
chen2005 = cArticle [qhQian, dyZhu, cfLee, grChen]
"A concise algorithm for computing the factor of safety using the morgenstern price method"
jnlCGJ 2005 [month Feb, volume 42, number 1, pages [272,278]]
jnlCGJ 2005 [month Feb, volume 42, number 1, pages [272..278]]
"chen2005"

fredlund1977 = cArticle [dgFredlund, jKrahn]
"Comparison of slope stability methods of analysis"
jnlCGJ 1977 [month Apr, pages [429, 439], volume 14, number 3]
jnlCGJ 1977 [month Apr, pages [429..439], volume 14, number 3]
"fredlund1977"

li2010 = cArticle [yCLi, ymChen, tltZhan, ssLing, pjCleall]
("An efficient approach for locating the critical slip surface in" ++
" slope stability analyses using a real-coded genetic algorithm")
jnlCGJ 2010 [month Jun, pages [806,820], volume 47, number 7]
jnlCGJ 2010 [month Jun, pages [806..820], volume 47, number 7]
"li2010"

karchewski2012 = cInProceedings [bKarchewski, pGuo, dStolle]
Expand All @@ -37,8 +37,10 @@ karchewski2012 = cInProceedings [bKarchewski, pGuo, dStolle]
[address "Winnipeg, MB, Canada", organization "Canadian Geotechnical Society"]
"karchewski2012"

huston2008 = cBookA [rHuston, hJosephs] ("Practical stress analysis in " ++
"engineering design") "CRC Press" 2008 [edition 3] "huston2008"
huston2008 = cBookA [rHuston, hJosephs] "Practical stress analysis in engineering design"
"CRC Press" 2008 [edition 3] "huston2008"

morgenstern1965 = cArticle [nrMorgenstern, vePrice] ("The analysis of the " ++ "stability of general slip surfaces") "Géotechnique" 1965 [month Jan,
pages [79,93], number 15] "morgenstern1965"
morgenstern1965 = cArticle [nrMorgenstern, vePrice]
"The analysis of the stability of general slip surfaces"
"Géotechnique" 1965 [month Jan, pages [79..93], number 15]
"morgenstern1965"
88 changes: 48 additions & 40 deletions code/drasil-printers/Language/Drasil/HTML/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Data.List (intercalate, partition, sortBy)
import Text.PrettyPrint hiding (Str)
import Numeric (showEFloat)
import Control.Arrow (second)
import Utils.Drasil (checkValidStr, numList)

import qualified Language.Drasil as L (People, Person,
CitationKind(Misc, Book, MThesis, PhDThesis, Article),
Expand Down Expand Up @@ -92,20 +93,24 @@ titleSpec s = pSpec s

-- | Renders the Sentences in the HTML body (called by 'printLO')
pSpec :: Spec -> Doc
pSpec (E e) = em $ pExpr e
pSpec (a :+: b) = pSpec a <> pSpec b
pSpec (S s) = text s
pSpec (Sy s) = text $ uSymb s
pSpec (Sp s) = text $ unPH $ L.special s
pSpec HARDNL = text "<br />"
pSpec (E e) = em $ pExpr e
pSpec (a :+: b) = pSpec a <> pSpec b
pSpec (S s) = either error (text . concatMap escapeChars) $ checkValidStr s invalid
where
invalid = ['<', '>']
escapeChars '&' = "\\&"
escapeChars c = [c]
pSpec (Sy s) = text $ uSymb s
pSpec (Sp s) = text $ unPH $ L.special s
pSpec HARDNL = text "<br />"
pSpec (Ref Internal r a) = reflink r $ pSpec a
pSpec (Ref Cite2 r EmptyS) = reflink r $ text r -- no difference for citations?
pSpec (Ref Cite2 r a) = reflinkInfo r (text r) (pSpec a) -- no difference for citations?
pSpec (Ref External r a) = reflinkURI r $ pSpec a
pSpec EmptyS = text "" -- Expected in the output
pSpec (Quote q) = doubleQuotes $ pSpec q
-- pSpec (Acc Grave c) = text $ '&' : c : "grave;" --Only works on vowels.
-- pSpec (Acc Acute c) = text $ '&' : c : "acute;" --Only works on vowels.
pSpec EmptyS = text "" -- Expected in the output
pSpec (Quote q) = doubleQuotes $ pSpec q
--pSpec (Acc Grave c) = text $ '&' : c : "grave;" --Only works on vowels.
--pSpec (Acc Acute c) = text $ '&' : c : "acute;" --Only works on vowels.

-- | Renders symbols for HTML document
symbol :: L.Symbol -> String
Expand Down Expand Up @@ -322,12 +327,12 @@ makeBib = ul ["hide-list-style"] . vcat .

--for when we add other things to reference like website, newspaper
renderCite :: Citation -> (Doc, Doc)
renderCite (Cite e L.Book cfs) = (text e, renderF cfs useStyleBk <> text " Print.")
renderCite (Cite e L.Article cfs) = (text e, renderF cfs useStyleArtcl <> text " Print.")
renderCite (Cite e L.MThesis cfs) = (text e, renderF cfs useStyleBk <> text " Print.")
renderCite (Cite e L.PhDThesis cfs) = (text e, renderF cfs useStyleBk <> text " Print.")
renderCite (Cite e L.Misc cfs) = (text e, renderF cfs useStyleBk)
renderCite (Cite e _ cfs) = (text e, renderF cfs useStyleArtcl) --FIXME: Properly render these later.
renderCite (Cite e L.Book cfs) = (text e, renderF cfs useStyleBk <> text " Print.")
renderCite (Cite e L.Article cfs) = (text e, renderF cfs useStyleArtcl <> text " Print.")
renderCite (Cite e L.MThesis cfs) = (text e, renderF cfs useStyleBk <> text " Print.")
renderCite (Cite e L.PhDThesis cfs) = (text e, renderF cfs useStyleBk <> text " Print.")
renderCite (Cite e L.Misc cfs) = (text e, renderF cfs useStyleBk)
renderCite (Cite e _ cfs) = (text e, renderF cfs useStyleArtcl) --FIXME: Properly render these later.

renderF :: [CiteField] -> (StyleGuide -> (CiteField -> Doc)) -> Doc
renderF fields styl = hsep $ map (styl bibStyleH) (sortBy compCiteField fields)
Expand Down Expand Up @@ -402,39 +407,36 @@ bookMLA (Year y) = dot $ text $ show y
--bookMLA (URLdate d m y) = "Web. " ++ bookMLA (Date d m y) sm
bookMLA (BookTitle s) = dot $ em $ pSpec s
bookMLA (Journal s) = comm $ em $ pSpec s
bookMLA (Pages [n]) = dot $ text $ "p. " ++ show n
bookMLA (Pages [a,b]) = dot $ text $ "pp. " ++ show a ++ "&ndash;" ++ show b
bookMLA (Pages _) = error "Page range specified is empty or has more than two items"
bookMLA (Pages [p]) = dot $ text $ "pg. " ++ show p
bookMLA (Pages p) = dot $ text "pp. " <> foldPages p
bookMLA (Note s) = pSpec s
bookMLA (Number n) = comm $ text ("no. " ++ show n)
bookMLA (School s) = comm $ pSpec s
--bookMLA (Thesis t) = comm $ show t
--bookMLA (URL s) = dot $ pSpec s
bookMLA (HowPublished (Verb s)) = comm $ pSpec s
bookMLA (HowPublished (URL l@(S s))) = dot $ pSpec $ Ref External s l
bookMLA (HowPublished (URL s)) = dot $ pSpec s
bookMLA (Editor p) = comm $ text "Edited by " <> pSpec (foldlList (map (S . L.nameStr) p))
bookMLA (Chapter _) = text ""
bookMLA (Institution i) = comm $ pSpec i
bookMLA (Organization i) = comm $ pSpec i
bookMLA (Month m) = comm $ text $ show m
bookMLA (Type t) = comm $ pSpec t
bookMLA (HowPublished (Verb s)) = comm $ pSpec s
bookMLA (HowPublished (URL l@(S s))) = dot $ pSpec $ Ref External s l
bookMLA (HowPublished (URL s)) = dot $ pSpec s
bookMLA (Editor p) = comm $ text "Edited by " <> foldPeople p
bookMLA (Chapter _) = text ""
bookMLA (Institution i) = comm $ pSpec i
bookMLA (Organization i) = comm $ pSpec i
bookMLA (Month m) = comm $ text $ show m
bookMLA (Type t) = comm $ pSpec t

bookAPA :: CiteField -> Doc --FIXME: year needs to come after author in L.APA
bookAPA (Author p) = pSpec (rendPeople L.rendPersLFM' p) --L.APA uses initals rather than full name
bookAPA (Year y) = dot $ text $ paren $ show y --L.APA puts "()" around the year
--bookAPA (Date _ _ y) = bookAPA (Year y) --L.APA doesn't care about the day or month
--bookAPA (URLdate d m y) = "Retrieved, " ++ (comm $ unwords [show d, show m, show y])
bookAPA (Pages [n]) = dot $ text $ show n
bookAPA (Pages [a,b]) = dot $ text $ show a ++ "&ndash;" ++ show b
bookAPA (Pages _) = error "Page range specified is empty or has more than two items"
bookAPA (Editor p) = dot $ pSpec (foldlList $ map (S . L.nameStr) p) <> text " (Ed.)"
bookAPA (Pages p) = dot $ foldPages p
bookAPA (Editor p) = dot $ foldPeople p <> text " (Ed.)"
bookAPA i = bookMLA i --Most items are rendered the same as L.MLA

bookChicago :: CiteField -> Doc
bookChicago (Author p) = pSpec (rendPeople L.rendPersLFM'' p) --L.APA uses middle initals rather than full name
bookChicago p@(Pages _) = bookAPA p
bookChicago (Editor p) = dot $ pSpec (foldlList $ map (S . L.nameStr) p) <> text (toPlural p " ed")
bookChicago (Pages p) = dot $ foldPages p
bookChicago (Editor p) = dot $ foldPeople p <> text (toPlural p " ed")
bookChicago i = bookMLA i --Most items are rendered the same as L.MLA

-- for article renderings
Expand All @@ -459,16 +461,22 @@ artclChicago i = bookChicago i
-- PEOPLE RENDERING --
rendPeople :: (L.Person -> String) -> L.People -> Spec
rendPeople _ [] = S "N.a." -- "No authors given"
rendPeople f people = foldlList $ map (S . f) people --foldlList is in SentenceStructures.hs
rendPeople f people = S . foldlList $ map f people --foldlList is in drasil-utils

rendPeople' :: L.People -> Spec
rendPeople' [] = S "N.a." -- "No authors given"
rendPeople' people = foldlList $ map (S . rendPers) (init people) ++ [S (rendPersL $ last people)]
rendPeople' people = S . foldlList $ map rendPers (init people) ++ [rendPersL (last people)]

foldPages :: [Int] -> Doc
foldPages = text . foldlList . numList "&ndash;"

foldPeople :: L.People -> Doc
foldPeople p = text . foldlList $ map L.nameStr p

foldlList :: [Spec] -> Spec
foldlList [] = EmptyS
foldlList [a,b] = a :+: S " and " :+: b
foldlList lst = foldle1 (\a b -> a :+: S ", " :+: b) (\a b -> a :+: S ", and " :+: b) lst
foldlList :: [String] -> String
foldlList [] = ""
foldlList [a,b] = a ++ " and " ++ b
foldlList lst = foldle1 (\a b -> a ++ ", " ++ b) (\a b -> a ++ ", and " ++ b) lst

foldle1 :: (a -> a -> a) -> (a -> a -> a) -> [a] -> a
foldle1 _ _ [] = error "foldle1 cannot be used with empty list"
Expand Down
56 changes: 14 additions & 42 deletions code/drasil-printers/Language/Drasil/Printing/Import.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Language.Drasil.Printing.Import(space,expr,symbol,spec,makeDocument) where

module Language.Drasil.Printing.Import (space, expr, symbol, spec,
makeDocument) where

import Language.Drasil hiding (sec, symbol)
import Language.Drasil.Development (precA, precB, eprec)
Expand Down Expand Up @@ -257,17 +257,17 @@ pow sm a b = P.Row [expr a sm, P.Sup (expr b sm)]
-- | Print a RealInterval
renderRealInt :: PrintingInformation -> Symbol -> RealInterval Expr Expr -> P.Expr
renderRealInt st s (Bounded (Inc,a) (Inc,b)) =
P.Row [ expr a st, P.MO P.LEq, symbol s, P.MO P.LEq, expr b st]
P.Row [expr a st, P.MO P.LEq, symbol s, P.MO P.LEq, expr b st]
renderRealInt st s (Bounded (Inc,a) (Exc,b)) =
P.Row [ expr a st, P.MO P.LEq, symbol s, P.MO P.Lt, expr b st]
P.Row [expr a st, P.MO P.LEq, symbol s, P.MO P.Lt, expr b st]
renderRealInt st s (Bounded (Exc,a) (Inc,b)) =
P.Row [ expr a st, P.MO P.Lt, symbol s, P.MO P.LEq, expr b st]
P.Row [expr a st, P.MO P.Lt, symbol s, P.MO P.LEq, expr b st]
renderRealInt st s (Bounded (Exc,a) (Exc,b)) =
P.Row [ expr a st, P.MO P.Lt, symbol s, P.MO P.Lt, expr b st]
renderRealInt st s (UpTo (Inc,a)) = P.Row [ symbol s, P.MO P.LEq, expr a st]
renderRealInt st s (UpTo (Exc,a)) = P.Row [ symbol s, P.MO P.Lt, expr a st]
renderRealInt st s (UpFrom (Inc,a)) = P.Row [ symbol s, P.MO P.GEq, expr a st]
renderRealInt st s (UpFrom (Exc,a)) = P.Row [ symbol s, P.MO P.Gt, expr a st]
P.Row [expr a st, P.MO P.Lt, symbol s, P.MO P.Lt, expr b st]
renderRealInt st s (UpTo (Inc,a)) = P.Row [symbol s, P.MO P.LEq, expr a st]
renderRealInt st s (UpTo (Exc,a)) = P.Row [symbol s, P.MO P.Lt, expr a st]
renderRealInt st s (UpFrom (Inc,a)) = P.Row [symbol s, P.MO P.GEq, expr a st]
renderRealInt st s (UpFrom (Exc,a)) = P.Row [symbol s, P.MO P.Gt, expr a st]


-- | Translates Sentence to the Printing representation of Sentence ('Spec')
Expand All @@ -276,7 +276,8 @@ spec :: PrintingInformation -> Sentence -> P.Spec
spec sm (EmptyS :+: b) = spec sm b
spec sm (a :+: EmptyS) = spec sm a
spec sm (a :+: b) = spec sm a P.:+: spec sm b
spec _ (S s) = P.S s
spec _ (S s) = either error P.S $ checkValidStr s invalidChars
where invalidChars = ['<', '>', '\"', '&', '#', '$', '%', '&', '~', '^', '\\', '{', '}']
spec _ (Sy s) = P.Sy s
spec _ Percent = P.E $ P.MO P.Perc
spec _ (P s) = P.E $ symbol s
Expand Down Expand Up @@ -308,38 +309,9 @@ renderCitInfo :: RefInfo -> Sentence
renderCitInfo None = EmptyS
renderCitInfo (RefNote rn) = sParen (S rn)
renderCitInfo (Equation [x]) = sParen (S "Eq." +:+ S (show x))
renderCitInfo (Equation i ) = sParen (S "Eqs." +:+ foldNums i)
renderCitInfo (Equation i ) = sParen (S "Eqs." +:+ foldNums "-" i)
renderCitInfo (Page [x]) = sParen (S "pg." +:+ S (show x))
renderCitInfo (Page i ) = sParen (S "pp." +:+ foldNums i)

-- | Parses a list of integers into a nice sentence (ie. S "1, 4-7, and 13")
foldNums :: [Int] -> Sentence
foldNums x = foldlList Comma List $ map S (numbers x)

-- | Helper for foldNums
numbers :: [Int] -> [String]
numbers [] = error "Empty list when making reference with additional information"
numbers [x] = [show x]
numbers [x, y]
| y == x + 1 = [hyp x y]
| otherwise = map show [x, y]
numbers (x:y:xs)
| y == x + 1 = range x y xs
| otherwise = show x : numbers (y:xs)

-- | Helper for foldNums
range :: Int -> Int -> [Int] -> [String]
range a b [] = [hyp a b]
range a b [x]
| x == b + 1 = [hyp a x]
| otherwise = [hyp a b, show x]
range a b (x:xs)
| x == b + 1 = range a x xs
| otherwise = hyp a b : numbers (x:xs)

-- | Helper for foldNums
hyp :: Int -> Int -> String
hyp a b = show a ++ "-" ++ show b
renderCitInfo (Page i ) = sParen (S "pp." +:+ foldNums "-" i)

-- | Translates from Document to the Printing representation of Document
makeDocument :: PrintingInformation -> Document -> T.Document
Expand Down
15 changes: 11 additions & 4 deletions code/drasil-printers/Language/Drasil/TeX/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,24 @@ mkEnv nm d =
d $+$
pure (text ("\\end" ++ H.brace nm))

-- Encapsulate environments with argument
mkEnvArgs :: String -> String -> D -> D
mkEnvArgs nm args d =
-- Encapsulate environments with argument with braces
mkEnvArgBr :: String -> String -> D -> D
mkEnvArgBr nm args d =
pure (text ("\\begin" ++ H.brace nm ++ H.brace args)) $+$
d $+$
pure (text ("\\end" ++ H.brace nm))

-- Encapsulate environments with argument with brackets
mkEnvArgSq :: String -> String -> D -> D
mkEnvArgSq nm args d =
pure (text ("\\begin" ++ H.brace nm ++ H.sqbrac args)) $+$
d $+$
pure (text ("\\end" ++ H.brace nm))

-- Makes minipage environment
mkMinipage :: D -> D
mkMinipage d = commandD "vspace" (command0 "baselineskip") $+$
command0 "noindent" $+$ mkEnvArgs "minipage" "\\textwidth" d
command0 "noindent" $+$ mkEnvArgBr "minipage" "\\textwidth" d

-- for defining (LaTeX) macros
comm :: String -> String -> Maybe String -> D
Expand Down
Loading