mirror of
https://gitlab.com/vyla-entertainment/documentation.git
synced 2026-11-19 17:07:22 -05:00
fixed syntax issues
This commit is contained in:
118
src/js/main.js
118
src/js/main.js
@@ -487,7 +487,11 @@ function cgSwitch(btn) {
|
||||
t.classList.toggle("active", t === btn);
|
||||
});
|
||||
group.querySelectorAll(".code-group-panel").forEach(function (p, i) {
|
||||
p.classList.toggle("active", String(i) === index);
|
||||
var on = String(i) === index;
|
||||
p.classList.toggle("active", on);
|
||||
if (on && window.Prism) {
|
||||
window.Prism.highlightAllUnder(p);
|
||||
}
|
||||
});
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
}
|
||||
@@ -663,6 +667,63 @@ function isBookmarked(href) {
|
||||
return getBookmarks().some(function (b) { return b.href === href; });
|
||||
}
|
||||
|
||||
function buildCopyMarkdownButton(rawMd) {
|
||||
var b = document.createElement("button");
|
||||
b.type = "button";
|
||||
b.className = "copy-md-btn";
|
||||
b.setAttribute("aria-label", "Copy Markdown");
|
||||
b.title = "Copy page as Markdown";
|
||||
b.innerHTML = icon("copy");
|
||||
b.addEventListener("click", function (e) {
|
||||
e.stopPropagation();
|
||||
var text = rawMd || "";
|
||||
var onSuccess = function () {
|
||||
b.innerHTML = icon("check");
|
||||
b.classList.add("copied");
|
||||
setTimeout(function () {
|
||||
b.innerHTML = icon("copy");
|
||||
b.classList.remove("copied");
|
||||
}, 2000);
|
||||
};
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(onSuccess).catch(function () {
|
||||
fallbackCopyText(text, onSuccess);
|
||||
});
|
||||
} else {
|
||||
fallbackCopyText(text, onSuccess);
|
||||
}
|
||||
});
|
||||
return b;
|
||||
}
|
||||
|
||||
function fallbackCopyText(text, cb) {
|
||||
var ta = document.createElement("textarea");
|
||||
ta.value = text;
|
||||
ta.style.position = "fixed";
|
||||
ta.style.opacity = "0";
|
||||
document.body.appendChild(ta);
|
||||
ta.focus();
|
||||
ta.select();
|
||||
try {
|
||||
document.execCommand("copy");
|
||||
if (cb) cb();
|
||||
} catch (e) { }
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
|
||||
function highlightAllCode(container) {
|
||||
var target = container || document;
|
||||
if (window.Prism && typeof window.Prism.highlightAllUnder === "function") {
|
||||
window.Prism.highlightAllUnder(target);
|
||||
} else {
|
||||
setTimeout(function () {
|
||||
if (window.Prism && typeof window.Prism.highlightAllUnder === "function") {
|
||||
window.Prism.highlightAllUnder(target);
|
||||
}
|
||||
}, 60);
|
||||
}
|
||||
}
|
||||
|
||||
function buildBookmarkButton(route) {
|
||||
var b = document.createElement("button");
|
||||
b.type = "button";
|
||||
@@ -858,6 +919,7 @@ function parseMarkdown(md) {
|
||||
var inCodeGroup = false;
|
||||
var codeGroupTabs = [];
|
||||
var codeGroupPanels = [];
|
||||
var pendingTabTitle = "";
|
||||
|
||||
function flushList() {
|
||||
if (inList) {
|
||||
@@ -921,9 +983,24 @@ function parseMarkdown(md) {
|
||||
inCodeGroup = true;
|
||||
codeGroupTabs = [];
|
||||
codeGroupPanels = [];
|
||||
pendingTabTitle = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inCodeGroup && !inPre) {
|
||||
var tabCommentMatch = line.match(/<!--\s*tab:\s*([^-]+?)\s*-->/i);
|
||||
if (tabCommentMatch) {
|
||||
pendingTabTitle = tabCommentMatch[1].trim();
|
||||
continue;
|
||||
}
|
||||
if (line.trim().startsWith("<!--") && line.trim().endsWith("-->")) {
|
||||
continue;
|
||||
}
|
||||
if (line.trim().length === 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (inCodeGroup && line === ":::") {
|
||||
flushList();
|
||||
flushTable();
|
||||
@@ -936,13 +1013,14 @@ function parseMarkdown(md) {
|
||||
codeGroupPanels.forEach(function (panel, idx) {
|
||||
var activeClass = idx === 0 ? " active" : "";
|
||||
var langClass = panel.lang ? ' class="language-' + panel.lang + '"' : ' class="language-none"';
|
||||
cgHtml += '<div class="code-group-panel' + activeClass + '"><pre><code' + langClass + '>' + esc(panel.code) + '</code></pre></div>';
|
||||
cgHtml += '<div class="code-group-panel' + activeClass + '"><pre' + langClass + '><code' + langClass + '>' + esc(panel.code) + '</code></pre></div>';
|
||||
});
|
||||
cgHtml += '</div></div>';
|
||||
out.push(cgHtml);
|
||||
inCodeGroup = false;
|
||||
codeGroupTabs = [];
|
||||
codeGroupPanels = [];
|
||||
pendingTabTitle = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -953,27 +1031,37 @@ function parseMarkdown(md) {
|
||||
inPre = true;
|
||||
var info = line.slice(3).trim();
|
||||
var tabMatch = info.match(/\[([^\]]+)\]/);
|
||||
var tabTitle = tabMatch ? tabMatch[1] : "";
|
||||
var tabTitle = tabMatch ? tabMatch[1] : (pendingTabTitle || "");
|
||||
pendingTabTitle = "";
|
||||
preLang = info.replace(/\[([^\]]+)\]/, "").trim();
|
||||
if (inCodeGroup && tabTitle) {
|
||||
codeGroupTabs.push(tabTitle);
|
||||
if (inCodeGroup) {
|
||||
codeGroupTabs.push(tabTitle || preLang || ("Tab " + (codeGroupTabs.length + 1)));
|
||||
}
|
||||
preCode = [];
|
||||
} else {
|
||||
inPre = false;
|
||||
var codeContent = preCode.join("\n");
|
||||
var resolvedLang = preLang;
|
||||
var resolvedLang = (preLang || "").toLowerCase().trim();
|
||||
if (resolvedLang === "js") resolvedLang = "javascript";
|
||||
else if (resolvedLang === "ts") resolvedLang = "typescript";
|
||||
else if (resolvedLang === "sh" || resolvedLang === "shell" || resolvedLang === "zsh") resolvedLang = "bash";
|
||||
else if (resolvedLang === "ps" || resolvedLang === "ps1") resolvedLang = "powershell";
|
||||
else if (resolvedLang === "py") resolvedLang = "python";
|
||||
else if (resolvedLang === "rs") resolvedLang = "rust";
|
||||
else if (resolvedLang === "kt") resolvedLang = "kotlin";
|
||||
else if (resolvedLang === "yml") resolvedLang = "yaml";
|
||||
else if (resolvedLang === "md") resolvedLang = "markdown";
|
||||
if (!resolvedLang) {
|
||||
if (codeContent.trim().startsWith("{") || codeContent.trim().startsWith("[")) resolvedLang = "json";
|
||||
else if (codeContent.indexOf("=") !== -1 && !codeContent.includes("function") && !codeContent.includes(";")) resolvedLang = "ini";
|
||||
else if (codeContent.startsWith("http://") || codeContent.startsWith("https://")) resolvedLang = "http";
|
||||
else if (codeContent.startsWith("http://") || codeContent.startsWith("https://") || codeContent.startsWith("GET ") || codeContent.startsWith("POST ")) resolvedLang = "http";
|
||||
else resolvedLang = "bash";
|
||||
}
|
||||
if (inCodeGroup) {
|
||||
codeGroupPanels.push({ lang: resolvedLang, code: codeContent });
|
||||
} else {
|
||||
var langClass = resolvedLang ? ' class="language-' + resolvedLang + '"' : ' class="language-none"';
|
||||
out.push('<div class="code-wrap"><pre><code' + langClass + ">" + esc(codeContent) + "</code></pre></div>");
|
||||
out.push('<div class="code-wrap"><pre' + langClass + '><code' + langClass + ">" + esc(codeContent) + "</code></pre></div>");
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -1685,16 +1773,18 @@ function loadPage() {
|
||||
var hasApiToken = md.indexOf("YOUR_API_URL") !== -1;
|
||||
contentEl.innerHTML = parseMarkdown(personalize(md));
|
||||
|
||||
if (window.Prism) {
|
||||
window.Prism.highlightAllUnder(contentEl);
|
||||
}
|
||||
|
||||
var eyebrow = document.createElement("div");
|
||||
eyebrow.className = "eyebrow";
|
||||
var eyebrowText = document.createElement("span");
|
||||
eyebrowText.textContent = route.group.title;
|
||||
eyebrow.appendChild(eyebrowText);
|
||||
eyebrow.appendChild(buildBookmarkButton(route));
|
||||
|
||||
var actions = document.createElement("div");
|
||||
actions.className = "eyebrow-actions";
|
||||
actions.appendChild(buildCopyMarkdownButton(md));
|
||||
actions.appendChild(buildBookmarkButton(route));
|
||||
eyebrow.appendChild(actions);
|
||||
|
||||
var h1 = contentEl.querySelector("h1");
|
||||
if (h1) h1.parentNode.insertBefore(eyebrow, h1);
|
||||
|
||||
@@ -1725,6 +1815,7 @@ function loadPage() {
|
||||
updateFooterNav(route.item);
|
||||
updateToc();
|
||||
addCopyButtons();
|
||||
highlightAllCode(contentEl);
|
||||
initCodeFades();
|
||||
wrapTables();
|
||||
resolveLatestDownloads();
|
||||
@@ -2183,7 +2274,6 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
buildSearch();
|
||||
buildSettings();
|
||||
initEasterEggs();
|
||||
initContribSheet();
|
||||
bindLightboxClicks();
|
||||
loadPage();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user