├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── keymaps └── paste-url.json ├── lib ├── index.js └── paste-url.js ├── menus └── paste-url.json ├── package.json └── styles └── paste-url.less /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.4.0 - Trim title whitespace 2 | * trim whitespace in URL title - thanks to timblair for the PR 3 | ## 1.3.0 - Fix key bindings 4 | * Fix key bindings so they show up in Plugin Settings 5 | * Customize key bindings per-platform 6 | ## 1.2.0 - Inkdrop 4.x support 7 | * Migrated code to support Inkdrop 4.x 8 | ## 1.0.1 - First Release 9 | * Fetches Title for first URL found on clipboard and pastes title and url as a markdown link 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # paste-url Inkdrop Plugin 2 | ![](https://inkdrop-plugin-badge.vercel.app/api/version/paste-url) ![](https://inkdrop-plugin-badge.vercel.app/api/downloads/paste-url) 3 | 4 | A plugin for [Inkdrop](https://www.inkdrop.info/) which adds [BoostNote](https://boostnote.io/)-style URL pasting as a markdown link. 5 | 6 | If reachable, it will fetch the webpage to parse its title and insert `[title](url)` into the Note 7 | ## Install 8 | 9 | ```sh 10 | ipm install paste-url 11 | ``` 12 | 13 | ## Usage 14 | 15 | Press (default) `CTRL + ALT + V` or select `Plugins → Paste URL` from menu. 16 | -------------------------------------------------------------------------------- /keymaps/paste-url.json: -------------------------------------------------------------------------------- 1 | { 2 | ".platform-darwin": { 3 | "cmd-alt-v": "paste-url:paste-url" 4 | }, 5 | ".platform-win32": { 6 | "ctrl-alt-v": "paste-url:paste-url" 7 | }, 8 | ".platform-linux": { 9 | "ctrl-alt-v": "paste-url:paste-url" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | activate() { 5 | this.subscription = inkdrop.commands.add(document.body, { 6 | 'paste-url:paste-url': () => require("./paste-url").pasteURL() 7 | }); 8 | }, 9 | 10 | deactivate() { 11 | this.subscription.dispose(); 12 | } 13 | } -------------------------------------------------------------------------------- /lib/paste-url.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _electron = require('electron'); 4 | 5 | module.exports = { 6 | pasteURL 7 | } 8 | 9 | function getFirstUrlFromClipboard() { 10 | // first try to read clipboard as html 11 | 12 | //var clip_text = _electron.clipboard.readHTML(); 13 | //if (clip_text.length > 0) { 14 | // const mydom = new DOMParser().parseFromString(clip_text, 'text/html') 15 | // if (mydom.getElementsByTagName('a').length > 0) { 16 | // return mydom.getElementsByTagName('a')[0].href 17 | // } 18 | //} 19 | 20 | // else use regex on text 21 | var clip_text = _electron.clipboard.readText(); 22 | if (clip_text.length > 0) { 23 | const re = /(http[s]?:\/\/[^\s"'<]*)/ 24 | var results = re.exec(clip_text) 25 | if (results.length > 0) { 26 | return results[0] 27 | } 28 | } 29 | 30 | return false 31 | } 32 | 33 | function pasteURL() { 34 | try { 35 | // parse a URL from the clipboard 36 | const url = getFirstUrlFromClipboard() 37 | if (url === false) { 38 | console.log("paste-url: Clipboard does not contain a URL") 39 | return false 40 | } 41 | 42 | // download the webpage and grab contents 43 | fetch(url).then(res=>res.text()).then(text => { 44 | console.log("paste-url fetching: "+url) 45 | var newdom = new DOMParser().parseFromString(text, 'text/html'); 46 | const title = newdom.head.getElementsByTagName('title')[0].text.trim(); 47 | 48 | // paste the URL with title into the Note 49 | const editor = global.inkdrop.getActiveEditor(); 50 | const {cm} = editor; 51 | cm.replaceSelection("["+title+"]("+url+")"); 52 | }) 53 | } catch (err) { 54 | console.log("paste-url Error: "+err.message); 55 | } 56 | return true; 57 | } 58 | -------------------------------------------------------------------------------- /menus/paste-url.json: -------------------------------------------------------------------------------- 1 | { 2 | "menu": [ 3 | { 4 | "label": "Plugins", 5 | "submenu": [ 6 | { 7 | "label": "Paste URL...", 8 | "command": "paste-url:paste-url" 9 | } 10 | ] 11 | } 12 | ], 13 | "context-menu": { 14 | ".CodeMirror": [ 15 | { 16 | "label": "Paste URL", 17 | "command": "paste-url:paste-url" 18 | } 19 | ] 20 | } 21 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "paste-url", 3 | "main": "./lib/index.js", 4 | "version": "1.4.2", 5 | "description": "BoostNote-style pasting of URLs as a markdown link", 6 | "keywords": [], 7 | "repository": "https://github.com/john-k/inkdrop-paste-url", 8 | "license": "MIT", 9 | "engines": { 10 | "inkdrop": "^4.x" 11 | }, 12 | "dependencies": {} 13 | } 14 | -------------------------------------------------------------------------------- /styles/paste-url.less: -------------------------------------------------------------------------------- 1 | .paste-url { 2 | } 3 | --------------------------------------------------------------------------------