Skip to content

Commit daf71aa

Browse files
committed
add mentions from @clockwork-it/simplemde-markdown-editor-mention
1 parent 32599af commit daf71aa

File tree

7 files changed

+96
-21
lines changed

7 files changed

+96
-21
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
localtesting/
22
node_modules/
33
bower_components/
4+
debug/
45

56
#For IDE
67
*.iml

‎bower.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "simplemde",
33
"version": "1.11.2",
4-
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
4+
"homepage": "https://github.com/clockwork-it/simplemde-markdown-editor-mention",
55
"authors": [
6-
"Wes Cossick <https://wescossick.com>"
6+
"Wes Cossick <https://wescossick.com>",
7+
"Andreas Eckersperger <[email protected]>"
78
],
8-
"description": "A simple, beautiful, and embeddable JavaScript Markdown editor.",
9+
"description": "A simple, beautiful, and embeddable JavaScript Markdown editor with mention support.",
910
"main": ["src/js/simplemde.js", "src/css/simplemde.css"],
1011
"keywords": [
1112
"embeddable",

‎dist/simplemde.min.css‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/simplemde.min.js‎

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"name": "simplemde",
33
"version": "1.11.2",
4-
"description": "A simple, beautiful, and embeddable JavaScript Markdown editor. Features autosavingand spell checking.",
4+
"description": "A simple, beautiful, and embeddable JavaScript Markdown editor. Features autosaving, mention support and spell checking. Based on https://github.com/sparksuite/simplemde-markdown-editor.",
55
"keywords": [
66
"embeddable",
77
"markdown",
88
"editor",
99
"javascript",
1010
"wysiwyg"
1111
],
12-
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
12+
"homepage": "https://github.com/clockwork-it/simplemde-markdown-editor-mention",
1313
"main": "./src/js/simplemde.js",
1414
"license": "MIT",
15-
"company": "Next Step Webs, Inc.",
15+
"company": "Clockwork IT GmbH",
1616
"author":{
17-
"name": "Wes Cossick",
18-
"url": "http://www.WesCossick.com"
17+
"name": "Andreas Eckersperger",
18+
"url": "https://www.clockwork-it.de"
1919
},
2020
"bugs":{
21-
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor/issues"
21+
"url": "https://github.com/clockwork-it/simplemde-markdown-editor-mention/issues"
2222
},
2323
"dependencies":{
2424
"codemirror": "*",
@@ -43,6 +43,6 @@
4343
},
4444
"repository":{
4545
"type": "git",
46-
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor"
46+
"url": "https://github.com/clockwork-it/simplemde-markdown-editor-mention"
4747
}
4848
}

‎src/css/simplemde.css‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,35 @@
325325

326326
.CodeMirror .CodeMirror-placeholder{
327327
opacity:.5;
328+
}
329+
330+
.CodeMirror-hints{
331+
position: absolute;
332+
z-index:2147483647;
333+
overflow: hidden;
334+
list-style: none;
335+
margin:0;
336+
padding:2px;
337+
-webkit-box-shadow:2px3px5pxrgba(0,0,0,.2);
338+
-moz-box-shadow:2px3px5pxrgba(0,0,0,.2);
339+
box-shadow:2px3px5pxrgba(0,0,0,.2);
340+
border-radius:3px;
341+
border:1px solid silver;
342+
background: white;
343+
max-height:20em;
344+
overflow-y: auto;
345+
}
346+
347+
.CodeMirror-hint{
348+
margin:0;
349+
padding:04px;
350+
border-radius:2px;
351+
white-space: pre;
352+
color: black;
353+
cursor: pointer;
354+
}
355+
356+
li.CodeMirror-hint-active{
357+
background:#08f;
358+
color: white;
328359
}

‎src/js/simplemde.js‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,62 @@ require("./codemirror/tablist");
66
require("codemirror/addon/display/fullscreen.js");
77
require("codemirror/mode/markdown/markdown.js");
88
require("codemirror/addon/mode/overlay.js");
9+
require("codemirror/addon/hint/show-hint.js");
910
require("codemirror/addon/display/placeholder.js");
1011
require("codemirror/addon/selection/mark-selection.js");
1112
require("codemirror/mode/gfm/gfm.js");
1213
require("codemirror/mode/xml/xml.js");
1314
varCodeMirrorSpellChecker=require("codemirror-spell-checker");
1415
varmarked=require("marked");
1516

17+
varcurrentEditorHelperHint;
18+
19+
CodeMirror.defineOption("autoSuggest",[],function(cm,autoSuggestOptions,old){
20+
cm.on("inputRead",function(cm,change){
21+
varmode=cm.getModeAt(cm.getCursor());
22+
23+
if(mode.name===autoSuggestOptions.mode&&autoSuggestOptions.startChars.indexOf(change.text[0])!=-1){
24+
25+
currentEditorHelperHint=autoSuggestOptions;
26+
currentEditorHelperHint.startChar=change.text[0];
27+
28+
cm.showHint({
29+
completeSingle: false,
30+
closeCharacters: /[\v()\[\]{};:>,]/,
31+
hint: function(cm,options){
32+
varcur=cm.getCursor(),
33+
token=cm.getTokenAt(cur);
34+
varstart=token.start+1,
35+
end=token.end;
36+
37+
varline=cm.getCursor().line,
38+
ch=cm.getCursor().ch,
39+
stringToMatch=currentEditorHelperHint.startChar,
40+
n=stringToMatch.length,
41+
lineToStarChar=cm.getLine(line).substring(0,token.start+1),
42+
charBeforeStarChar=lineToStarChar.substring(cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar)-1,cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar)),
43+
stringToTest=lineToStarChar.substring(cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar),token.start+1);
44+
45+
if(charBeforeStarChar!=' '&&charBeforeStarChar!=''){
46+
returnfalse;
47+
}
48+
49+
varlistCallback=currentEditorHelperHint.listCallback(stringToTest);
50+
51+
if(listCallback.length==0){
52+
returnfalse;
53+
}
54+
55+
return{
56+
list: listCallback,
57+
from: CodeMirror.Pos(cur.line,cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar)),
58+
to: CodeMirror.Pos(cur.line,end)
59+
};
60+
}
61+
});
62+
}
63+
});
64+
});
1665

1766
// Some variables
1867
varisMac=/Mac/.test(navigator.platform);
@@ -1498,7 +1547,8 @@ SimpleMDE.prototype.render = function(el){
14981547
lineWrapping: (options.lineWrapping===false) ? false : true,
14991548
allowDropFileTypes: ["text/plain"],
15001549
placeholder: options.placeholder||el.getAttribute("placeholder")||"",
1501-
styleSelectedText: (options.styleSelectedText!=undefined) ? options.styleSelectedText : true
1550+
styleSelectedText: (options.styleSelectedText!=undefined) ? options.styleSelectedText : true,
1551+
autoSuggest: (options.autoSuggest!=undefined) ? options.autoSuggest : NULL
15021552
});
15031553

15041554
if(options.forceSync===true){

0 commit comments

Comments
(0)