From 8366a94bded4ed769e51c49b32cf11f7d4517179 Mon Sep 17 00:00:00 2001 From: Matt <69441971+sigaloid@users.noreply.github.com> Date: Mon, 27 Dec 2021 12:27:00 +0000 Subject: [PATCH] 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 --- src/share/content_renderer.js | 34 +++++++++++++++++++++------------- src/views/share/page.ejs | 8 +++++++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/share/content_renderer.js b/src/share/content_renderer.js index 14572b062..5ebe643b1 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(``)) { + content += ``; + content += ``; + content += ``; + content += ``; + } } } - 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 = `` + content += `` + content += `` } } + else if (note.type === 'mermaid') { + content = `
${content}

Chart source
${content}
` + } else if (note.type === 'image') { content = ``; } @@ -83,12 +90,11 @@ function getContent(note) { content = ``; } } - else if (note.type === 'book') { - content = getChildrenList(note); - } else { - content = '

This note type cannot be displayed.

' + getChildrenList(note); + content = '

This note type cannot be displayed.

'; } + var child = getChildrenList(note); + content += child === '' ? '' : `
${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 6be374b2c..afdf8e243 100644 --- a/src/views/share/page.ejs +++ b/src/views/share/page.ejs @@ -18,9 +18,15 @@
+
+ <% if (note.parents[0].noteId !== 'share' && note.parents.length != 0) { %> + + <% } %>

<%= note.title %>

-
+
<%- content %>