-
Notifications
You must be signed in to change notification settings - Fork 181
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
Markdoc formatter - update to skip printing undefined attributes #432
Conversation
I want to let @mfix-stripe weigh in before merging, but this looks good to me. |
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.
PTAL @matv-stripe
src/formatter.ts
Outdated
if (Ast.isAst(v)) { | ||
return format(v); | ||
} | ||
if (v === null) { | ||
return 'null'; | ||
} | ||
if (v === undefined) { |
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.
Let's just move this to the top of this function.
src/formatter.ts
Outdated
if (formattedValue !== undefined) { | ||
return `${a.name}=${formattedValue}`; | ||
} else { | ||
// The Markdoc parser does not support undefined attribute | ||
// values. Filter those values out. | ||
return undefined; | ||
} |
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.
if (formattedValue !== undefined) { | |
return `${a.name}=${formattedValue}`; | |
} else { | |
// The Markdoc parser does not support undefined attribute | |
// values. Filter those values out. | |
return undefined; | |
} | |
if (formattedValue !== undefined) { | |
return `${a.name}=${formattedValue}`; | |
} | |
// The Markdoc parser does not support undefined attribute | |
// values. Filter those values out. | |
return undefined; | |
src/formatter.ts
Outdated
const attributes = [...formatAttributes(n)]; | ||
const tag = [open + n.tag, ...attributes.filter((v) => v !== undefined)]; |
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.
const attributes = [...formatAttributes(n)]; | |
const tag = [open + n.tag, ...attributes.filter((v) => v !== undefined)]; | |
const attributes = [...formatAttributes(n)].filter((v) => v !== undefined); | |
const tag = [open + n.tag, ...attributes]; |
ptal @mfix-stripe |
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.
PTAL @matv-stripe — one more thing, sorry!
src/formatter.ts
Outdated
if (formattedValue !== undefined) { | ||
return `${a.name}=${formattedValue}`; | ||
} | ||
// The Markdoc parser does not support undefined attribute | ||
// values. Filter those values out. | ||
return undefined; |
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.
Wait, I just realized. Let's just move if (formattedValue === undefined) return undefined
to the first branch of this function, and leave return
${a.name}=${formattedValue};
as the fallback.
ty for the feedback! ptal @mfix-stripe |
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.
TY!
See test - the Markdoc parser does not support
undefined
passed into as an attribute. When generating Markdoc this can cause issues because the data source might have undefined values.Let me know thoughts around this, I am fine with not merging it.
r? @mfix-stripe