-
Notifications
You must be signed in to change notification settings - Fork 374
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 attachment rendering in PDF and HTML #716
Add attachment rendering in PDF and HTML #716
Conversation
Add attachment getter in PDF export (exports.ts) Add parsing note md content to replace <img src='id'> with valid note id - id blob is replaced with object url link in PDF export - id blob is replaced with base64 encoding of the image Update downloadBlob to have cleanup callback (for revoking objectURLs in PDF export)
src/lib/download.ts
Outdated
@@ -22,6 +30,9 @@ export function downloadBlob(blob: Blob, fileName: string) { | |||
anchor.click() | |||
window.URL.revokeObjectURL(anchor.href) | |||
document.body.removeChild(anchor) | |||
if (callback) { |
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 is unnecessary. There are no deferred statements.
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.
True, fixed!
src/lib/download.ts
Outdated
@@ -22,6 +30,9 @@ export function downloadBlob(blob: Blob, fileName: string) { | |||
anchor.click() |
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 think we should use download apis https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/downloads
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.
Or use writeFile
method from electronOnly
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 didn't really write this method, but will need more time to investigate this downloads API, is this something we could use from electron API? Yes I see, for blob it don't matter since we could just write it to disk? Will update it later today.
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.
So I investigated this further. For download APIs - that's extensions? In this case electron supports some, but it seems a bit complicated setting that up, do you have any examples of this? did you try it?
As for writeFile, I could call something like this:
await writeFile(fileName, Buffer.from(await blob.arrayBuffer()))
similar thing is done for attachment writing. But this involves promises and a drawback that we are saving it with filename only - location should then be fetched from user somehow (folder where to save the item, as we have for storage location selection boxes).
This is currently done with ".click()" when user selects the location, in that location/filename the blob is saved/downloaded.
So can you inspect this one more time, and give me the specification, which method would be best, so we can change it?
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 guess we can merge this now. I'll investigate more later!
src/lib/exports.ts
Outdated
@@ -189,10 +204,108 @@ const generatePrintToPdfHTML = ( | |||
` | |||
} | |||
|
|||
const blobToBase64 = async (blob: Blob) => { |
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.
convertBlobToBase64
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 prefer to use conventional functions rather than arrow functions
function convertBlobToBase64(blob: Blob) {...}
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.
Oh I see, didn't know that. Updated
src/lib/exports.ts
Outdated
}) | ||
} | ||
|
||
const updateNoteLinks = async ( |
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.
Same issue 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.
Fixed!
Update download blob to not have callback Use normal functions instead of arrow in exports.ts
Add attachment rendering in PDF and HTML
<img src='id'>
with valid note image idHow it works:
Users can export the PDF and HTML and any image link attached to document which renders well in markdown preview should be exported inside downloaded PDF and HTML (see more details in commit description).
How it looks:
- md:
- result: PDF & HTML
Test:
Test invalid attachements exporting, error message, see below:
Error Handling:
If attachment cannot be found, it is skipped and error message is shown to the user. The exporting continues with all valid attachments.