From 83240e7fa5bd8f32b07b4652cb74102ce0fe9533 Mon Sep 17 00:00:00 2001 From: Andrea Alberti Date: Tue, 13 Aug 2024 19:29:04 +0200 Subject: [PATCH] Finished correcting bugs. Now testing it. --- legacy_settings/data_1_4.json | 4 ++-- src/main.ts | 37 ++++++----------------------------- src/settings_tab.ts | 12 ++++++------ src/types_legacy.ts | 2 +- 4 files changed, 15 insertions(+), 40 deletions(-) diff --git a/legacy_settings/data_1_4.json b/legacy_settings/data_1_4.json index 00cf296..afd19ac 100644 --- a/legacy_settings/data_1_4.json +++ b/legacy_settings/data_1_4.json @@ -4,12 +4,12 @@ "dataview-recent-files": { "name": "Dataview Recent Files", - "anno": "markdown:\nMy own plugin to show the recently modified files.\n[[2024-06-13 Survey group culture]]\n\n![[00 Meta/Misc/Test.jpg]]\n\n[[2024-08-05 Review Cs-based Rydberg quantum computers]]" + "anno": "markdown:\n${label}My own plugin to show the recently modified files.\n[[2024-06-13 Survey group culture]]\n\n![[00 Meta/Misc/Test.jpg]]\n\n[[2024-08-05 Review Cs-based Rydberg quantum computers]]" }, "dataview": { "name": "Dataview", - "anno": "Super-useful plugin that allows querying the notes to provide database functionality. 🔥🔥🔥" + "anno": "html:\n${label}Super-useful plugin that allows querying the notes to provide database functionality. 🔥🔥🔥" }, "highlightr-plugin": { diff --git a/src/main.ts b/src/main.ts index ebe91aa..e351250 100644 --- a/src/main.ts +++ b/src/main.ts @@ -354,7 +354,7 @@ export default class PluginsAnnotations extends Plugin { } case AnnotationType.markdown: { const label = Platform.isMobile ? this.settings.label_mobile : this.settings.label_desktop; - const desc_with_label = desc.replace(/\$\{label\}/g, label); + const desc_with_label = label + desc; await MarkdownRenderer.renderMarkdown(desc_with_label, annotation_div, '', this); this.handleAnnotationLinks(annotation_div); break; @@ -416,8 +416,11 @@ export default class PluginsAnnotations extends Plugin { annotation_container.classList.remove('plugin-comment-placeholder'); } - // const text = annotation_div.innerText; // text without html markup - // annotation_div.innerText = text; // this removes all html markup for editing + const text = annotation_div.innerText; // text without html markup + annotation_div.innerText = text; // this removes all html markup for editing + + // Force a DOM reflow by reading the offsetHeight (or another property) + annotation_div.offsetHeight; const range = document.createRange(); range.selectNodeContents(annotation_div); @@ -455,8 +458,6 @@ export default class PluginsAnnotations extends Plugin { const innerText = annotation_div.innerText.trim(); - console.log(innerText); - if (isPlaceholder || innerText === '') { // placeholder annotation_div.innerHTML = placeholder; delete this.settings.annotations[pluginId]; @@ -490,32 +491,6 @@ export default class PluginsAnnotations extends Plugin { if(!this.settings.editable) { return; } event.stopPropagation(); }); - - // Save the comment on input change and update inputTriggered status - // annotation_div.addEventListener('change', (event: Event) => { - // console.log("CHANGE"); - // if(!this.settings.editable) { return; } - // annotation_text = annotation_div.innerText.trim(); - // if (annotation_text === '') { - // annotation_text = ''; - // isPlaceholder = true; - // delete this.settings.annotations[pluginId]; - // annotation_div.classList.add('plugin-comment-placeholder'); - // } else { - // isPlaceholder = false; - - // const {type,content} = parse_annotation_1_4_0(annotation_text); - - // this.settings.annotations[pluginId] = { - // desc: content, - // name: pluginName, - // type: type, - // }; - // annotation_div.classList.remove('plugin-comment-placeholder'); - // isPlaceholder = false; - // } - // this.debouncedSaveAnnotations(); - // }); } async addIcon(tab: SettingTab) { diff --git a/src/settings_tab.ts b/src/settings_tab.ts index 2c967e3..b31cd5d 100644 --- a/src/settings_tab.ts +++ b/src/settings_tab.ts @@ -95,23 +95,23 @@ export class PluginsAnnotationsSettingTab extends PluginSettingTab { div.appendChild(p1); const p2 = document.createElement('p2'); - p2.innerHTML = "You can enter rich text notes using Markdown and HTML. Markdown annotations will be dispalyed as Obsidian normally renders Markdown text. \ - To this purpose, your annotation needs to start with a preamble line containing one \ - of three strings:\ + p2.innerHTML = "You can enter rich text notes using Markdown (recommended) and HTML. Markdown annotations will be dispalyed as Obsidian renders Markdown text. \ + The annotation type can be selected by starting the annotation text with a line containing one \ + of the following options:\ \ - If you do not enter any preamble line, the default text: will be assumed."; + If the first line of annotation text contains none of the options above, the default markdown: is assumed."; div.appendChild(p2); const p3 = document.createElement('p'); - p3.innerHTML = "You can directly link your Obsidian notes from inside your annotations by adding links such as [[My notes/Review of plugin XYZ|my plugin note]]."; + p3.innerHTML = "In Markdown annotations, you can directly link notes inside your vault by adding links such as [[My notes/Review of plugin XYZ|my plugin note]]."; div.appendChild(p3); const p4 = document.createElement('p'); - p4.innerHTML = "When editing HTML and Markdown annotations, use the placeholder ${label} to display the annotation label at the chosen location." + p4.innerHTML = "When editing HTML annotations, use the placeholder ${label} to display the annotation label at the chosen location." div.appendChild(p4); frag.appendChild(div); diff --git a/src/types_legacy.ts b/src/types_legacy.ts index 51c7c25..613849c 100644 --- a/src/types_legacy.ts +++ b/src/types_legacy.ts @@ -37,7 +37,7 @@ export function parseAnnotation_1_4_0(text: string): {type:AnnotationType,conten if (preamble.startsWith('html:')) { return {type: AnnotationType.html, content: sliced}; } else if (preamble.startsWith('markdown:')) { - return {type: AnnotationType.markdown, content: sliced}; + return {type: AnnotationType.markdown, content: sliced.replace(/\$\{label\}/g, '')}; } else if (preamble.startsWith('text:')) { return {type: AnnotationType.text, content: sliced}; } else {