Show More
@@ -143,6 +143,14 b' class BoldPattern(TextFormatter):' | |||||
143 | format_right = '__' |
|
143 | format_right = '__' | |
144 |
|
144 | |||
145 |
|
145 | |||
|
146 | class CodePattern(TextFormatter): | |||
|
147 | name = 'code' | |||
|
148 | preview_left = '<code>' | |||
|
149 | preview_right = '</code>' | |||
|
150 | ||||
|
151 | format_left = ' ' | |||
|
152 | ||||
|
153 | ||||
146 | class NeboardMarkdown(markdown.Extension): |
|
154 | class NeboardMarkdown(markdown.Extension): | |
147 | def extendMarkdown(self, md, md_globals): |
|
155 | def extendMarkdown(self, md, md_globals): | |
148 | self._add_neboard_patterns(md) |
|
156 | self._add_neboard_patterns(md) | |
@@ -186,4 +194,5 b' formatters = [' | |||||
186 | BoldPattern, |
|
194 | BoldPattern, | |
187 | CommentPattern, |
|
195 | CommentPattern, | |
188 | StrikeThroughPattern, |
|
196 | StrikeThroughPattern, | |
|
197 | CodePattern, | |||
189 | ] |
|
198 | ] |
@@ -23,7 +23,17 b'' | |||||
23 | for the JavaScript code in this page. |
|
23 | for the JavaScript code in this page. | |
24 | */ |
|
24 | */ | |
25 |
|
25 | |||
|
26 | /** | |||
|
27 | * Add the desired characters to the start and end of selection. | |||
|
28 | * @param start Start (left) text | |||
|
29 | * @param end End (right) text | |||
|
30 | * @returns {boolean} | |||
|
31 | */ | |||
26 | function addMarkToMsg(start, end) { |
|
32 | function addMarkToMsg(start, end) { | |
|
33 | if (end.length == 0) { | |||
|
34 | return addTextToEachLineOfSelection(start); | |||
|
35 | } | |||
|
36 | ||||
27 | var textarea = document.getElementsByTagName('textarea')[0]; |
|
37 | var textarea = document.getElementsByTagName('textarea')[0]; | |
28 | if(!textarea) return; |
|
38 | if(!textarea) return; | |
29 | if( document.selection ) { |
|
39 | if( document.selection ) { | |
@@ -39,4 +49,68 b' function addMarkToMsg(start, end) {' | |||||
39 | textarea.value += start + end; |
|
49 | textarea.value += start + end; | |
40 | } |
|
50 | } | |
41 | return false; |
|
51 | return false; | |
|
52 | } | |||
|
53 | ||||
|
54 | /** | |||
|
55 | * Add text to the beginning of each selected line. Partially selected lines | |||
|
56 | * are included | |||
|
57 | * @param textToAdd | |||
|
58 | * @returns {*} | |||
|
59 | */ | |||
|
60 | function addTextToEachLineOfSelection(textToAdd) { | |||
|
61 | var editor, end, newValue, start, value, _ref, _ref1; | |||
|
62 | editor = document.getElementsByTagName('textarea')[0]; | |||
|
63 | _ref = [editor.selectionStart, editor.selectionEnd], start = _ref[0], end = _ref[1]; | |||
|
64 | if (start == null) { | |||
|
65 | return; | |||
|
66 | } | |||
|
67 | if (start === end) { | |||
|
68 | return; | |||
|
69 | } | |||
|
70 | console.log("Selection range: start=" + start + " end=" + end); | |||
|
71 | value = editor.value; | |||
|
72 | _ref1 = getLinesRange(start, end, value), start = _ref1[0], end = _ref1[1]; | |||
|
73 | newValue = replaceLines(start, end, value, textToAdd); | |||
|
74 | return editor.value = newValue; | |||
|
75 | } | |||
|
76 | ||||
|
77 | function replaceLines(start, end, value, textToAdd) { | |||
|
78 | var line, replacedText, text; | |||
|
79 | text = value.slice(start, end); | |||
|
80 | replacedText = ((function() { | |||
|
81 | var _i, _len, _ref, _results; | |||
|
82 | _ref = text.split("\n"); | |||
|
83 | _results = []; | |||
|
84 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |||
|
85 | line = _ref[_i]; | |||
|
86 | _results.push(textToAdd + line); | |||
|
87 | } | |||
|
88 | return _results; | |||
|
89 | })()).join("\n"); | |||
|
90 | return replaceSubstring(start, end, value, replacedText); | |||
|
91 | } | |||
|
92 | ||||
|
93 | function replaceSubstring(start, end, string, replacingString) { | |||
|
94 | return string.slice(0, start) + replacingString + string.slice(end); | |||
|
95 | } | |||
|
96 | ||||
|
97 | function getLinesRange(start, end, value) { | |||
|
98 | var i, rangeEnd, rangeStart, _i, _j, _ref, _ref1; | |||
|
99 | if (value[start] === "\n") { | |||
|
100 | start = start - 1; | |||
|
101 | } | |||
|
102 | _ref = [start, end], rangeStart = _ref[0], rangeEnd = _ref[1]; | |||
|
103 | for (i = _i = start; start <= 0 ? _i <= 0 : _i >= 0; i = start <= 0 ? ++_i : --_i) { | |||
|
104 | if (value[i] === "\n") { | |||
|
105 | break; | |||
|
106 | } | |||
|
107 | rangeStart = i; | |||
|
108 | } | |||
|
109 | for (i = _j = end, _ref1 = value.length; end <= _ref1 ? _j < _ref1 : _j > _ref1; i = end <= _ref1 ? ++_j : --_j) { | |||
|
110 | if (value[i] === "\n") { | |||
|
111 | break; | |||
|
112 | } | |||
|
113 | rangeEnd = i; | |||
|
114 | } | |||
|
115 | return [rangeStart, rangeEnd]; | |||
42 | } No newline at end of file |
|
116 | } |
General Comments 0
You need to be logged in to leave comments.
Login now