mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-03 08:13:14 +08:00
Moved from highlight.js to codemirror
This commit is contained in:
39
resources/assets/js/code.js
Normal file
39
resources/assets/js/code.js
Normal file
@ -0,0 +1,39 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -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"},
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user