Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #7 from stoe/use-babel
Browse files Browse the repository at this point in the history
Switch to `use babel` and ECMAScript 6
  • Loading branch information
stoe authored Dec 15, 2016
2 parents 3b2f01c + b312110 commit 51ec73d
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 256 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_modules
.DS_Store
.snyk
npm-debug.log
*.js*

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## atom-markdown-wrapper

### 5.0.0.
- Switch to `use babel` and ECMAScript 6

### 4.2.0
- Change **bold** shortcut to `cmd-b` (`ctrl-b`)

Expand Down
56 changes: 0 additions & 56 deletions lib/atom-markdown-wrapper.coffee

This file was deleted.

39 changes: 39 additions & 0 deletions lib/atom-markdown-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use babel';

const mdwrap = require('./mdwrap');
const {CompositeDisposable, Notification} = require('atom');

const cb = (fn) => {
let clipboard = atom.clipboard.read();
let editor = atom.workspace.getActiveTextEditor();
let selection = editor.getSelectedText();

try {
return this.mdwrap[fn](editor, selection, clipboard);
} catch (e) {
return atom.notifications.addError(e.message, {
dismissable: true,
detail: clipboard,
icon: 'zap'
});
}
};

module.exports = {
config: {},
activate: () => {
this.mdwrap = new mdwrap();

return this.command = atom.commands.add('atom-text-editor', {
'atom-markdown-wrapper:paste': cb.bind(this, 'paste'),
'atom-markdown-wrapper:image': cb.bind(this, 'image'),
'atom-markdown-wrapper:bold': cb.bind(this, 'bold'),
'atom-markdown-wrapper:italic': cb.bind(this, 'italic')
});
},
deactivate: () => {
this.command.dispose();

return this.mdwrap.destroy();
}
};
64 changes: 0 additions & 64 deletions lib/mdwrap.coffee

This file was deleted.

87 changes: 87 additions & 0 deletions lib/mdwrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use babel';

const {CompositeDisposable} = require('atom');
const validUrl = require('valid-url');

class mdwrap {
constructor() {
this.subscriptions = new CompositeDisposable;

this.subscriptions.add(
atom.commands.add(
'atom-workspace', {
'atom-markdown-wrapper:paste': this.paste,
'atom-markdown-wrapper:image': this.image,
'atom-markdown-wrapper:bold': this.bold,
'atom-markdown-wrapper:italic': this.italic
}
)
)
}

destroy() {
this.subscriptions.dispose();
}

paste(editor, selection, clipboard) {
let insert;

if (editor && selection && clipboard) {
insert = '[$selection]($href)'
.replace('$selection', selection)
.replace('$href', clipboard);
}

if (!validUrl.isWebUri(clipboard) && !clipboard.match(/^\#/)) {
throw new Error('Not a valid URL or #anchor');
}

editor.insertText(insert);

return insert;
}

image(editor, selection, clipboard) {
let insert;

if (editor && clipboard) {
insert = '![$selection]($href)'
.replace('$selection', selection || '')
.replace('$href', clipboard);
}

if (!validUrl.isWebUri(clipboard)) {
throw new Error('Not a valid image URL');
}

editor.insertText(insert);

return insert;
}

bold(editor, selection) {
let insert;

if (editor && selection) {
insert = '**$selection**'
.replace('$selection', selection);
}
editor.insertText(insert);

return insert;
}

italic(editor, selection) {
let insert;

if (editor && selection) {
insert = '_$selection_'
.replace('$selection', selection);
}
editor.insertText(insert);

return insert;
}
}

module.exports = mdwrap;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"valid-url": "^1.0.9"
},
"devDependencies": {
"snyk": "^1.16.0"
"snyk": "^1.21.2"
}
}
Loading

0 comments on commit 51ec73d

Please sign in to comment.