Finished correcting bugs. Now testing it.

This commit is contained in:
Andrea Alberti 2024-08-13 19:29:04 +02:00
parent 820207a1bc
commit 83240e7fa5
4 changed files with 15 additions and 40 deletions

View file

@ -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":
{

View file

@ -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) {

View file

@ -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:\
<ul>\
<li>markdown:</li>\
<li>html:</li>\
<li>text:</li>\
</ul>\
If you do not enter any preamble line, the default <em>text:</em> will be assumed.";
If the first line of annotation text contains none of the options above, the default <em>markdown:</em> 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 <em>${label}</em> to display the <em>annotation label</em> at the chosen location."
p4.innerHTML = "When editing HTML annotations, use the placeholder <em>${label}</em> to display the <em>annotation label</em> at the chosen location."
div.appendChild(p4);
frag.appendChild(div);

View file

@ -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 {