const {JSDOM} = require("jsdom"); const NO_CONTENT = '
This note has no content.
'; const shaca = require("./shaca/shaca"); function getChildrenList(note) { if (note.hasChildren()) { const document = new JSDOM().window.document; const ulEl = document.createElement("ul"); for (const childNote of note.getChildNotes()) { const li = document.createElement("li"); const link = document.createElement("a"); link.appendChild(document.createTextNode(childNote.title)); link.setAttribute("href", childNote.noteId); li.appendChild(link); ulEl.appendChild(li); } return 'Child notes:
' + ulEl.outerHTML; } else { return ''; } } function getContent(note) { let content = note.getContent(); if (note.type === 'text') { const document = new JSDOM(content || "").window.document; const isEmpty = document.body.textContent.trim().length === 0 && document.querySelectorAll("img").length === 0; if (isEmpty) { content = NO_CONTENT; } else { for (const linkEl of document.querySelectorAll("a")) { const href = linkEl.getAttribute("href"); if (href?.startsWith("#")) { const notePathSegments = href.split("/"); const noteId = notePathSegments[notePathSegments.length - 1]; const linkedNote = shaca.getNote(noteId); if (linkedNote) { linkEl.setAttribute("href", linkedNote.shareId); } else { linkEl.removeAttribute("href"); } } } content = document.body.innerHTML; if (content.includes(``)) { content += ``; content += ``; content += ``; content += ``; } } } else if (note.type === 'code') { if (!content?.trim()) { content = NO_CONTENT; } else { content = `` content += `` content += `` } } else if (note.type === 'mermaid') { content = `${content}
This note type cannot be displayed.
'; } var child = getChildrenList(note); content += child === '' ? '' : `