support markdown in notes when using showNotesPanel #4091 #6332

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458
2024-08-27 15:24:36 +01:00
parent bf00de4425
commit b4323223cc
7 changed files with 4092 additions and 4 deletions

View File

@@ -47,6 +47,8 @@
<script keeplink=1 type="text/javascript" src="scripts/filesaver.min.js"></script>
<script keeplink=1 type="text/javascript" src="scripts/ol{{{min}}}.js"></script>
<script keeplink=1 type="text/javascript" src="scripts/ol3-contextmenu{{{min}}}.js"></script>
<script keeplink=1 type="text/javascript" src="scripts/purify{{{min}}}.js"></script>
<script keeplink=1 type="text/javascript" src="scripts/marked{{{min}}}.js"></script>
<title>{{{title}}}</title>
</head>
<body id="body" oncontextmenu="handleContextMenu(event)" style="display:none;min-width:495px" onload="if (typeof(startup) !== 'undefined') startup();">
@@ -630,7 +632,7 @@
</thead>
<tbody>
<tr>
<td><textarea id=notesPanelArea readonly style=width:300px;height:200px;resize:none;overflow-y:scroll></textarea></td>
<td><div id=notesPanelArea style=width:300px;height:200px;resize:none;overflow-y:scroll></div></td>
</tr>
</tbody>
</table>
@@ -2970,7 +2972,7 @@
focusTextBox('d2devNotes');
}
}else{
if (message.notes) { QH('notesPanelArea', decodeURIComponent(message.notes)); } else { QH('notesPanelArea', ''); }
Q('notesPanelArea').innerHTML = (message.notes && marked && DOMPurify) ? DOMPurify.sanitize(marked.parse(decodeURIComponent(message.notes), { breaks: true }), { USE_PROFILES: { html: true } }) : '';
if (showNotesPanel && message.notes) { QV('notesPanel',true); }else{ QV('notesPanel', false); }
}
break;
@@ -8153,13 +8155,14 @@
if (xxdialogMode) return;
if (noteid == null) { noteid = encodeURIComponentEx('p'+userinfo._id); }
var x = '<textarea id=d2devNotes ro=' + readonly + ' noteid=' + noteid + ' readonly style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea>';
if (noteid.startsWith('node%2F%2F')) { x += '<span style=font-size:10px>' + "Device group notes can be viewed and changed by other device group administrators." + '<span>'; }
if (noteid.startsWith('node%2F%2F')) { x += ' <span style=font-size:10px>' + "Device group notes can be viewed and changed by other device group administrators." + '</span>'; }
if (showNotesPanel) { x += ' <span style=font-size:10px><a target=_blank href=\'https://www.markdownguide.org/cheat-sheet/\'>' + "Markdown syntax supported" + '</a></span>'; }
setDialogMode(2, "Notes", 3, showNotesEx, x, noteid);
meshserver.send({ action: 'getNotes', id: decodeURIComponent(noteid) });
}
function showNotesEx(buttons, tag) {
QH('notesPanelArea', Q('d2devNotes').value);
Q('notesPanelArea').innerHTML = (marked && DOMPurify) ? DOMPurify.sanitize(marked.parse(Q('d2devNotes').value, { breaks: true }), { USE_PROFILES: { html: true } }) : Q('d2devNotes').value;
meshserver.send({ action: 'setNotes', id: decodeURIComponent(tag), notes: encodeURIComponentEx(Q('d2devNotes').value) });
if (showNotesPanel && Q('d2devNotes').value != '') { QV('notesPanel',true); }else{ QV('notesPanel', false); }
}