mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Added a view for the API docs
This commit is contained in:
18
resources/js/components/details-highlighter.js
Normal file
18
resources/js/components/details-highlighter.js
Normal file
@ -0,0 +1,18 @@
|
||||
import Code from "../services/code"
|
||||
class DetailsHighlighter {
|
||||
|
||||
constructor(elem) {
|
||||
this.elem = elem;
|
||||
this.dealtWith = false;
|
||||
elem.addEventListener('toggle', this.onToggle.bind(this));
|
||||
}
|
||||
|
||||
onToggle() {
|
||||
if (this.dealtWith) return;
|
||||
|
||||
Code.highlightWithin(this.elem);
|
||||
this.dealtWith = true;
|
||||
}
|
||||
}
|
||||
|
||||
export default DetailsHighlighter;
|
@ -30,6 +30,7 @@ import settingColorPicker from "./setting-color-picker";
|
||||
import entityPermissionsEditor from "./entity-permissions-editor";
|
||||
import templateManager from "./template-manager";
|
||||
import newUserPassword from "./new-user-password";
|
||||
import detailsHighlighter from "./details-highlighter";
|
||||
|
||||
const componentMapping = {
|
||||
'dropdown': dropdown,
|
||||
@ -64,6 +65,7 @@ const componentMapping = {
|
||||
'entity-permissions-editor': entityPermissionsEditor,
|
||||
'template-manager': templateManager,
|
||||
'new-user-password': newUserPassword,
|
||||
'details-highlighter': detailsHighlighter,
|
||||
};
|
||||
|
||||
window.components = {};
|
||||
|
@ -87,9 +87,20 @@ const modeMap = {
|
||||
* Highlight pre elements on a page
|
||||
*/
|
||||
function highlight() {
|
||||
let codeBlocks = document.querySelectorAll('.page-content pre, .comment-box .content pre');
|
||||
for (let i = 0; i < codeBlocks.length; i++) {
|
||||
highlightElem(codeBlocks[i]);
|
||||
const codeBlocks = document.querySelectorAll('.page-content pre, .comment-box .content pre');
|
||||
for (const codeBlock of codeBlocks) {
|
||||
highlightElem(codeBlock);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight all code blocks within the given parent element
|
||||
* @param {HTMLElement} parent
|
||||
*/
|
||||
function highlightWithin(parent) {
|
||||
const codeBlocks = parent.querySelectorAll('pre');
|
||||
for (const codeBlock of codeBlocks) {
|
||||
highlightElem(codeBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,6 +319,7 @@ function getMetaKey() {
|
||||
|
||||
export default {
|
||||
highlight: highlight,
|
||||
highlightWithin: highlightWithin,
|
||||
wysiwygView: wysiwygView,
|
||||
popupEditor: popupEditor,
|
||||
setMode: setMode,
|
||||
|
Reference in New Issue
Block a user