Homepage    |    GitHub    |    API    |    FAQ

Need help to create Joplin plugin to read markdown file inside zip

I am trying to create a joplin plugin to read a zip file from the user system and upload a specific makrdown file inside it (say data.md). I see that plugin looks like a node module but I am still able to use node packages like adm-zip (GitHub - cthackers/adm-zip: A Javascript implementation of zip for nodejs. Allows user to create or extract zip files both in memory or to/from disk).

Also, I want to know whether I would be able to use something like "fs.readFile" to read the content of .md file from a path and add it as a note in joplin.

Below is the sample code I have written to see if I can unzip a file and import .md file in the zip.

	onStart: async function() {

		await joplin.interop.registerImportModule({
			description: 'Import enhan(t) zip',
			format: 'md',
			sources: [FileSystemItem.File],
			isNoteArchive: false,
			outputFormat: ImportModuleOutputFormat.Markdown,
			onExec: async (context:any) => {
				// In this case importing is a lot more complicated due to the need to avoid
				// duplicate IDs, to validate data and ensure note links and 
				// resources are still working properly.
				// See InteropService_Importer_Raw for an example.
				console.log('Not implemented! Importing from:', context);

The joplin documentation says that the imported file and context will be present inside onExec, but for me the function is never called. The joplin app gives a message "An object could not be cloned", and exits.

Yes, you access fs using joplin.plugin.require

I am using adm-zip module to extract the zip file. Apparently, adm-zip is dependent on "fs" module and internally checks for it. This raises error : Module not found: Error: Can't resolve 'fs'.

So how to use packages which are dependent on "fs" ?

Something like this worked for me:
add to your webpack config in createArchiveConfig

	node: {
		fs: "empty",

Thanks... that worked.

This leaves me with one last issue :

I am creating a custom import which can import all markdown files inside zip. When I add the zip file - I get " An object could not be cloned " , and the onExec event never fires.

I have added the code in the thread for reference.

Where is this error coming from? I'm not too familiar with the import API.