This commit is contained in:
mayurankv 2025-01-25 18:02:20 +00:00
parent d88824d255
commit 5f227b6ff6
3 changed files with 23 additions and 5 deletions

View file

@ -75,14 +75,14 @@ export function renderedFencedCodeUndecorating(): void {
export function renderedViewFold(
contentEl: HTMLElement,
fold?: boolean,
fold: boolean | null,
): void {
const codeblockPreElements = contentEl.querySelectorAll(`pre.${PREFIX}pre`);
codeblockPreElements.forEach(
(codeblockPreElement: HTMLElement) => {
foldFencePreElement(
codeblockPreElement,
(typeof fold === "undefined") ? (codeblockPreElement.getAttribute(DEFAULT_FOLD_ATTRIBUTE) ?? "false") === "true" : fold,
fold ?? (codeblockPreElement.getAttribute(DEFAULT_FOLD_ATTRIBUTE) ?? "false") === "true",
);
},
);

View file

@ -267,16 +267,17 @@ function setTitleAndReference(
): Partial<FenceCodeParameters> {
if (parameterValue !== null) {
const linkInfo = parseLink(parameterValue)
if (linkInfo === null)
if (linkInfo === null) {
if (parameterKey === "title")
return { ...result, title: parameterValue }
else
return result
else
} else {
if ((parameterKey === "title") || !("title" in result))
return {...result, ...linkInfo}
return { ...result, ...linkInfo }
else
return { ...result, reference: linkInfo.reference }
}
} else {
if (parameterKey !== "title" || !("title" in result))

View file

@ -0,0 +1,17 @@
import { MarkdownView } from "obsidian";
import CodeStylerPlugin from "src/main";
import { renderedViewFold } from "../Decorating/Rendered/Fenced";
export function viewFold(
fold: boolean | null,
plugin: CodeStylerPlugin,
) {
const activeView = plugin.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
if (activeView.getMode() === "preview")
renderedViewFold(activeView.contentEl, fold);
else if (activeView.getMode() === "source")
//@ts-expect-error Undocumented Obsidian API
editingDocumentFold(activeView.editor.cm.docView.view, fold);
}
}