Skip to content

Commit bbd48c6

Browse files
committed
initial v1.0.0
1 parent e496ef0 commit bbd48c6

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist/
44
*.egg-info/
55
*.pypirc
66
*.pyc
7+
*note

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
draceditor
2-
------------
1+
draceditor |pypi version|
2+
------------------------------
33

4-
.. image:: https://img.shields.io/pypi/v/draceditor.svg?style=flat-square
4+
.. |pypi version|
5+
image:: https://img.shields.io/pypi/v/draceditor.svg?style=flat-square
56
:target: https://pypi.python.org/pypi/draceditor
67
78
.. image:: https://img.shields.io/badge/license-GNUGPLv3-blue.svg?style=flat-square
@@ -16,6 +17,5 @@ draceditor
1617
.. image:: https://img.shields.io/pypi/dm/draceditor.svg?style=flat-square
1718
:target: https://pypi.python.org/pypi/draceditor
1819

19-
-------------------
2020

21-
**Django Markdown Editor** build for Dracos Linux https://dracos-linux.org *(Under Development Mode)*
21+
**DracEditor** is Django Markdown Editor build for Dracos Linux https://dracos-linux.org *(Under Development Mode)*

draceditor/static/js/draceditor.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,84 @@
114114
});
115115
};
116116

117+
/**
118+
* The state of CodeMirror at the given position.
119+
* https://github.com/lepture/editor
120+
*/
121+
var getState = function(cm, pos) {
122+
pos = pos || cm.getCursor('start');
123+
var stat = cm.getTokenAt(pos);
124+
if (!stat.type) return {};
125+
126+
var types = stat.type.split(' ');
127+
128+
var ret = {}, data, text;
129+
for (var i = 0; i < types.length; i++) {
130+
data = types[i];
131+
if (data === 'strong') {
132+
ret.bold = true;
133+
} else if (data === 'variable-2') {
134+
text = cm.getLine(pos.line);
135+
if (/^\s*\d+\.\s/.test(text)) {
136+
ret['ordered-list'] = true;
137+
} else {
138+
ret['unordered-list'] = true;
139+
}
140+
} else if (data === 'atom') {
141+
ret.quote = true;
142+
} else if (data === 'em') {
143+
ret.italic = true;
144+
}
145+
}
146+
return ret;
147+
}
148+
149+
var replaceSelection = function(cm, active, start, end) {
150+
var text;
151+
var startPoint = cm.getCursor('start');
152+
var endPoint = cm.getCursor('end');
153+
if (active) {
154+
text = cm.getLine(startPoint.line);
155+
start = text.slice(0, startPoint.ch);
156+
end = text.slice(startPoint.ch);
157+
cm.setLine(startPoint.line, start + end);
158+
} else {
159+
text = cm.getSelection();
160+
cm.replaceSelection(start + text + end);
161+
162+
startPoint.ch += start.length;
163+
endPoint.ch += start.length;
164+
}
165+
cm.setSelection(startPoint, endPoint);
166+
cm.focus();
167+
}
168+
117169
var onKeyUpEvent = function(e) {
118170
console.log(e);
119171
onMention();
120172
onEmoji();
121173
}
122174

175+
var timeout;
176+
var update = function(e) {
177+
console.log(e);
178+
onMention();
179+
console.log(e.getValue());
180+
//clearTimeout(timeout);
181+
//timeout = setTimeout(getMarkdown, 1000);
182+
};
183+
184+
var editor;
185+
setTimeout(function(){
186+
//$('.CodeMirror').attr({'contentEditable': 'true'});
187+
editor = $('.CodeMirror')[0].CodeMirror;
188+
editor.on('change', update);
189+
editor.on('keyup', function(cm, e) {
190+
console.log(cm, e);
191+
onMention();
192+
});
193+
}, 500);
194+
123195
var draceditor = $(this);
124196
var dracEditor = $(this).find('.draceditor');
125197
dracEditor.on('keydown.draceditor', onKeyUpEvent);

0 commit comments

Comments
 (0)