Skip to content

Latest commit

 

History

History
82 lines (64 loc) · 9.66 KB

API.md

File metadata and controls

82 lines (64 loc) · 9.66 KB

NOTE: You can ommit function's parentheses if the argument is only a string or table

local clip_img = require('clipboard-image')
clip_img.setup({img_dir = 'assets'})

-- Is the same as
local clip_img = require 'clipboard-image'
clip_img.setup {img_dir = 'assets'}

How to call these function:

require 'clipboard-image.<module>'.<function>()

Example:

-- Paste image
require 'clipboard-image.paste'.paste_img()

Modules

Init

For this module, it's fine if you don't specify the module's name.

-- These will produce the same result
require 'clipboard-image'.setup()
require 'clipboard-image.init'.setup()
Function Parameter Return Description
setup config: config Set your configuration up

Config

Function Parameter Return Description
get_config config: config Get raw config
merge_config old_opts: table
new_opts: table
config: table
get_usable_config usable_config: img_opts Original config isn't ready to use because it contains config for various filetypes.
Default config for all filetype and config for current filetype need to be merged to be usable before pasting image.
load_config config_toload: img_opts loaded_config: table Config field which value is function needs to be loaded first.
{ img_name = function () return os.date('%Y-%m-%d-%H-%M-%S') end }
to { img_name = "2021-08-21-16-14-17" }

Config Structure

Field Type Description
default img_opts The default value of img_opts for all filetype
<file-type> img_opts Value of img_opts for specific filetype.
Run :set filetype? to get filetype name.

Image Options

Field Type Default Value Description
img_name string, function function () return os.date('%Y-%m-%d-%H-%M-%S') end
Example result: "2021-08-21-16-14-17"
Image's name
img_dir string, function "img" Directory to save the image
img_dir_txt string, function "img" Directory on the text/buffer.
Example: Your actual dir is src/assets/img but your dir on text or buffer is /assets/img
img_handler function function(img) end Function that will handle image after pasted.
img is a table that contain image's name and path
affix string, function default: "%s"
markdown: "![](%s)"
asciidoc: "image::%s[]"
String that sandwiched the image's path

Paste

Function Parameter Return Description
paste_img opts?: img_opts Paste name

Utils

Function Parameter Return Description
get_os os_name: string
Windows, Linux, Darwin, etc
Reference https://vi.stackexchange.com/a/2577/33116
get_clip_command cmd_check: string
cmd_paste: string
Get command to check and paste clipboard content
get_clip_content command: string
command to check clip_content
usable_config: table Will be used in utils.is_clipboard_img to check if image data exist
is_clipboard_img content: string
clipboard-content
loaded_config: table Check if clipboard contain image data
See also: Data URI scheme
resolve_dir dir: string | table
path_separator: string
full_path: string Resolve any complicated pathing
create_dir dir: string dir path Create directory
get_img_path dir: string
img_name: string
is_txt?: "txt"
Wether img_path will be used as inserted text or to copy image because Windows has different path separator
img_path: string Get image's path
NOTE: Probably will replace is_text with path_separator
insert_txt
insert_text
affix: string
path_txt: string
Insert image's path with affix