Closed mattstratford closed 4 years ago
Couple things:
/Users/stratfordm/Desktop/test/
) so perhaps I used an incorrect pathing module.Will give a look next time I'm on computer
Is the file path to the image inside the .md file you're trying to upload URL encoded? I can't see how it's getting that file path any other way. Relative file paths shouldn't be URL encoded though so I'm hesitant to add a URL decode. Whatever is generating those .md files probably shouldn't be URL encoding the folder name.
If fixing the thing that's generating the input .md files isn't fixable, you can use imagePathFunc=
to decode your paths before upload.
from pathlib import Path
import urllib
from notion.client import NotionClient
from md2notion.upload import upload
client = NotionClient(token_v2='{token_v2}')
page = client.get_block('https://www.notion.so/Test-0192acd694d443ec924a2a5de270c90d')
def convertImagePath(imagePath, mdFilePath):
decodedImagePath = urllib.parse.unquote(imagePath)
return Path(mdFilePath).parent / Path(decodedImagePath)
upload(mdFile, page , imagePathFunc=convertImagePath)
What do you think?
Thanks for responding. Apologies, I am not anywhere close to being competent with computers… I've done just enough introductory programming courses to be dangerous.
So I tried with a new file which references an image some image.png
in the same directory using a variety of syntaxes, none of which seemed to work
![image](some image.png)
![image](/some image.png)
-![image](attachment:some image.png)
![[some image.png]]
No dice.
So finally I thought maybe the filename itself was causing problems with spaces. Bingo. Renaming the image from some image.png
to image.png
solved it.
![image](image.png)
I guess I can solve my own problem by going through and renaming all the attachments? Or perhaps there's something easy on your end that can handle spaces in file names?
Anyway thanks for getting back to me.
Hmm, so after looking at this further, it looks like links and images with spaces are actually supposed to be interpreted as text by CommonMark
So my suggestion is it's probably better to rename your attachments, but for the sake of utility, it might be nice if md2notion
checked the URLs for file://
syntax as well as URL decode and potentially try all three strings as paths to find a file.
Alright, this should now work for you in v2.1.1. We can reopen if it doesn't
Thanks! I'll take a look presently…
Thanks for writing this script. I can successfully import text Markdown files with it. However, in testing this it's failing to locate relative images.
I have a directory structure on Mac
~/Desktop/test/
where the contents oftest
are a fileFavorite tweet – PizzoniGiada – June 17, 2020 at 0901AM.md
and a folderFavorite tweet – PizzoniGiada – June 17, 2020 at 0901AM
which contains a single imageimage_1.jpeg
.Running using
Python 3.8.3
and the latest version ofmd2notion
installed viapip3 install md2notion
, I am getting the following:The end result is a note created but without the image attachment.
Hope this helps.