mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 06:15:48 +01:00
Various share page improvements (#2471)
* Add clientside mermaid chart rendering Merry Christmas :) * Add katex math rendering client-side * Update page.ejs * Revert (wrong branch) * Add children nodes to all notes under hr * Add parent note button * Add note type in child note info * Fix parent, relative paths * Add code rendering, fix space in HTML class
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user