robinchenyu / imagepaste

MIT License
25 stars 14 forks source link

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

Open Janus-Xu opened 6 years ago

Janus-Xu commented 6 years ago

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

lindexi commented 6 years ago

Thx