X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a6bbe4698741a5221f22fa7818a0a3037a54430a..refs/pull/2003/head:/resources/js/services/code.js diff --git a/resources/js/services/code.js b/resources/js/services/code.js index 3fcf74125..14801de9c 100644 --- a/resources/js/services/code.js +++ b/resources/js/services/code.js @@ -5,15 +5,18 @@ import Clipboard from "clipboard/dist/clipboard.min"; import 'codemirror/mode/css/css'; import 'codemirror/mode/clike/clike'; import 'codemirror/mode/diff/diff'; +import 'codemirror/mode/fortran/fortran'; import 'codemirror/mode/go/go'; +import 'codemirror/mode/haskell/haskell'; import 'codemirror/mode/htmlmixed/htmlmixed'; import 'codemirror/mode/javascript/javascript'; import 'codemirror/mode/julia/julia'; import 'codemirror/mode/lua/lua'; -import 'codemirror/mode/haskell/haskell'; import 'codemirror/mode/markdown/markdown'; import 'codemirror/mode/mllike/mllike'; import 'codemirror/mode/nginx/nginx'; +import 'codemirror/mode/perl/perl'; +import 'codemirror/mode/pascal/pascal'; import 'codemirror/mode/php/php'; import 'codemirror/mode/powershell/powershell'; import 'codemirror/mode/properties/properties'; @@ -42,6 +45,8 @@ const modeMap = { 'c#': 'text/x-csharp', csharp: 'text/x-csharp', diff: 'diff', + for: 'fortran', + fortran: 'fortran', go: 'go', haskell: 'haskell', hs: 'haskell', @@ -58,9 +63,13 @@ const modeMap = { markdown: 'markdown', ml: 'mllike', nginx: 'nginx', + perl: 'perl', + pl: 'perl', powershell: 'powershell', properties: 'properties', ocaml: 'mllike', + pascal: 'text/x-pascal', + pas: 'text/x-pascal', php: (content) => { return content.includes('/gi ,'\n'); - const content = elem.textContent.trim(); + const content = elem.textContent.trimEnd(); let mode = ''; if (innerCodeElem !== null) { @@ -171,7 +191,7 @@ function getMode(suggestion, content) { * @returns {*|string} */ function getTheme() { - return window.codeTheme || 'base16-light'; + return window.codeTheme || 'default'; } /** @@ -258,10 +278,18 @@ function setMode(cmInstance, modeSuggestion, content) { function setContent(cmInstance, codeContent) { cmInstance.setValue(codeContent); setTimeout(() => { - cmInstance.refresh(); + updateLayout(cmInstance); }, 10); } +/** + * Update the layout (codemirror refresh) of a cm instance. + * @param cmInstance + */ +function updateLayout(cmInstance) { + cmInstance.refresh(); +} + /** * Get a CodeMirror instance to use for the markdown editor. * @param {HTMLElement} elem @@ -297,10 +325,12 @@ function getMetaKey() { export default { highlight: highlight, + highlightWithin: highlightWithin, wysiwygView: wysiwygView, popupEditor: popupEditor, setMode: setMode, setContent: setContent, + updateLayout: updateLayout, markdownEditor: markdownEditor, getMetaKey: getMetaKey, };