mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 07:58:08 +00:00
Merge pull request #36 from mleo2003/master
Add text-highlights script.
This commit is contained in:
commit
9e13c4042d
2 changed files with 48 additions and 0 deletions
10
text-highlights/info.json
Normal file
10
text-highlights/info.json
Normal 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."
|
||||||
|
}
|
38
text-highlights/text-highlights.qml
Normal file
38
text-highlights/text-highlights.qml
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue