├── .gitignore ├── CHANGELOG.md ├── assets ├── README-31bb2.png └── README-d1eba.png ├── package.json ├── LICENSE.md ├── README.md └── lib └── main.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.1 - First Release 2 | * Original feature added 3 | -------------------------------------------------------------------------------- /assets/README-31bb2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigyuki/markdown-image-helper/HEAD/assets/README-31bb2.png -------------------------------------------------------------------------------- /assets/README-d1eba.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigyuki/markdown-image-helper/HEAD/assets/README-d1eba.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markdown-image-helper", 3 | "main": "./lib/main", 4 | "version": "1.0.4", 5 | "description": "When paste image to markdown ,this will make a directory name \"assets\" and will paste the image as a png file in this image ,then will insert a relative image url", 6 | "keywords": [ 7 | "markdown", 8 | "image", 9 | "clipboard", 10 | "paste", 11 | "copy" 12 | ], 13 | "repository": "https://github.com/bigyuki/markdown-image-helper", 14 | "license": "MIT", 15 | "engines": { 16 | "atom": ">=1.0.0 <2.0.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 bigyuki 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 | # Markdown Image Helper 2 | 3 | **Warning: I choose Emacs to write markdown , so this plugin is not maintain anymore** 4 | 5 | An Atom plugin for Markdown grammar. Create image file relative to the markdown file and insert a relative url to that file. 6 | 7 | Inspired by [markdown-assistant](https://github.com/knightli/markdown-assistant),instead upload the image, i think just copy to the relative path is better. 8 | 9 | ## Usage 10 | 1. Take a screenshot or copy any image to the clipboard. 11 | 2. Paste it into Atom markdown editor 12 | 3. See that an directory name "assets" was create, and the directory has a png file, and a url was inserted. 13 | 14 | ## Example 15 | * Before 16 | 17 | ![before](https://github.com/bigyuki/markdown-image-helper/raw/master/assets/README-31bb2.png) 18 | 19 | * After 20 | 21 | ![after](https://github.com/bigyuki/markdown-image-helper/raw/master/assets/README-d1eba.png) 22 | 23 | # Q&A 24 | - Does this plugin support on Windows system ? 25 | 26 | According to the issue [#2](https://github.com/bigyuki/markdown-image-helper/issues/2), thanks to @[hgaronfolo](https://github.com/hgaronfolo) he said that 27 | 28 | For markdown-image-helper to work, the language needs to be "Git Markdown", so on Windows Atom, I went in to settings, packages and searched for "language-gfm" (core package). 29 | This package was disabled by default in Windows Atom, but enabled by default in Linux Atom. 30 | 31 | I enabled "language-gfm", and now I can choose "Github Markdown" in Windows Atom and markdown-image-helper now works! :-) 32 | 33 | so you should enable `language-gfm`, maybe i will work, if not please let me know. 34 | 35 | ## Other 36 | If you are using [Hexo](https://github.com/hexojs/hexo) to writer blog or wiki , i think this small plugin [`hexo-generator-assets`](https://github.com/bigyuki/hexo-generator-assets) is helpful with `markdown-image-helper` 37 | -------------------------------------------------------------------------------- /lib/main.coffee: -------------------------------------------------------------------------------- 1 | 2 | {CompositeDisposable,File,Directory} = require 'atom' 3 | 4 | module.exports = MarkdownImgHelper = 5 | 6 | activate: (state) -> 7 | atom.commands.onWillDispatch (e) => 8 | if e.type is "core:paste" 9 | 10 | editor = atom.workspace.getActiveTextEditor() 11 | return unless editor 12 | grammar = editor.getGrammar() 13 | return unless grammar 14 | return unless grammar.scopeName is 'source.gfm' 15 | 16 | 17 | clipboard = require 'clipboard' 18 | img = clipboard.readImage() 19 | 20 | return if img.isEmpty() 21 | 22 | e.stopImmediatePropagation() 23 | 24 | imgbuffer = img.toPng() 25 | 26 | thefile = new File(editor.getPath()) 27 | assetsDirPath = thefile.getParent().getPath()+"/assets" 28 | 29 | 30 | crypto = require "crypto" 31 | md5 = crypto.createHash 'md5' 32 | md5.update(imgbuffer) 33 | 34 | filename = "#{thefile.getBaseName().replace(/\.\w+$/, '').replace(/\s+/g,'')}-#{md5.digest('hex').slice(0,5)}.png" 35 | 36 | @createDirectory assetsDirPath, ()=> 37 | @writePng assetsDirPath+'/', filename, imgbuffer, ()=> 38 | # ascClip = "assets/#{filename}" 39 | # clipboard.writeText(ascClip) 40 | 41 | @insertUrl "assets/#{filename}",editor 42 | 43 | return false 44 | 45 | createDirectory: (dirPath, callback)-> 46 | assetsDir = new Directory(dirPath) 47 | 48 | assetsDir.exists().then (existed) => 49 | if not existed 50 | assetsDir.create().then (created) => 51 | if created 52 | console.log 'Success Create dir' 53 | callback() 54 | else 55 | callback() 56 | 57 | writePng: (assetsDir, filename, buffer, callback)-> 58 | fs = require('fs') 59 | fs.writeFile assetsDir+filename, buffer, 'binary',() => 60 | console.log('finish clip image') 61 | callback() 62 | 63 | insertUrl: (url,editor) -> 64 | editor.insertText(url) 65 | 66 | 67 | deactivate: -> 68 | 69 | 70 | serialize: -> 71 | --------------------------------------------------------------------------------