andy-stack_vaultkeeper-ai/Services/HTMLService.ts
Andrew Beal 28c8ccb44b feat: add quick actions system with provider-aware model settings
Introduce QuickActionsService and QuickAgent for lightweight, single-shot AI
operations. Add a dedicated quickActionModel setting alongside a new top-level
provider setting, with validation ensuring all models match the selected provider
and provider-specific defaults. Refactor FileSystemService to offer both TFile
and path-based overloads (readFile/readFilePath, writeToFile/writeToFilePath,
patchFile/patchFileAtPath). Replace window/document globals with activeWindow/
activeDocument throughout InputService and VaultkeeperAISettingTab for Obsidian
mobile compatibility.
Update linting packages to latest.
2026-04-20 20:20:22 +01:00

35 lines
No EOL
1.2 KiB
TypeScript

export class HTMLService {
public clearElement(element: HTMLElement) {
element.empty();
}
public setHTMLContent(container: HTMLElement, htmlString: string) {
this.clearElement(container);
const fragment = this.parseHTMLString(htmlString);
container.appendChild(fragment);
}
public parseHTMLString(htmlString: string): DocumentFragment {
const parser = new DOMParser();
const fragment = activeDocument.createDocumentFragment();
const doc = parser.parseFromString(htmlString, "text/html");
// Transfer all nodes from the parsed body to the fragment
while (doc.body.firstChild) {
fragment.appendChild(doc.body.firstChild);
}
return fragment;
}
// Creates a temporary container, parses HTML, and returns the container.
// Useful for parsing HTML when you need to traverse the resulting DOM structure.
public parseHTMLToContainer(htmlString: string): HTMLDivElement {
const container = activeDocument.createElement("div");
const fragment = this.parseHTMLString(htmlString);
container.appendChild(fragment);
return container;
}
}