Added support of code block languages autocomplete for charts

This commit is contained in:
Wu Cheng-Han 2016-01-19 10:01:40 -06:00
parent 0dbde6d3d0
commit 75548df29e

View file

@ -26,6 +26,7 @@ var updateViewDebounce = 200;
var cursorActivityDebounce = 50; var cursorActivityDebounce = 50;
var cursorAnimatePeriod = 100; var cursorAnimatePeriod = 100;
var supportCodeModes = ['javascript', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'coffeescript', 'yaml', 'jade', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile']; var supportCodeModes = ['javascript', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'coffeescript', 'yaml', 'jade', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile'];
var supportCharts = ['sequence-diagram', 'flow-chart', 'graphviz'];
var supportHeaders = [ var supportHeaders = [
{ {
text: '# h1', text: '# h1',
@ -2230,15 +2231,26 @@ $(editor.getInputField())
}, },
{ // Code block language strategy { // Code block language strategy
langs: supportCodeModes, langs: supportCodeModes,
charts: supportCharts,
match: /(^|\n)```(\w+)$/, match: /(^|\n)```(\w+)$/,
search: function (term, callback) { search: function (term, callback) {
callback($.map(this.langs, function (lang) { var list = [];
return lang.indexOf(term) === 0 ? lang : null; $.map(this.langs, function (lang) {
})); if (lang.indexOf(term) === 0)
list.push(lang);
});
$.map(this.charts, function (chart) {
if (chart.indexOf(term) === 0)
list.push(chart);
});
checkCursorMenu(); checkCursorMenu();
callback(list);
}, },
replace: function (lang) { replace: function (lang) {
if (this.langs.indexOf(lang) !== -1)
return '$1```' + lang + '=\n\n```'; return '$1```' + lang + '=\n\n```';
else if (this.charts.indexOf(lang) !== -1)
return '$1```' + lang + '\n\n```';
}, },
done: function () { done: function () {
editor.doc.cm.execCommand("goLineUp"); editor.doc.cm.execCommand("goLineUp");