Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for mermaid.js diagrams (#135)
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "Mermaid Diagrams", | ||
"identifier": "mermaid", | ||
"script": "mermaid.qml", | ||
"authors": ["@dohliam"], | ||
"platforms": ["linux", "macos", "windows"], | ||
"version": "0.0.1", | ||
"minAppVersion": "20.6.0", | ||
"description" : "Support for rendering mermaid diagrams." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import QtQml 2.0 | ||
import QOwnNotesTypes 1.0 | ||
|
||
QtObject { | ||
/** | ||
* This function is called when the markdown html of a note is generated | ||
* | ||
* It allows you to modify this html | ||
* This is for example called before by the note preview | ||
* | ||
* The method can be used in multiple scripts to modify the html of the preview | ||
* | ||
* @param {NoteApi} note - the note object | ||
* @param {string} html - the html that is about to being rendered | ||
* @param {string} forExport - the html is used for an export, false for the preview | ||
* @return {string} the modified html 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 normalize = diag.replace(/>/gi, ">").replace(/</gi, "<"); | ||
var encodedData = Qt.btoa(normalize); | ||
var ink = '![](https://mermaid.ink/img/' + encodedData + ')'; | ||
return ink; | ||
}); | ||
return markdown; | ||
} | ||
|
||
} |