diff --git a/README.md b/README.md index 89d2620..accb49d 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Scripts * [dump_mysql.sh](https://forge.tourmentine.com/n/scripts/src/main/dump_mysql.sh) => dump all mysql databases (and send a report to the monitoring system) * [dump_postgresql.sh](https://forge.tourmentine.com/n/scripts/src/main/dump_postgresql.sh) => dump all Postgres databases (and send a report to the monitoring system). based on [dump_mysql.sh](https://forge.tourmentine.com/n/scripts/src/main/dump_mysql.sh). * [opdsupdates.py](https://forge.tourmentine.com/n/scripts/src/main/opdsupdates.py) => look for OPDS catalog updates and send a mail if any + * [qownnotes-mermaid-dark.qml](https://forge.tourmentine.com/n/scripts/src/main/qownnotes-mermaid-dark.qml) => Fork of QOwnNotes' [Mermaid script](https://github.com/qownnotes/scripts/tree/master/mermaid) for dark theme * [randomwallpaper.sh](https://forge.tourmentine.com/n/scripts/src/main/randomwallpaper.sh) => display a random wallpaper * [secupdate](https://forge.tourmentine.com/n/scripts/src/main/secupdate) => apply security updates & recompile kernel (FreeBSD) * [superscreen](https://forge.tourmentine.com/n/scripts/src/main/superscreen) => open multiple ssh sessions to a bunch of servers inside a screen diff --git a/qownnotes-mermaid-dark.qml b/qownnotes-mermaid-dark.qml new file mode 100644 index 0000000..e5aea65 --- /dev/null +++ b/qownnotes-mermaid-dark.qml @@ -0,0 +1,29 @@ +import QtQml 2.0 +import QOwnNotesTypes 1.0 + +QtObject { + /** + * This function is called before the markdown html of a note is generated + * + * It allows you to modify what is passed to the markdown to html converter + * + * The method can for example be used in multiple scripts to render code (like LaTeX math or mermaid) + * to its graphical representation for the preview + * + * The note will not be changed in this process + * + * @param {NoteApi} note - the note object + * @param {string} markdown - the markdown that is about to being converted to html + * @param {string} forExport - true if the html is used for an export, false for the preview + * @return {string} the modified markdown or an empty string if nothing should be modified + */ + function preNoteToMarkdownHtmlHook(note, markdown, forExport) { + var re = /```mermaid\n([\s\S]*?)\n```/gim; + markdown = markdown.replace(re, function(_, diag){ + var encodedData = Qt.btoa(diag); + var ink = '![](https://mermaid.ink/img/' + encodedData + '?bgColor=!201F1F)'; + return ink; + }); + return markdown; + } +}