/* eslint-disable no-unused-vars */ import tinydate from 'tinydate'; import DOMPurify from 'dompurify'; import * as dom from '../util/dom'; import cssVars from '../util/polyfill/css-vars'; import { getAndActive, sticky } from '../event/sidebar'; import { getPath, isAbsolutePath } from '../router/util'; import { isMobile, inBrowser } from '../util/env'; import { isPrimitive, merge } from '../util/core'; import { scrollActiveSidebar } from '../event/scroll'; import { Compiler } from './compiler'; import * as tpl from './tpl'; import { prerenderEmbed } from './embed'; let vueGlobalData; function executeScript() { const script = dom .findAll('.markdown-section>script') .filter(s => !/template/.test(s.type))[0]; if (!script) { return false; } const code = script.innerText.trim(); if (!code) { return false; } new Function(code)(); } function formatUpdated(html, updated, fn) { updated = typeof fn === 'function' ? fn(updated) : typeof fn === 'string' ? tinydate(fn)(new Date(updated)) : updated; return html.replace(/{docsify-updated}/g, updated); } function renderMain(html) { const docsifyConfig = this.config; const markdownElm = dom.find('.markdown-section'); const vueVersion = 'Vue' in window && window.Vue.version && Number(window.Vue.version.charAt(0)); const isMountedVue = elm => { const isVue2 = Boolean(elm.__vue__ && elm.__vue__._isVue); const isVue3 = Boolean(elm._vnode && elm._vnode.__v_skip); return isVue2 || isVue3; }; if (!html) { html = '

404 - Not found

'; } if ('Vue' in window) { const mountedElms = dom .findAll('.markdown-section > *') .filter(elm => isMountedVue(elm)); // Destroy/unmount existing Vue instances for (const mountedElm of mountedElms) { if (vueVersion === 2) { mountedElm.__vue__.$destroy(); } else if (vueVersion === 3) { mountedElm.__vue_app__.unmount(); } } } this._renderTo(markdownElm, html); // Render sidebar with the TOC !docsifyConfig.loadSidebar && this._renderSidebar(); // Execute markdown