|
2 | 2 |
|
3 | 3 | /*global $, window, CodeMirror, Showdown, moment */ |
4 | 4 | (function () { |
5 | | - "use strict"; |
| 5 | + 'use strict'; |
6 | 6 | var Markdown = { |
7 | 7 | init : function (options, elem) { |
8 | 8 | var self = this; |
|
17 | 17 | replace: function () { |
18 | 18 | var text = this.elem.getSelection(), pass = true, md, cursor, line, word, letterCount, converter; |
19 | 19 | switch (this.style) { |
20 | | - case "h1": |
| 20 | + case 'h1': |
21 | 21 | cursor = this.elem.getCursor(); |
22 | 22 | line = this.elem.getLine(cursor.line); |
23 | | - this.elem.setLine(cursor.line, "# " + line); |
| 23 | + this.elem.setLine(cursor.line, '# ' + line); |
24 | 24 | this.elem.setCursor(cursor.line, cursor.ch + 2); |
25 | 25 | pass = false; |
26 | 26 | break; |
27 | | - case "h2": |
| 27 | + case 'h2': |
28 | 28 | cursor = this.elem.getCursor(); |
29 | 29 | line = this.elem.getLine(cursor.line); |
30 | | - this.elem.setLine(cursor.line, "## " + line); |
| 30 | + this.elem.setLine(cursor.line, '## ' + line); |
31 | 31 | this.elem.setCursor(cursor.line, cursor.ch + 3); |
32 | 32 | pass = false; |
33 | 33 | break; |
34 | | - case "h3": |
| 34 | + case 'h3': |
35 | 35 | cursor = this.elem.getCursor(); |
36 | 36 | line = this.elem.getLine(cursor.line); |
37 | | - this.elem.setLine(cursor.line, "### " + line); |
| 37 | + this.elem.setLine(cursor.line, '### ' + line); |
38 | 38 | this.elem.setCursor(cursor.line, cursor.ch + 4); |
39 | 39 | pass = false; |
40 | 40 | break; |
41 | | - case "h4": |
| 41 | + case 'h4': |
42 | 42 | cursor = this.elem.getCursor(); |
43 | 43 | line = this.elem.getLine(cursor.line); |
44 | | - this.elem.setLine(cursor.line, "#### " + line); |
| 44 | + this.elem.setLine(cursor.line, '#### ' + line); |
45 | 45 | this.elem.setCursor(cursor.line, cursor.ch + 5); |
46 | 46 | pass = false; |
47 | 47 | break; |
48 | | - case "h5": |
| 48 | + case 'h5': |
49 | 49 | cursor = this.elem.getCursor(); |
50 | 50 | line = this.elem.getLine(cursor.line); |
51 | | - this.elem.setLine(cursor.line, "##### " + line); |
| 51 | + this.elem.setLine(cursor.line, '##### ' + line); |
52 | 52 | this.elem.setCursor(cursor.line, cursor.ch + 6); |
53 | 53 | pass = false; |
54 | 54 | break; |
55 | | - case "h6": |
| 55 | + case 'h6': |
56 | 56 | cursor = this.elem.getCursor(); |
57 | 57 | line = this.elem.getLine(cursor.line); |
58 | | - this.elem.setLine(cursor.line, "###### " + line); |
| 58 | + this.elem.setLine(cursor.line, '###### ' + line); |
59 | 59 | this.elem.setCursor(cursor.line, cursor.ch + 7); |
60 | 60 | pass = false; |
61 | 61 | break; |
62 | | - case "link": |
| 62 | + case 'link': |
63 | 63 | md = this.options.syntax.link.replace('$1', text); |
64 | | - this.elem.replaceSelection(md, "end"); |
| 64 | + this.elem.replaceSelection(md, 'end'); |
65 | 65 | cursor = this.elem.getCursor(); |
66 | 66 | this.elem.setSelection({line: cursor.line, ch: cursor.ch - 8}, {line: cursor.line, ch: cursor.ch - 1}); |
67 | 67 | pass = false; |
68 | 68 | break; |
69 | | - case "image": |
| 69 | + case 'image': |
70 | 70 | cursor = this.elem.getCursor(); |
71 | 71 | md = this.options.syntax.image.replace('$1', text); |
72 | | - if (this.elem.getLine(cursor.line) !== "") { |
| 72 | + if (this.elem.getLine(cursor.line) !== '') { |
73 | 73 | md = "\n\n" + md; |
74 | 74 | } |
75 | 75 | this.elem.replaceSelection(md, "end"); |
76 | 76 | cursor = this.elem.getCursor(); |
77 | 77 | this.elem.setSelection({line: cursor.line, ch: cursor.ch - 8}, {line: cursor.line, ch: cursor.ch - 1}); |
78 | 78 | pass = false; |
79 | 79 | break; |
80 | | - case "uppercase": |
| 80 | + case 'uppercase': |
81 | 81 | md = text.toLocaleUpperCase(); |
82 | 82 | break; |
83 | | - case "lowercase": |
| 83 | + case 'lowercase': |
84 | 84 | md = text.toLocaleLowerCase(); |
85 | 85 | break; |
86 | | - case "titlecase": |
| 86 | + case 'titlecase': |
87 | 87 | md = text.toTitleCase(); |
88 | 88 | break; |
89 | | - case "selectword": |
| 89 | + case 'selectword': |
90 | 90 | cursor = this.elem.getCursor(); |
91 | 91 | word = this.elem.getTokenAt(cursor); |
92 | 92 | if (!/\w$/g.test(word.string)) { |
|
95 | 95 | this.elem.setSelection({line: cursor.line, ch: word.start}, {line: cursor.line, ch: word.end}); |
96 | 96 | } |
97 | 97 | break; |
98 | | - case "copyHTML": |
| 98 | + case 'copyHTML': |
99 | 99 | converter = new Showdown.converter(); |
100 | 100 | if (text) { |
101 | 101 | md = converter.makeHtml(text); |
|
106 | 106 | $(".modal-copyToHTML-content").text(md).selectText(); |
107 | 107 | pass = false; |
108 | 108 | break; |
109 | | - case "list": |
110 | | - md = text.replace(/^(\s*)(\w\W*)/gm, "$1* $2"); |
111 | | - this.elem.replaceSelection(md, "end"); |
| 109 | + case 'list': |
| 110 | + md = text.replace(/^(\s*)(\w\W*)/gm, '$1* $2'); |
| 111 | + this.elem.replaceSelection(md, 'end'); |
112 | 112 | pass = false; |
113 | 113 | break; |
114 | | - case "currentDate": |
115 | | - md = moment(new Date()).format("D MMMM YYYY"); |
| 114 | + case 'currentDate': |
| 115 | + md = moment(new Date()).format('D MMMM YYYY'); |
| 116 | + this.elem.replaceSelection(md, 'end'); |
| 117 | + pass = false; |
116 | 118 | break; |
117 | 119 | default: |
118 | 120 | if (this.options.syntax[this.style]) { |
119 | 121 | md = this.options.syntax[this.style].replace('$1', text); |
120 | 122 | } |
121 | 123 | } |
122 | 124 | if (pass && md) { |
123 | | - this.elem.replaceSelection(md, "end"); |
| 125 | + this.elem.replaceSelection(md, 'end'); |
124 | 126 | if (!text) { |
125 | 127 | letterCount = md.length; |
126 | 128 | cursor = this.elem.getCursor(); |
|
0 commit comments