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

Allow 6-digit color spec w/o # #1690

Merged
merged 5 commits into from Sep 1, 2018
Merged

Allow 6-digit color spec w/o # #1690

merged 5 commits into from Sep 1, 2018

Conversation

ronkok
Copy link
Collaborator

@ronkok ronkok commented Aug 31, 2018

This PR takes a minimalist approach to addressing issue #1657. This does not completely change the color specification syntax to align with the color package or the xcolor package. It does not accommodate RGB notation or a cmyk color model. It does, however, allow a 6-digit HTML color specification to pass without a leading # symbol, as in xcolor's HTML color model.

Copy link
Member

@kevinbarabash kevinbarabash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving our \color a little closer towards LaTeX's \color.

src/Parser.js Outdated
// If not predefined, allow a 6-digit color specification without
// a leading #, as in the xcolor package's HTML color model.
const colorWordRegEx = RegExp("^(silver|maroon|purple|yellow|orange" +
"|bisque|indigo|orchid|salmon|sienna|tomato|violet)$",'i');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're passing through strings whose length aren't 6 maybe we check that color matches a hex 6-tuple that way we're not prefix things like cherry. What's LaTeX's behaviour if it gets a named color that isn't defined? Also, you said this PR was minimal so may we can deal with those situations in subsequent PR.

Copy link
Member

@ylemkimon ylemkimon Sep 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every supported 6-letter color names seem to be out of hexadecimal digits range ([0-9a-f]). I think it'd be better to test for [0-9a-f]{6}. Also, why not support 3-digit color codes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not support 3-digit color codes?

  1. 3-digit codes preceded by # are already supported by KaTeX. No change there.
  2. 3-digit codes not preceded by # are not supported by the xcolor package. Since I'm trying to nudge this a little closer to xcolor, I thought it best to fall in line with this behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's LaTeX's behaviour if it gets a named color that isn't defined?

There is an error message such as: !Package xcolor Error: Undefined color 'cherry'. quicklatex.com will still render a black expression if the Report LaTeX errors box is unchecked. So the error behavior is somewhat similar to KaTeX. That is, KaTeX also will render a black expression.

maybe we check that color matches a hex 6-tuple

I'll see if that can be done fairly easily.

@codecov
Copy link

codecov bot commented Sep 1, 2018

Codecov Report

Merging #1690 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1690      +/-   ##
==========================================
+ Coverage   93.84%   93.85%   +<.01%     
==========================================
  Files          78       78              
  Lines        4568     4571       +3     
  Branches      801      802       +1     
==========================================
+ Hits         4287     4290       +3     
  Misses        248      248              
  Partials       33       33
Impacted Files Coverage Δ
src/Parser.js 97.12% <100%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3ec100...80662d7. Read the comment docs.

@ronkok
Copy link
Collaborator Author

ronkok commented Sep 1, 2018

The latest commit revises the RegEx pattern as recommended by @ylemkimon. (Thanks!) This simplifies the code but it does not raise a parse error on a mis-typed predefined color name. \color{cherry} will render in black.

I'd like to raise an error on a mis-typed predefined color name, but the only way I can think to accomplish that is via a RegEx pattern that enumerates all 150 of the HTML predefined colors. Is that something I should do?

src/Parser.js Outdated
return newArgument({
type: "color-token",
mode: this.mode,
color: match[0],
color: color,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be just color,.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ylemkimon
Copy link
Member

I'd like to raise an error on a mis-typed predefined color name, but the only way I can think to accomplish that is via a RegEx pattern that enumerates all 150 of the HTML predefined colors. Is that something I should do?

I think it is impossible without access to DOM APIs and there is no need to check the color name is valid.

@kevinbarabash kevinbarabash merged commit 9b7e10e into KaTeX:master Sep 1, 2018
@ronkok ronkok deleted the colorDescription branch September 2, 2018 03:31
@jessebett
Copy link

Just wanted to come in here and say thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants