-
Notifications
You must be signed in to change notification settings - Fork 44
Lesson export #134
base: master
Are you sure you want to change the base?
Lesson export #134
Conversation
…md as a .zip file
…sts + images linked in markdown
Thanks! This is fine @Blargian – we can work with this. It's probably my fault in the beginning (when I first set up the repo) for not being strict enough with code formatting. This review is on my todo list. I haven't forgotten 😄 |
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.
Apologies on the review delay.
This is an amazing PR – Great job! Thanks for taking the time to make such a substantial and helpful contribution. I've had a quick play around it seems to work great.
I've left a couple of minor comments. The main change is to revert the deletion of the .editorconfig
file.
I think going forward, we can look to add in a build tool like webpack vs having vendor libraries copied in i.e. jzip & fileSaver. In the meantime it might be cleaner to move these into a vendor
directory so it makes it easier for other contributors to differentiate between project source code and third-party source code.
Also, (beyond the scope of this PR for now) it would be nice to have some of the lesson export functions tested. Specifically, hasElementChild
, mapTagToMd
, and downloadFile
just in case there are some edge cases that haven't been accounted for.
//Retrieves the lesson object from localstorage given the lessonID | ||
this.dataFromLocalStorage = function (lessonID) { | ||
try { | ||
return JSON.parse(localStorage.getItem("user")).lessons.filter( |
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.
Nice 👍
markdown.push(mdOfElement + " \n"); | ||
} | ||
} | ||
console.log(markdown); |
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.
can we remove this log please
return (string += line); | ||
}, "") | ||
); | ||
zip.generateAsync({ type: "blob" }).then(function (content) { |
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.
Do we need to safeguard against this async logic failing here? Could we wrap this in a try/catch or chain a .catch
block?
}; | ||
|
||
const headingToMD = (className, textContent) => { | ||
switch (className) { |
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.
Great use of a switch statement here!
}; | ||
|
||
let elements = parsedDocument.body.children; | ||
for (let i = 0; i < elements.length; i++) { |
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.
nit: could we use a forEach
here for consistency?
app-main/.editorconfig
Outdated
@@ -1,12 +0,0 @@ | |||
# EditorConfig helps developers define and maintain consistent |
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.
We don't want to remove the editorconfig. If you can add this back in that would be great :)
}; | ||
|
||
//Takes a lesson object and formats the data to be markdown | ||
this.formatMarkdown = function (lessonObject) { |
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.
Destructuring can be a nice clean alternative for extracting values from object props. I.e.
function ({ title, content }) {
|
||
//Stateful image counter function using a closure | ||
//Increments by 1 each time it is called | ||
const imageCounter = (function () { |
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.
Nice use of an IIFE 👍
}; | ||
})(); | ||
|
||
//Maps an htmltag to the correspinding md and pushes to markdown array |
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.
nit: small typo in the comment 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.
Hi @jrobind, thanks for your feedback! I think I hit all the points you mentioned. Have added back the .editorconfig file but the indentation problem is back unfortunately.
Hi @jrobind, I tried a bunch of things but have ended up just removing the .editorconfig file. This last commit titled "removed .editorconfig" seems to have corrected the indentation issues and the diffs in the files I did change are showing correctly. Let me know if you're still having issues.