imagepaste icon indicating copy to clipboard operation
imagepaste copied to clipboard

paste all images into 'assets' dir As gitbook-editor

Open Janus-Xu opened this issue 8 years ago • 1 comments

I want to use this plugin as gitbook-editor : all images in dir assets, just as below:

open ImagePaste.py,change def get_filename(self) block

def get_filename(self):
	view = self.view
	filename = view.file_name()

	# create dir in current path with the name of current filename
	dirname, _ = os.path.splitext(filename)

	# create new image file under currentdir/filename_without_ext/filename_without_ext%d.png
	fn_without_ext = os.path.basename(dirname)
	gitbook_dir = os.path.split(dirname)[0]+'\\assets'
	if not os.path.lexists(gitbook_dir):
		os.mkdir(gitbook_dir)
	i = 0
	while True:
		# relative file path
		rel_filename = os.path.join("%s/%s%d.png" % ("assets", fn_without_ext, i))
		# absolute file path
		abs_filename = os.path.join(gitbook_dir, "%s%d.png" % ( fn_without_ext, i))
		if not os.path.exists(abs_filename):
			break
		i += 1

	print("save file: " + abs_filename + "\nrel " + rel_filename)
	return abs_filename, rel_filename

tim 20180409163056

Janus-Xu avatar Apr 09 '18 08:04 Janus-Xu

Thx

lindexi avatar May 22 '18 06:05 lindexi