Add text-highlights script.

This commit is contained in:
Matthew Robinson 2018-08-02 13:51:11 -07:00
parent 8796d9b2f6
commit f2490ddcb7
2 changed files with 48 additions and 0 deletions

10
text-highlights/info.json Normal file
View File

@ -0,0 +1,10 @@
{
"name": "Text Highlights",
"identifier": "text-highlights",
"script": "text-highlights.qml",
"authors": ["@mleo2003"],
"platforms": ["linux", "macos", "windows"],
"version": "0.0.2",
"minAppVersion": "17.06.2",
"description" : "Provide a way to highlight text in markdown and render it as some other markdown viewers do. Uses ==text== syntax, and the color shown is configurable."
}

View File

@ -0,0 +1,38 @@
import QtQml 2.0
import QOwnNotesTypes 1.0
QtObject {
property string highlightColor;
property variant settingsVariables: [
{
"identifier": "highlightColor",
"name": "Highlight Color",
"description": "Color to highlight text as",
"type": "string",
"default": "FFFF00",
}
];
function noteToMarkdownHtmlHook(note, html) {
var stylesheet = ".highlighted {background-color: #" + highlightColor + ";}";
html = html.replace(/==(.+?)==/g, "<span class='highlighted'>$1</span>");
html = html.replace("</style>", stylesheet + "</style>");
return html;
}
function init() {
script.registerCustomAction("addHighlights", "Add Highlight Marks", "Add Highlights", "text-wrap");
}
function customActionInvoked(identifier) {
switch (identifier) {
case "addHighlights":
// getting selected text from the note text edit
var text = "==" + script.noteTextEditSelectedText() + "==";
// put the result to the current cursor position in the note text edit
script.noteTextEditWrite(text);
break;
}
}
}