mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-07-23 09:54:28 -06:00
Gulp now pretty formats JS and CSS
This commit is contained in:
parent
b43b99e50d
commit
8218391cfd
16
gulpfile.js
16
gulpfile.js
@ -4,7 +4,7 @@ var gulp = require('gulp'),
|
|||||||
concat = require('gulp-concat'),
|
concat = require('gulp-concat'),
|
||||||
header = require('gulp-header'),
|
header = require('gulp-header'),
|
||||||
pkg = require('./package.json'),
|
pkg = require('./package.json'),
|
||||||
beautify = require('gulp-beautify');
|
prettify = require('gulp-jsbeautifier');
|
||||||
|
|
||||||
var banner = ['/**',
|
var banner = ['/**',
|
||||||
' * <%= pkg.name %> v<%= pkg.version %>',
|
' * <%= pkg.name %> v<%= pkg.version %>',
|
||||||
@ -46,10 +46,16 @@ gulp.task('styles', function() {
|
|||||||
.pipe(gulp.dest('dist'));
|
.pipe(gulp.dest('dist'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('beautify', function() {
|
gulp.task('prettify-js', function() {
|
||||||
gulp.src('./src/js/simplemde.js')
|
gulp.src('./src/js/simplemde.js')
|
||||||
.pipe(beautify({indentSize: 4}))
|
.pipe(prettify({js: {braceStyle: "collapse", indentChar: "\t", indentSize: 1, maxPreserveNewlines: 3, spaceBeforeConditional: false}}))
|
||||||
.pipe(gulp.dest('./src/js/test'))
|
.pipe(gulp.dest('./src/js'));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('prettify-css', function() {
|
||||||
|
gulp.src('./src/css/simplemde.css')
|
||||||
|
.pipe(prettify({css: {indentChar: "\t", indentSize: 1}}))
|
||||||
|
.pipe(gulp.dest('./src/css'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('default', ['scripts', 'styles', 'beautify']);
|
gulp.task('default', ['scripts', 'styles', 'prettify-js', 'prettify-css']);
|
@ -20,7 +20,7 @@
|
|||||||
"gulp-uglify": "*",
|
"gulp-uglify": "*",
|
||||||
"gulp-concat": "*",
|
"gulp-concat": "*",
|
||||||
"gulp-header": "*",
|
"gulp-header": "*",
|
||||||
"gulp-beautify": "*"
|
"gulp-jsbeautifier": "*"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.CodeMirror-fullscreen {
|
.CodeMirror-fullscreen {
|
||||||
background:#fff;
|
background: #fff;
|
||||||
position: fixed !important;
|
position: fixed !important;
|
||||||
top: 50px;
|
top: 50px;
|
||||||
left: 0;
|
left: 0;
|
||||||
@ -43,7 +43,8 @@
|
|||||||
border-top-right-radius: 4px;
|
border-top-right-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-toolbar:after, .editor-toolbar:before {
|
.editor-toolbar:after,
|
||||||
|
.editor-toolbar:before {
|
||||||
display: block;
|
display: block;
|
||||||
content: ' ';
|
content: ' ';
|
||||||
height: 1px;
|
height: 1px;
|
||||||
@ -57,7 +58,9 @@
|
|||||||
margin-top: 8px
|
margin-top: 8px
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-toolbar:hover, .editor-wrapper input.title:focus, .editor-wrapper input.title:hover {
|
.editor-toolbar:hover,
|
||||||
|
.editor-wrapper input.title:focus,
|
||||||
|
.editor-wrapper input.title:hover {
|
||||||
opacity: .8
|
opacity: .8
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +92,8 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-toolbar a.active, .editor-toolbar a:hover {
|
.editor-toolbar a.active,
|
||||||
|
.editor-toolbar a:hover {
|
||||||
background: #fcfcfc;
|
background: #fcfcfc;
|
||||||
border-color: #95a5a6;
|
border-color: #95a5a6;
|
||||||
}
|
}
|
||||||
@ -112,8 +116,8 @@
|
|||||||
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
|
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
|
||||||
font-size: 65%;
|
font-size: 65%;
|
||||||
vertical-align: text-bottom;
|
vertical-align: text-bottom;
|
||||||
position:relative;
|
position: relative;
|
||||||
top:2px;
|
top: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-toolbar a.fa-header-1:after {
|
.editor-toolbar a.fa-header-1:after {
|
||||||
@ -157,8 +161,8 @@
|
|||||||
.editor-preview {
|
.editor-preview {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width:100%;
|
width: 100%;
|
||||||
height:100%;
|
height: 100%;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
background: #fafafa;
|
background: #fafafa;
|
||||||
@ -184,23 +188,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.editor-preview-active-side {
|
.editor-preview-active-side {
|
||||||
display: block
|
display: block
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-preview-active {
|
.editor-preview-active {
|
||||||
display: block
|
display: block
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-preview>p, .editor-preview-side>p {
|
.editor-preview>p,
|
||||||
|
.editor-preview-side>p {
|
||||||
margin-top: 0
|
margin-top: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-preview pre, .editor-preview-side pre {
|
.editor-preview pre,
|
||||||
|
.editor-preview-side pre {
|
||||||
background: #eee;
|
background: #eee;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-preview table td, .editor-preview table th, .editor-preview-side table td, .editor-preview-side table th {
|
.editor-preview table td,
|
||||||
|
.editor-preview table th,
|
||||||
|
.editor-preview-side table td,
|
||||||
|
.editor-preview-side table th {
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
@ -101,18 +101,18 @@ function toggleFullScreen(editor) {
|
|||||||
// Set fullscreen
|
// Set fullscreen
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
|
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
|
||||||
|
|
||||||
|
|
||||||
// Update toolbar class
|
// Update toolbar class
|
||||||
var wrap = cm.getWrapperElement();
|
var wrap = cm.getWrapperElement();
|
||||||
|
|
||||||
if(!/fullscreen/.test(wrap.previousSibling.className)) {
|
if(!/fullscreen/.test(wrap.previousSibling.className)) {
|
||||||
wrap.previousSibling.className += " fullscreen";
|
wrap.previousSibling.className += " fullscreen";
|
||||||
} else {
|
} else {
|
||||||
wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, "");
|
wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update toolbar button
|
// Update toolbar button
|
||||||
var toolbarButton = editor.toolbarElements.fullscreen;
|
var toolbarButton = editor.toolbarElements.fullscreen;
|
||||||
|
|
||||||
@ -121,11 +121,11 @@ function toggleFullScreen(editor) {
|
|||||||
} else {
|
} else {
|
||||||
toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, '');
|
toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Hide side by side if needed
|
// Hide side by side if needed
|
||||||
var sidebyside = cm.getWrapperElement().nextSibling;
|
var sidebyside = cm.getWrapperElement().nextSibling;
|
||||||
if (/editor-preview-active-side/.test(sidebyside.className))
|
if(/editor-preview-active-side/.test(sidebyside.className))
|
||||||
toggleSideBySide(editor);
|
toggleSideBySide(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ function toggleSideBySide(editor) {
|
|||||||
var preview = wrapper.nextSibling;
|
var preview = wrapper.nextSibling;
|
||||||
var toolbarButton = editor.toolbarElements["side-by-side"];
|
var toolbarButton = editor.toolbarElements["side-by-side"];
|
||||||
|
|
||||||
if (/editor-preview-active-side/.test(preview.className)) {
|
if(/editor-preview-active-side/.test(preview.className)) {
|
||||||
preview.className = preview.className.replace(
|
preview.className = preview.className.replace(
|
||||||
/\s*editor-preview-active-side\s*/g, ''
|
/\s*editor-preview-active-side\s*/g, ''
|
||||||
);
|
);
|
||||||
@ -295,17 +295,17 @@ function toggleSideBySide(editor) {
|
|||||||
wrapper.className = wrapper.className.replace(/\s*CodeMirror-sided\s*/g, ' ');
|
wrapper.className = wrapper.className.replace(/\s*CodeMirror-sided\s*/g, ' ');
|
||||||
} else {
|
} else {
|
||||||
/* When the preview button is clicked for the first time,
|
/* When the preview button is clicked for the first time,
|
||||||
* give some time for the transition from editor.css to fire and the view to slide from right to left,
|
* give some time for the transition from editor.css to fire and the view to slide from right to left,
|
||||||
* instead of just appearing.
|
* instead of just appearing.
|
||||||
*/
|
*/
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
if (!cm.getOption("fullScreen")) toggleFullScreen(editor);
|
if(!cm.getOption("fullScreen")) toggleFullScreen(editor);
|
||||||
preview.className += ' editor-preview-active-side'
|
preview.className += ' editor-preview-active-side'
|
||||||
}, 1);
|
}, 1);
|
||||||
toolbarButton.className += ' active';
|
toolbarButton.className += ' active';
|
||||||
wrapper.className += ' CodeMirror-sided';
|
wrapper.className += ' CodeMirror-sided';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide normal preview if active
|
// Hide normal preview if active
|
||||||
var previewNormal = wrapper.lastChild;
|
var previewNormal = wrapper.lastChild;
|
||||||
if(/editor-preview-active/.test(previewNormal.className)) {
|
if(/editor-preview-active/.test(previewNormal.className)) {
|
||||||
@ -363,10 +363,10 @@ function togglePreview(editor) {
|
|||||||
}
|
}
|
||||||
var text = cm.getValue();
|
var text = cm.getValue();
|
||||||
preview.innerHTML = parse(text);
|
preview.innerHTML = parse(text);
|
||||||
|
|
||||||
// Turn off side by side if needed
|
// Turn off side by side if needed
|
||||||
var sidebyside = cm.getWrapperElement().nextSibling;
|
var sidebyside = cm.getWrapperElement().nextSibling;
|
||||||
if (/editor-preview-active-side/.test(sidebyside.className))
|
if(/editor-preview-active-side/.test(sidebyside.className))
|
||||||
toggleSideBySide(editor);
|
toggleSideBySide(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,62 +407,53 @@ function _toggleHeading(cm, direction, size) {
|
|||||||
(function(i) {
|
(function(i) {
|
||||||
var text = cm.getLine(i);
|
var text = cm.getLine(i);
|
||||||
var currHeadingLevel = text.search(/[^#]/);
|
var currHeadingLevel = text.search(/[^#]/);
|
||||||
|
|
||||||
if(direction !== undefined){
|
if(direction !== undefined) {
|
||||||
if (currHeadingLevel <= 0) {
|
if(currHeadingLevel <= 0) {
|
||||||
if (direction == 'bigger') {
|
if(direction == 'bigger') {
|
||||||
text = '###### ' + text;
|
text = '###### ' + text;
|
||||||
} else {
|
} else {
|
||||||
text = '# ' + text;
|
text = '# ' + text;
|
||||||
}
|
}
|
||||||
} else if (currHeadingLevel == 6 && direction == 'smaller') {
|
} else if(currHeadingLevel == 6 && direction == 'smaller') {
|
||||||
text = text.substr(7);
|
text = text.substr(7);
|
||||||
} else if (currHeadingLevel == 1 && direction == 'bigger') {
|
} else if(currHeadingLevel == 1 && direction == 'bigger') {
|
||||||
text = text.substr(2);
|
text = text.substr(2);
|
||||||
} else {
|
} else {
|
||||||
if (direction == 'bigger') {
|
if(direction == 'bigger') {
|
||||||
text = text.substr(1);
|
text = text.substr(1);
|
||||||
} else {
|
} else {
|
||||||
text = '#' + text;
|
text = '#' + text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
if(size == 1) {
|
||||||
if(size == 1){
|
if(currHeadingLevel <= 0) {
|
||||||
if (currHeadingLevel <= 0) {
|
|
||||||
text = '# ' + text;
|
text = '# ' + text;
|
||||||
}
|
} else if(currHeadingLevel == size) {
|
||||||
else if(currHeadingLevel == size){
|
|
||||||
text = text.substr(currHeadingLevel + 1);
|
text = text.substr(currHeadingLevel + 1);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
text = '# ' + text.substr(currHeadingLevel + 1);
|
text = '# ' + text.substr(currHeadingLevel + 1);
|
||||||
}
|
}
|
||||||
}
|
} else if(size == 2) {
|
||||||
else if(size == 2){
|
if(currHeadingLevel <= 0) {
|
||||||
if (currHeadingLevel <= 0) {
|
|
||||||
text = '## ' + text;
|
text = '## ' + text;
|
||||||
}
|
} else if(currHeadingLevel == size) {
|
||||||
else if(currHeadingLevel == size){
|
|
||||||
text = text.substr(currHeadingLevel + 1);
|
text = text.substr(currHeadingLevel + 1);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
text = '## ' + text.substr(currHeadingLevel + 1);
|
text = '## ' + text.substr(currHeadingLevel + 1);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
if(currHeadingLevel <= 0) {
|
||||||
if (currHeadingLevel <= 0) {
|
|
||||||
text = '### ' + text;
|
text = '### ' + text;
|
||||||
}
|
} else if(currHeadingLevel == size) {
|
||||||
else if(currHeadingLevel == size){
|
|
||||||
text = text.substr(currHeadingLevel + 1);
|
text = text.substr(currHeadingLevel + 1);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
text = '### ' + text.substr(currHeadingLevel + 1);
|
text = '### ' + text.substr(currHeadingLevel + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.replaceRange(text, {
|
cm.replaceRange(text, {
|
||||||
line: i,
|
line: i,
|
||||||
ch: 0
|
ch: 0
|
||||||
@ -719,7 +710,7 @@ var toolbarBuiltInButtons = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var toolbar = ["bold", "italic", "heading", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "|", "preview", "side-by-side", "fullscreen", "guide"];
|
var toolbar = ["bold", "italic", "heading", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "|", "preview", "side-by-side", "fullscreen", "guide"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface of SimpleMDE.
|
* Interface of SimpleMDE.
|
||||||
@ -762,12 +753,12 @@ SimpleMDE.toolbar = toolbar;
|
|||||||
SimpleMDE.markdown = function(text) {
|
SimpleMDE.markdown = function(text) {
|
||||||
if(window.marked) {
|
if(window.marked) {
|
||||||
// Update options
|
// Update options
|
||||||
if(this.options.singleLineBreaks !== false){
|
if(this.options.singleLineBreaks !== false) {
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
breaks: true
|
breaks: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return marked(text);
|
return marked(text);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -842,7 +833,7 @@ SimpleMDE.prototype.render = function(el) {
|
|||||||
if(options.autosave != undefined && options.autosave.enabled === true) {
|
if(options.autosave != undefined && options.autosave.enabled === true) {
|
||||||
this.autosave();
|
this.autosave();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createSidebyside();
|
this.createSidebyside();
|
||||||
|
|
||||||
this._rendered = this.element;
|
this._rendered = this.element;
|
||||||
@ -903,7 +894,7 @@ SimpleMDE.prototype.createSidebyside = function() {
|
|||||||
var wrapper = cm.getWrapperElement();
|
var wrapper = cm.getWrapperElement();
|
||||||
var preview = wrapper.nextSibling;
|
var preview = wrapper.nextSibling;
|
||||||
|
|
||||||
if (!/editor-preview-side/.test(preview.className)) {
|
if(!/editor-preview-side/.test(preview.className)) {
|
||||||
preview = document.createElement('div');
|
preview = document.createElement('div');
|
||||||
preview.className = 'editor-preview-side';
|
preview.className = 'editor-preview-side';
|
||||||
wrapper.parentNode.insertBefore(preview, wrapper.nextSibling);
|
wrapper.parentNode.insertBefore(preview, wrapper.nextSibling);
|
||||||
@ -913,7 +904,11 @@ SimpleMDE.prototype.createSidebyside = function() {
|
|||||||
var cScroll = false;
|
var cScroll = false;
|
||||||
var pScroll = false;
|
var pScroll = false;
|
||||||
cm.on('scroll', function(v) {
|
cm.on('scroll', function(v) {
|
||||||
if (cScroll){cScroll=false; return;}; pScroll=true;
|
if(cScroll) {
|
||||||
|
cScroll = false;
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
pScroll = true;
|
||||||
height = v.getScrollInfo().height - v.getScrollInfo().clientHeight;
|
height = v.getScrollInfo().height - v.getScrollInfo().clientHeight;
|
||||||
ratio = parseFloat(v.getScrollInfo().top) / height;
|
ratio = parseFloat(v.getScrollInfo().top) / height;
|
||||||
move = (preview.scrollHeight - preview.clientHeight) * ratio;
|
move = (preview.scrollHeight - preview.clientHeight) * ratio;
|
||||||
@ -922,7 +917,11 @@ SimpleMDE.prototype.createSidebyside = function() {
|
|||||||
|
|
||||||
// Syncs scroll preview -> editor
|
// Syncs scroll preview -> editor
|
||||||
preview.onscroll = function(v) {
|
preview.onscroll = function(v) {
|
||||||
if (pScroll){pScroll=false; return;}; cScroll=true;
|
if(pScroll) {
|
||||||
|
pScroll = false;
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
cScroll = true;
|
||||||
height = preview.scrollHeight - preview.clientHeight;
|
height = preview.scrollHeight - preview.clientHeight;
|
||||||
ratio = parseFloat(preview.scrollTop) / height;
|
ratio = parseFloat(preview.scrollTop) / height;
|
||||||
move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio;
|
move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio;
|
||||||
@ -937,9 +936,9 @@ SimpleMDE.prototype.createToolbar = function(items) {
|
|||||||
if(!items || items.length === 0) {
|
if(!items || items.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i = 0; i < items.length; i++) {
|
for(var i = 0; i < items.length; i++) {
|
||||||
if(toolbarBuiltInButtons[items[i]] != undefined){
|
if(toolbarBuiltInButtons[items[i]] != undefined) {
|
||||||
items[i] = toolbarBuiltInButtons[items[i]];
|
items[i] = toolbarBuiltInButtons[items[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user