mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 16:30:27 +00:00
- 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
35 lines
No EOL
1.1 KiB
TypeScript
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;
|
|
}
|
|
|
|
} |