-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
refactor defineEnvironment to also accept HTML and MathML builders #875
Conversation
ed0b28a
to
0c1caa5
Compare
}, | ||
get(envName: string) { | ||
return _environments[envName]; | ||
}, |
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.
@marcianx here's what I did for the wrapper around _environments
.
* 2. requires all arguments except argType | ||
* It is generated by `defineEnvironment()` below. | ||
*/ | ||
type EnvSpec = {| |
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.
I tightened up some of these types by updating them to use exact object types.
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.
Meta-comment on GitHub reviews vs. Phabricator: I'm finding it frustrating that comments need to pin to a single line.
I thought we'd end up with separate files for |
eacad1e
to
59906e8
Compare
@@ -581,166 +581,6 @@ groupTypes.genfrac = function(group, options) { | |||
options); | |||
}; | |||
|
|||
groupTypes.array = function(group, options) { |
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.
Copied to const htmlBuilder = function(group, options) { ...
in array.js.
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.
Thanks for leaving hints like this!
// is part of the source2e.pdf file of LaTeX2e source documentation. | ||
// {darray} is an {array} environment where cells are set in \displaystyle, | ||
// as defined in nccmath.sty. | ||
defineEnvironment({ |
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.
The calls to defineEnvironment
look a little different from how they looked in environments.js. All of the existing parameters have been converted props in a single object argument. This was done so it's easier to know which param is which.
return res; | ||
}, | ||
htmlBuilder, | ||
mathmlBuilder, |
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.
These are the two "new" parameters.
@@ -1,326 +1,16 @@ | |||
// @flow |
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.
Everything except for defineEnvironment
and the type definitions have been copied over to array.js
while the remaining code has gone to defineEnvironment.js
.
} | ||
if (mathmlBuilder) { | ||
mathmlGroupTypes[type] = mathmlBuilder; | ||
} |
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.
The body of defineEnvironment
has remained largely the same. The new code adds registers the htmlBuilder
and mathmlBuilder
args for the given type
. This was previously being done in buildHTML.js
and buildMathML.js
respectively.
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.
Awesome! This is a big commit for my first foray into KaTeX, but the refactor looks sound. Since I'm unfamiliar with the library, my approval should be taken with a grain of salt; please test this thoroughly before landing.
I left a few questions, but nothing blocking. The motivation described in #870 makes sense to me.
Thanks for doing this!
postgap?: number, | ||
import {_environments} from "./defineEnvironment"; | ||
|
||
const environments = { |
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.
Cool! Is the motivation behind this abstraction to limit access to the _environments
object? Or do you expect for the bodies of has
and get
to eventually become more complicated?
If this API was added solely for clarity, I don't think has
and get
improve readability over hasOwnProperty
and []
.
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.
The motivation was to limit access. The plan was to do the same for _functions
and _symbols
. Not sure how necessary it is so I'm going to let this simmer for a while.
@@ -581,166 +581,6 @@ groupTypes.genfrac = function(group, options) { | |||
options); | |||
}; | |||
|
|||
groupTypes.array = function(group, options) { |
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.
Thanks for leaving hints like this!
src/environments/array.js
Outdated
let row = []; | ||
const body = [row]; | ||
const rowGaps = []; | ||
for (;;) { |
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.
I know this is a copypasta, but while(true)
would be clearer here.
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.
It was originally while(true)
, but a previous commit changed it after removing a top level eslint-disable. I can add it back in with a eslint-disable-line.
* 2. requires all arguments except argType | ||
* It is generated by `defineEnvironment()` below. | ||
*/ | ||
type EnvSpec = {| |
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.
Meta-comment on GitHub reviews vs. Phabricator: I'm finding it frustrating that comments need to pin to a single line.
src/environments/array.js
Outdated
"vmatrix", | ||
"Vmatrix", | ||
], | ||
props: {}, |
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.
Should props
be optional?
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.
That's a good question. defineFunction
requires numArgs
on props
even if it's 0
. I'm not sure how useful that is, but I'd rather be consistent so I'll make it mandatory here too.
src/defineEnvironment.js
Outdated
* - numOptionalArgs: (default 0) Just like for a function | ||
*/ | ||
type EnvProps = { | ||
numArgs?: number, |
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.
I only see numArgs
used in this review, but I imagine the rest are used elsewhere / externally?
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.
Good catch. We may want to add those at some point in the future, but if they're not being used no reason to include them now.
21190fa
to
598cff3
Compare
fixes #870