-
Notifications
You must be signed in to change notification settings - Fork 93
Format checkboxes #1128
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
Format checkboxes #1128
Conversation
@rscharfe I force-pushed your branch, please 8000 review. Range-diff
|
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 paragraph lamenting the ESLint annotations should be replaced by a note saying that you fixed them, Dscho.
I give two more line-specific comments, hopefully just demonstrating lack of experience with JavaScript and TypeScript.
Thank you for the test!
@@ -36,6 +36,10 @@ export function md2text(markdown: string, columns = 76): string { | |||
.replace(/(^|\n)(\n)(?!$)/g, "$1>$2"); // quote empty | |||
}}); | |||
}, | |||
checkBoxFormatter: (elem, _walk, builder) => { |
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.
Simply removing the unused function parameter didn't occur to me because using a different signature between caller and callee seems weird. I don't know JavaScript enough to know whether it can cause trouble.
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.
Yes, if you are used to C it looks terrifying to "just drop" a parameter. Yet that's totally normal in Javascript.
lib/markdown-renderer.ts
Outdated
@@ -36,6 +36,10 @@ export function md2text(markdown: string, columns = 76): string { | |||
.replace(/(^|\n)(\n)(?!$)/g, "$1>$2"); // quote empty | |||
}}); | |||
}, | |||
checkBoxFormatter: (elem, _walk, builder) => { | |||
const attribs = elem.attribs as { checked?: boolean }; |
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 cast looks tricky -- hopefully just to me, lacking TypeScript experience. It would be nice if the type of elem could be inferred from the caller of this callback, but that's probably a bridge too far. elem.attrib also has a property named "type" (not optional, it seems), but we can simply ignore it here, I guess? https://github.com/html-to-text/node-html-to-text/blob/ba8697718d9995efbfe6255fe27d629e9d556b0b/lib/formatter.js#L147 has "const attribs = elem.attribs || {};"; would that work as well?
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.
This cast basically says that we know that this any
type is actually an object that has an optional checked
attribute.
However, there is a bug: the attribute has type string ;-)
Will fix.
GitHub task lists are represented in HTML as unordered lists with checkboxes. These checkboxes are currently ignored when converting the HTML to text. This affects PRs with task lists (e.g. git/git#1359); the resulting text list has no indication anymore whether an item was checked (done) or not. Format checkboxes by turning checked ones into "[x]" and unchecked ones into "[ ]" to retain that information during the conversion. Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
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.
@rscharfe please have another look. As soon as you give the thumbs-up, I'll 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.
Looks good to me! Indeed, checked is either absent or a string.
GitHub task lists are represented in HTML as unordered lists with checkboxes. These checkboxes are currently ignored when converting the HTML to text. This affects PRs with task lists (e.g. git/git#1359); the resulting text list has no indication anymore whether an item was checked (done) or not.
E.g. this:
Is turned into:
* done item
* item still to do
Format checkboxes by turning checked ones into "[x]" and unchecked ones into "[ ]" to retain that information during the conversion. This turns the text result for the example above into:
* [x] done item
* [ ] item still to do
Unfortunately the simple formatter callback requires two ESLint annotations to avoid a warning and an error because it doesn't use all of its parameters and needs to access elem.attribs, which is untyped for some reason. Hopefully there's a better way, but that's the best I can do for now.