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
Add newline support by using a regex to parse blockText #22702
Conversation
* either a real named input like '{VALUE}', a newline, or if it matched a | ||
* trailing label, nothing. | ||
*/ | ||
const LABELED_INPUTS_REGEX = /.*?({[^}]*}|\n|$)/gm; |
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.
Why is the .*?
non-greedy match needed at the beginning?
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 matches the label for the input. If it's greedy, it will just consume everything between the beginning of the string and the last input.
It might be clearer to use [^{}]*
to match the label, I could go either way.
const inputs = tokens.map(token => { | ||
const parts = token.match(LABELED_INPUT_PARTS_REGEX); | ||
const label = parts[1]; | ||
const inputName = parts[3]; |
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.
Not at all blocking, but this makes me wish we had the Babel plugin for named capture groups.
apps/src/block_utils.js
Outdated
*/ | ||
const LABELED_INPUT_PARTS_REGEX = /(.*?)({([^}]*)}|\n|$)/m; | ||
|
||
const findInputConfig = (args, inputName) => { |
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.
Maybe clearer as findAndRemoveInputConfig
? Not clear initially that this method mutates the args
array.
Please add a JSDoc.
No description provided.