1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-21 23:48:08 +00:00

Merge pull request #36 from mleo2003/master

Add text-highlights script.
This commit is contained in:
Patrizio Bekerle 2018-08-03 05:47:49 +02:00 committed by GitHub
commit 9e13c4042d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
}
}
}