mirror of
https://github.com/dnlbauer/obsidian-dataview-autocompletion.git
synced 2026-07-22 05:32:56 +00:00
feat: replace innerHTML call with createEL (obsidian plugin guidelines)
This commit is contained in:
parent
1644899116
commit
f58f736df4
3 changed files with 20 additions and 3 deletions
|
|
@ -14,6 +14,10 @@ const createBaseConfig = (outdir) => ({
|
|||
src: "manifest.json",
|
||||
dest: outdir,
|
||||
},
|
||||
{
|
||||
src: "styles.css",
|
||||
dest: outdir,
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -68,9 +68,19 @@ export class DataviewSuggester extends EditorSuggest<String> {
|
|||
}
|
||||
|
||||
renderSuggestion(value: string, el: HTMLElement): void {
|
||||
// replace marks with bold
|
||||
const formattedHtml = value.replace(/<mark>(.*?)<\/mark>/g, '<span style="font-weight: bold;">$1</span>');
|
||||
el.innerHTML = formattedHtml;
|
||||
// Split the value into parts based on the <mark> tags and their content
|
||||
const parts = value.split(/(<mark>.*?<\/mark>)/g);
|
||||
|
||||
// We cannot use inner HTML; Create a span for each part
|
||||
parts.forEach((part) => {
|
||||
if (part.startsWith("<mark>") && part.endsWith("</mark>")) {
|
||||
const text = part.slice(6, -7); // Remove <mark> and </mark>
|
||||
el.createEl("span", { text, cls: "suggestion-highlight" });
|
||||
} else {
|
||||
// For normal text, create a text node or <span>
|
||||
el.createEl("span", { text: part });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
selectSuggestion(value: string, evt: MouseEvent | KeyboardEvent): void {
|
||||
|
|
|
|||
3
styles.css
Normal file
3
styles.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
span.suggestion-highlight {
|
||||
font-weight: bold;
|
||||
}
|
||||
Loading…
Reference in a new issue