mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-07-18 01:02:34 +00:00
Integrated the markdown editor with the image manager
This commit is contained in:
parent
26965fa08f
commit
efb49019d4
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var DropZone = require('dropzone');
|
var DropZone = require('dropzone');
|
||||||
var markdown = require( "marked" );
|
var markdown = require('marked');
|
||||||
|
|
||||||
var toggleSwitchTemplate = require('./components/toggle-switch.html');
|
var toggleSwitchTemplate = require('./components/toggle-switch.html');
|
||||||
var imagePickerTemplate = require('./components/image-picker.html');
|
var imagePickerTemplate = require('./components/image-picker.html');
|
||||||
|
@ -201,9 +201,9 @@ module.exports = function (ngApp, events) {
|
||||||
tinymce.init(scope.tinymce);
|
tinymce.init(scope.tinymce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}])
|
}]);
|
||||||
|
|
||||||
ngApp.directive('markdownEditor', ['$timeout', function($timeout) {
|
ngApp.directive('markdownInput', ['$timeout', function($timeout) {
|
||||||
return {
|
return {
|
||||||
restrict: 'A',
|
restrict: 'A',
|
||||||
scope: {
|
scope: {
|
||||||
|
@ -231,6 +231,50 @@ module.exports = function (ngApp, events) {
|
||||||
scope.mdChange(markdown(value));
|
scope.mdChange(markdown(value));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
ngApp.directive('markdownEditor', ['$timeout', function($timeout) {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
link: function (scope, element, attrs) {
|
||||||
|
|
||||||
|
// Elements
|
||||||
|
var input = element.find('textarea[markdown-input]');
|
||||||
|
var insertImage = element.find('button[data-action="insertImage"]');
|
||||||
|
|
||||||
|
var currentCaretPos = 0;
|
||||||
|
|
||||||
|
input.blur((event) => {
|
||||||
|
currentCaretPos = input[0].selectionStart;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Insert image shortcut
|
||||||
|
input.keydown((event) => {
|
||||||
|
if (event.which === 73 && event.ctrlKey && event.shiftKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
var caretPos = input[0].selectionStart;
|
||||||
|
var currentContent = input.val();
|
||||||
|
var mdImageText = "![](http://)";
|
||||||
|
input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
|
||||||
|
input.focus();
|
||||||
|
input[0].selectionStart = caretPos + ("![](".length);
|
||||||
|
input[0].selectionEnd = caretPos + ('![](http://'.length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Insert image from image manager
|
||||||
|
insertImage.click((event) => {
|
||||||
|
window.ImageManager.showExternal((image) => {
|
||||||
|
var caretPos = currentCaretPos;
|
||||||
|
var currentContent = input.val();
|
||||||
|
var mdImageText = "![" + image.name + "](" + image.url + ")";
|
||||||
|
input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
|
||||||
|
input.change();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
|
@ -39,44 +39,42 @@
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
width: 100%;
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.markdown-display, .markdown-editor-wrap {
|
.markdown-display, .markdown-editor-wrap {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding-top: 28px;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
border: 1px solid #DDD;
|
|
||||||
&:before {
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
padding: $-xs $-m;
|
|
||||||
font-family: 'Roboto Mono';
|
|
||||||
font-size: 11px;
|
|
||||||
line-height: 1;
|
|
||||||
border-bottom: 1px solid #DDD;
|
|
||||||
background-color: #EEE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.markdown-editor-wrap {
|
.markdown-editor-wrap {
|
||||||
display: flex;
|
display: flex;
|
||||||
&:before {
|
flex-direction: column;
|
||||||
content: 'Editor';
|
border: 1px solid #DDD;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.markdown-display {
|
.markdown-display {
|
||||||
padding: 0 $-m;
|
padding: 0 $-m 0;
|
||||||
padding-top: 28px;
|
|
||||||
margin-left: -1px;
|
margin-left: -1px;
|
||||||
&:before {
|
overflow-y: scroll;
|
||||||
content: 'Preview';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.editor-toolbar {
|
||||||
|
width: 100%;
|
||||||
|
padding: $-xs $-m;
|
||||||
|
font-family: 'Roboto Mono';
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.6;
|
||||||
|
border-bottom: 1px solid #DDD;
|
||||||
|
background-color: #EEE;
|
||||||
|
flex: none;
|
||||||
|
&:after {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
|
@ -51,14 +51,26 @@
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if(config('app.editor') === 'markdown')
|
@if(config('app.editor') === 'markdown')
|
||||||
<div id="markdown-editor" class="flex-fill flex">
|
<div id="markdown-editor" markdown-editor class="flex-fill flex">
|
||||||
|
|
||||||
<div class="markdown-editor-wrap">
|
<div class="markdown-editor-wrap">
|
||||||
<textarea markdown-editor md-change="editorChange" md-model="editContent" name="markdown" rows="5"
|
<div class="editor-toolbar">
|
||||||
|
<span class="float left">Editor</span>
|
||||||
|
<div class="float right buttons">
|
||||||
|
<button class="text-button" type="button" data-action="insertImage"><i class="zmdi zmdi-image"></i>Insert Image</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<textarea markdown-input md-change="editorChange" md-model="editContent" name="markdown" rows="5"
|
||||||
@if($errors->has('markdown')) class="neg" @endif>@if(isset($model) || old('markdown')){{htmlspecialchars( old('markdown') ? old('markdown') : ($model->markdown === '' ? $model->html : $model->markdown))}}@endif</textarea>
|
@if($errors->has('markdown')) class="neg" @endif>@if(isset($model) || old('markdown')){{htmlspecialchars( old('markdown') ? old('markdown') : ($model->markdown === '' ? $model->html : $model->markdown))}}@endif</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="markdown-display page-content" ng-bind-html="displayContent"></div>
|
<div class="markdown-editor-wrap">
|
||||||
|
<div class="editor-toolbar">
|
||||||
|
<div class="">Preview</div>
|
||||||
|
</div>
|
||||||
|
<div class="markdown-display page-content" ng-bind-html="displayContent"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" name="html" ng-value="displayContent">
|
<input type="hidden" name="html" ng-value="displayContent">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user