souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.08k stars 89 forks source link

Improve the display of attached files #61

Closed giboow closed 1 year ago

giboow commented 1 year ago

Attached files (Pdf/File/Video) are displayed via an "Image" link It would be nice if a link with the file name was displayed.

giboow commented 1 year ago

It's possible to extract filename from S3 Url using regex:

case "pdf":
                {
                    let blockContent;
                    if (type === "video")
                        blockContent = block.video;
                    if (type === "file")
                        blockContent = block.file;
                    if (type === "pdf")
                        blockContent = block.pdf;

                    if (blockContent) {
                        const file_type = blockContent.type;
                        let link;
                        if (file_type === "external")
                            link = blockContent.external.url;
                        if (file_type === "file")
                            link = blockContent.file.url;

                        if (link) {
                            const matches = link.match(/[^\/\\&\?]+\.\w{3,4}(?=([\?&].*$|$))/);
                            let fileName = matches ? matches[0] : "Image";
                            return md.link(fileName, link);
                        }
                    }
                }
                break;
souvikinator commented 1 year ago

Keeping this on hold since a feature to deal with the s3 urls is work in progress. More details here #60

souvikinator commented 1 year ago

This feature should be live in the upcoming major release. Thank you for contribution. Closing the issue now. In case of any issues feel free to reopen it.