Skip to content

Build your personal knowledge base with Trilium Notes

Various share page improvements (#2471)

Matt8366a94bded4
diff --git a/src/share/content_renderer.js b/src/share/content_renderer.js
index 14572b0627..5ebe643b18 100644
--- a/src/share/content_renderer.js
+++ b/src/share/content_renderer.js
@@ -35,7 +35,7 @@ function getContent(note) {
&& document.querySelectorAll("img").length === 0;
if (isEmpty) {
- content = NO_CONTENT + getChildrenList(note);
+ content = NO_CONTENT;
}
else {
for (const linkEl of document.querySelectorAll("a")) {
@@ -57,21 +57,28 @@ function getContent(note) {
}
content = document.body.innerHTML;
+
+ if (content.includes(`<span class="math-tex">`)) {
+ content += `<script src="../../libraries/katex/katex.min.js"></script>`;
+ content += `<link rel="stylesheet" href="../../libraries/katex/katex.min.css">`;
+ content += `<script src="../../libraries/katex/auto-render.min.js" onload="renderMathInElement(document.getElementById('content'));"></script>`;
+ content += `<script src="../../libraries/katex/mhchem.min.js"></script>`;
+ }
}
}
- else if (note.type === 'code' || note.type === 'mermaid') {
+ else if (note.type === 'code') {
if (!content?.trim()) {
- content = NO_CONTENT + getChildrenList(note);
+ content = NO_CONTENT;
}
else {
- const document = new JSDOM().window.document;
-
- const preEl = document.createElement('pre');
- preEl.appendChild(document.createTextNode(content));
-
- content = preEl.outerHTML;
+ content = `<textarea style="width:100px;" id="code">${content}</textarea>`
+ content += `<link rel="stylesheet" href="../../libraries/codemirror/codemirror.css">`
+ content += `<script src="../../libraries/codemirror/codemirror.js" onload="var editor = CodeMirror.fromTextArea(document.getElementById('code'), {lineNumbers: true, lineWrapping: true});"></script>`
}
}
+ else if (note.type === 'mermaid') {
+ content = `<div class=\"mermaid\">${content}</div><script src=\"../../libraries/mermaid.min.js\"></script><hr><details><summary>Chart source</summary><pre>${content}</pre></details>`
+ }
else if (note.type === 'image') {
content = `<img src="api/images/${note.noteId}/${note.title}?${note.utcDateModified}">`;
}
@@ -83,12 +90,11 @@ function getContent(note) {
content = `<button type="button" onclick="location.href='api/notes/${note.noteId}/download'">Download file</button>`;
}
}
- else if (note.type === 'book') {
- content = getChildrenList(note);
- }
else {
- content = '<p>This note type cannot be displayed.</p>' + getChildrenList(note);
+ content = '<p>This note type cannot be displayed.</p>';
}
+ var child = getChildrenList(note);
+ content += child === '' ? '' : `<hr>${child}`;
return content;
}
@@ -96,3 +102,5 @@ function getContent(note) {
module.exports = {
getContent
};
+
+
diff --git a/src/views/share/page.ejs b/src/views/share/page.ejs
index 6be374b2c8..afdf8e243f 100644
--- a/src/views/share/page.ejs
+++ b/src/views/share/page.ejs
@@ -18,9 +18,15 @@
<body>
<div id="layout">
<div id="main">
+ <br>
+ <% if (note.parents[0].noteId !== 'share' && note.parents.length != 0) { %>
+ <nav class="parent-link">
+ <a href="<%= note.parents[0].noteId %>">&lt; Parent note (<%= note.parents[0].title %>)</a>
+ </nav>
+ <% } %>
<h1 id="title"><%= note.title %></h1>
- <div id="content" class="note-<%= note.type %> <% if (note.type === 'text') { %>ck-content<% } %>">
+ <div id="content" class="note-<%= note.type %><% if (note.type === 'text') { %>ck-content<% } %>">
<%- content %>
</div>
</div>