1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Getting the latest changes

This commit is contained in:
Abijeet
2017-06-04 10:20:01 +05:30
78 changed files with 732 additions and 267 deletions

View File

@@ -0,0 +1,56 @@
require('codemirror/mode/css/css');
require('codemirror/mode/clike/clike');
require('codemirror/mode/go/go');
require('codemirror/mode/htmlmixed/htmlmixed');
require('codemirror/mode/javascript/javascript');
require('codemirror/mode/markdown/markdown');
require('codemirror/mode/nginx/nginx');
require('codemirror/mode/php/php');
require('codemirror/mode/powershell/powershell');
require('codemirror/mode/python/python');
require('codemirror/mode/ruby/ruby');
require('codemirror/mode/shell/shell');
require('codemirror/mode/sql/sql');
require('codemirror/mode/toml/toml');
require('codemirror/mode/xml/xml');
require('codemirror/mode/yaml/yaml');
const CodeMirror = require('codemirror');
module.exports.highlight = function() {
let codeBlocks = document.querySelectorAll('.page-content pre');
for (let i = 0; i < codeBlocks.length; i++) {
codeBlocks[i].innerHTML = codeBlocks[i].innerHTML.replace(/<br\s*[\/]?>/gi ,'\n');
let content = codeBlocks[i].textContent;
CodeMirror(function(elt) {
codeBlocks[i].parentNode.replaceChild(elt, codeBlocks[i]);
}, {
value: content,
mode: "",
lineNumbers: true,
theme: 'base16-light',
readOnly: true
});
}
};
module.exports.markdownEditor = function(elem) {
let content = elem.textContent;
let cm = CodeMirror(function(elt) {
elem.parentNode.insertBefore(elt, elem);
elem.style.display = 'none';
}, {
value: content,
mode: "markdown",
lineNumbers: true,
theme: 'base16-light',
lineWrapping: true
});
return cm;
};

View File

@@ -2,6 +2,7 @@
const DropZone = require("dropzone");
const MarkdownIt = require("markdown-it");
const mdTasksLists = require('markdown-it-task-lists');
const code = require('./code');
module.exports = function (ngApp, events) {
@@ -233,19 +234,41 @@ module.exports = function (ngApp, events) {
// Set initial model content
element = element.find('textarea').first();
let content = element.val();
scope.mdModel = content;
scope.mdChange(md.render(content));
element.on('change input', (event) => {
content = element.val();
// Codemirror Setup
let cm = code.markdownEditor(element[0]);
cm.on('change', (instance, changeObj) => {
update(instance);
});
cm.on('scroll', instance => {
// Thanks to http://liuhao.im/english/2015/11/10/the-sync-scroll-of-markdown-editor-in-javascript.html
let scroll = instance.getScrollInfo();
let atEnd = scroll.top + scroll.clientHeight === scroll.height;
if (atEnd) {
scope.$emit('markdown-scroll', -1);
return;
}
let lineNum = instance.lineAtHeight(scroll.top, 'local');
let range = instance.getRange({line: 0, ch: null}, {line: lineNum, ch: null});
let parser = new DOMParser();
let doc = parser.parseFromString(md.render(range), 'text/html');
let totalLines = doc.documentElement.querySelectorAll('body > *');
scope.$emit('markdown-scroll', totalLines.length);
});
function update(instance) {
let content = instance.getValue();
element.val(content);
$timeout(() => {
scope.mdModel = content;
scope.mdChange(md.render(content));
});
});
}
update(cm);
scope.$on('markdown-update', (event, value) => {
cm.setValue(value);
element.val(value);
scope.mdModel = value;
scope.mdChange(md.render(value));
@@ -259,7 +282,7 @@ module.exports = function (ngApp, events) {
* Markdown Editor
* Handles all functionality of the markdown editor.
*/
ngApp.directive('markdownEditor', ['$timeout', function ($timeout) {
ngApp.directive('markdownEditor', ['$timeout', '$rootScope', function ($timeout, $rootScope) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
@@ -282,34 +305,15 @@ module.exports = function (ngApp, events) {
currentCaretPos = $input[0].selectionStart;
});
// Scroll sync
let inputScrollHeight,
inputHeight,
displayScrollHeight,
displayHeight;
function setScrollHeights() {
inputScrollHeight = $input[0].scrollHeight;
inputHeight = $input.height();
displayScrollHeight = $display[0].scrollHeight;
displayHeight = $display.height();
}
setTimeout(() => {
setScrollHeights();
}, 200);
window.addEventListener('resize', setScrollHeights);
let scrollDebounceTime = 800;
let lastScroll = 0;
$input.on('scroll', event => {
let now = Date.now();
if (now - lastScroll > scrollDebounceTime) {
setScrollHeights()
// Handle scroll sync event from editor scroll
$rootScope.$on('markdown-scroll', (event, lineCount) => {
let elems = $display[0].children[0].children;
if (elems.length > lineCount) {
let topElem = (lineCount === -1) ? elems[elems.length-1] : elems[lineCount];
$display.animate({
scrollTop: topElem.offsetTop
}, {queue: false, duration: 200, easing: 'linear'});
}
let scrollPercent = ($input.scrollTop() / (inputScrollHeight - inputHeight));
let displayScrollY = (displayScrollHeight - displayHeight) * scrollPercent;
$display.scrollTop(displayScrollY);
lastScroll = now;
});
// Editor key-presses

View File

@@ -78,9 +78,9 @@ module.exports = function() {
extended_valid_elements: 'pre[*]',
automatic_uploads: false,
valid_children: "-div[p|pre|h1|h2|h3|h4|h5|h6|blockquote]",
plugins: "image table textcolor paste link autolink fullscreen imagetools code customhr autosave lists",
plugins: "image table textcolor paste link autolink fullscreen imagetools code customhr autosave lists codesample",
imagetools_toolbar: 'imageoptions',
toolbar: "undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image-insert link hr | removeformat code fullscreen",
toolbar: "undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image-insert link hr | removeformat code fullscreen codesample",
content_style: "body {padding-left: 15px !important; padding-right: 15px !important; margin:0!important; margin-left:auto!important;margin-right:auto!important;}",
style_formats: [
{title: "Header Large", format: "h2"},

View File

@@ -1,9 +1,14 @@
"use strict";
// Configure ZeroClipboard
const Clipboard = require("clipboard");
const Code = require('../code');
let setupPageShow = window.setupPageShow = function (pageId) {
Code.highlight();
if (!pageId) return;
// Set up pointer
let $pointer = $('#pointer').detach();
let pointerShowing = false;