andy-stack_vaultkeeper-ai/Services/HTMLService.ts
Andrew Beal 13a09cdb89 refactor: improve settings UI with icon grids and standardized helpers
- Add Exclusions heading section in settings
- Replace activeDocument calls with Obsidian helper functions (createEl, createDiv, createSpan, createFragment)
- Standardize file monitoring disclaimers with icon grid layout
- Add template warning for local models with external documentation link
- Consolidate file disclaimer rendering logic with clickable help links
- Remove redundant tooltip enum entry
- Add new CSS classes for icon grid layouts
2026-07-04 13:27:22 +01:00

35 lines
No EOL
1.1 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 = createFragment();
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 = createDiv();
const fragment = this.parseHTMLString(htmlString);
container.appendChild(fragment);
return container;
}
}