-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
EDIT: I looked at In the LaTeX Print.hs file, we have a function escapeChars :: Char -> String
escapeChars '_' = "\\_"
escapeChars c = [c] Which (if any) HTML and LaTeX characters should be escaped and which should result in errors? @JacquesCarette These are the lists of special characters in both languages. Also, before you mentioned using |
For HTML: For LaTeX: I would say |
@samm82 I definitely didn't mean to implement I think @Mornix 's refinement of what should be escaped / errors is good. I mean that a checking function should return type |
As far as I can tell, calling the check function in Drasil/code/drasil-gen/Language/Drasil/Generate.hs Lines 57 to 61 in 47c3358
by going over doc , although I'm not sure the best way to do that.
|
Also, changing the check function to give an |
So There are two check functions to write:
|
What should we do about underscores already in Drasil (mainly in labels, like Check-Physical_Constraints)? I'd say just replace them with hyphens. |
Also, I'm not sure how to make/where to put the first function. I tried moving the structure from spec :: Spec -> D
spec a@(s :+: t) = s' <> t'
where
ctx = const $ needs a
s' = switch ctx $ spec s
t' = switch ctx $ spec t
spec (E ex) = toMath $ pure $ text $ pExpr ex
spec (S s) = either error (pure . text . (concatMap escapeChars)) $ checkValidStr s invalid
where invalid = ['&', '#', '$', '%', '&', '~', '^', '\\', '{', '}']
spec (Sy s) = pUnit s
spec (Sp s) = pure $ text $ unPL $ L.special s
spec HARDNL = pure $ text "\\newline"
spec (Ref Internal r sn) = snref r $ spec sn
spec (Ref Cite2 r EmptyS) = cite (pure $ text r)
spec (Ref Cite2 r i) = citeInfo (pure $ text r) (spec i)
spec (Ref External r sn) = externalref r $ spec sn
spec EmptyS = empty
spec (Quote q) = quote $ spec q and I got a
which means that this is a level too deep. I personally think that it makes sense to have this function in |
Yes, replacing underscores with hyphens is a good idea. My guess is someone is prematurely rendering because there should be no ' |
It's defined a little later on in the file: Drasil/code/drasil-printers/Language/Drasil/TeX/Print.hs Lines 469 to 473 in 47c3358
Also, at some point, wouldn't we have to have a "\" inside a string to have it defined so it can be rendered? Since this use of "\" is internal to |
The "" will all be in
|
I have no idea how I'd go about this. Going through the rabbit hole of function calls from data CiteField = Address Spec
| Author People
| BookTitle Spec -- Used for 'InCollection' references only.
| Chapter Int
| Edition Int
| Editor People
| HowPublished HP
| Institution Spec
| Journal Spec
| Month Month
| Note Spec
| Number Int
| Organization Spec
| Pages [Int] -- Range of pages (ex1. 1-32; ex2. 7,31,52-55)
| Publisher Spec
| School Spec
| Series Spec
| Title Spec
| Type Spec -- BibTeX "type" field
| Volume Int
| Year Int And the |
Ok, I can help, but I may not get a proper time window to do it until late today / tomorrow. |
I would prioritize #1601, as it is holding up a couple of other issues unless you think this change is more important. @JacquesCarette |
I'm going to close this PR for now until you have a chance to look at the branch @JacquesCarette since it isn't ready to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are also some very nice changes to the latex printer in here. But a couple of issues to fix.
When an invalid character is encountered in a
Sentence
(wrapped asS String
), an error is thrown:I added the invalid characters list as per these websites: HTML and LaTeX, although I left out the apostrophe and underscore characters since they were both used in Drasil. Should they be checked for as well? Any other thoughts? @JacquesCarette @Mornix
Closes #1534