Skip to content

Build your personal knowledge base with Trilium Notes

book notes don't display images as separate children if the image is included in the parent text note, #892

zadamc9b2ff05e957
diff --git a/package-lock.json b/package-lock.json
index d8d768703f..3b425515d7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "trilium",
- "version": "0.40.6",
+ "version": "0.40.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/src/public/javascripts/widgets/note_actions.js b/src/public/javascripts/widgets/note_actions.js
index 6bf0569aab..37216a7205 100644
--- a/src/public/javascripts/widgets/note_actions.js
+++ b/src/public/javascripts/widgets/note_actions.js
@@ -10,6 +10,7 @@ const TPL = `
.note-actions .dropdown-item[disabled], .note-actions .dropdown-item[disabled]:hover {
color: var(--muted-text-color) !important;
background-color: transparent !important;
+ pointer-events: none; /* makes it unclickable */
}
</style>
@@ -64,14 +65,4 @@ export default class NoteActionsWidget extends TabAwareWidget {
this.$exportNoteButton.attr('disabled', 'disabled');
}
}
-
- triggerEvent(e, eventName) {
- const $item = $(e.target).closest('dropdown-item');
-
- if ($item.is('[disabled]')) {
- return;
- }
-
- this.triggerEvent(eventName);
- }
}
\ No newline at end of file
diff --git a/src/public/javascripts/widgets/type_widgets/book.js b/src/public/javascripts/widgets/type_widgets/book.js
index 13ba4a55bc..159be7e7b9 100644
--- a/src/public/javascripts/widgets/type_widgets/book.js
+++ b/src/public/javascripts/widgets/type_widgets/book.js
@@ -158,44 +158,60 @@ export default class BookTypeWidget extends TypeWidget {
this.$help.show();
}
+ const imageLinks = note.getRelations('imageLink');
+
for (const childNote of childNotes) {
- const childNotePath = this.notePath + '/' + childNote.noteId;
+ // image is already visible in the parent note so no need to display it separately in the book
+ if (imageLinks.find(rel => rel.value === childNote.noteId)) {
+ continue;
+ }
- const $content = $('<div class="note-book-content">')
- .css("max-height", ZOOMS[this.zoomLevel].height);
+ const $card = await this.renderNote(childNote);
- const $card = $('<div class="note-book-card">')
- .attr('data-note-id', childNote.noteId)
- .css("flex-basis", ZOOMS[this.zoomLevel].width)
- .append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNotePath, {showTooltip: false})))
- .append($content);
+ $container.append($card);
+ }
+ }
- try {
- const {type, renderedContent} = await noteContentRenderer.getRenderedContent(childNote);
+ async renderNote(note) {
+ const notePath = this.notePath + '/' + note.noteId;
- $card.addClass("type-" + type);
- $content.append(renderedContent);
- }
- catch (e) {
- console.log(`Caught error while rendering note ${note.noteId} of type ${note.type}: ${e.message}, stack: ${e.stack}`);
+ const $content = $('<div class="note-book-content">')
+ .css("max-height", ZOOMS[this.zoomLevel].height);
- $content.append("rendering error");
- }
+ const $card = $('<div class="note-book-card">')
+ .attr('data-note-id', note.noteId)
+ .css("flex-basis", ZOOMS[this.zoomLevel].width)
+ .append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(notePath, {showTooltip: false})))
+ .append($content);
- const childCount = childNote.getChildNoteIds().length;
+ try {
+ const {type, renderedContent} = await noteContentRenderer.getRenderedContent(note);
- if (childCount > 0) {
- const label = `${childCount} child${childCount > 1 ? 'ren' : ''}`;
+ $card.addClass("type-" + type);
+ $content.append(renderedContent);
+ } catch (e) {
+ console.log(`Caught error while rendering note ${note.noteId} of type ${note.type}: ${e.message}, stack: ${e.stack}`);
- $card.append($('<div class="note-book-children">')
- .append($(`<a class="note-book-open-children-button no-print" href="javascript:">+ Show ${label}</a>`))
- .append($(`<a class="note-book-hide-children-button no-print" href="javascript:">- Hide ${label}</a>`).hide())
- .append($('<div class="note-book-children-content">'))
- );
- }
+ $content.append("rendering error");
+ }
- $container.append($card);
+ const imageLinks = note.getRelations('imageLink');
+
+ const childCount = note.getChildNoteIds()
+ .filter(childNoteId => !imageLinks.find(rel => rel.value === childNoteId))
+ .length;
+
+ if (childCount > 0) {
+ const label = `${childCount} child${childCount > 1 ? 'ren' : ''}`;
+
+ $card.append($('<div class="note-book-children">')
+ .append($(`<a class="note-book-open-children-button no-print" href="javascript:">+ Show ${label}</a>`))
+ .append($(`<a class="note-book-hide-children-button no-print" href="javascript:">- Hide ${label}</a>`).hide())
+ .append($('<div class="note-book-children-content">'))
+ );
}
+
+ return $card;
}
/** @return {boolean} true if this is "auto book" activated (empty text note) and not explicit book note */
diff --git a/src/public/javascripts/widgets/type_widgets/text.js b/src/public/javascripts/widgets/type_widgets/text.js
index ce621faaa5..5fc8e488dc 100644
--- a/src/public/javascripts/widgets/type_widgets/text.js
+++ b/src/public/javascripts/widgets/type_widgets/text.js
@@ -155,15 +155,7 @@ export default class TextTypeWidget extends TypeWidget {
// if content is only tags/whitespace (typically <p>&nbsp;</p>), then just make it empty
// this is important when setting new note to code
- return this.isContentEmpty(content) ? '' : content;
- }
-
- isContentEmpty(content) {
- content = content.toLowerCase();
-
- return jQuery(content).text().trim() === ''
- && !content.includes("<img")
- && !content.includes("<section")
+ return utils.isHtmlEmpty(content) ? '' : content;
}
focus() {
diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css
index 920463de5c..4066eea515 100644
--- a/src/public/stylesheets/style.css
+++ b/src/public/stylesheets/style.css
@@ -201,6 +201,7 @@ span.fancytree-node.archived {
.icon-action.disabled {
color: var(--muted-text-color) !important;
cursor: not-allowed;
+ pointer-events: none;
}
.ui-widget-content a:not(.ui-tabs-anchor) {
@@ -271,6 +272,7 @@ div.ui-tooltip {
.dropdown-menu .disabled {
color: #888 !important;
+ pointer-events: none;
}
.dropdown-menu a:hover:not(.disabled), .dropdown-item:hover:not(.disabled) {