From f2490ddcb749b592984d4dc13155a91526fc5fb8 Mon Sep 17 00:00:00 2001 From: Matthew Robinson Date: Thu, 2 Aug 2018 13:51:11 -0700 Subject: [PATCH] Add text-highlights script. --- text-highlights/info.json | 10 ++++++++ text-highlights/text-highlights.qml | 38 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 text-highlights/info.json create mode 100644 text-highlights/text-highlights.qml diff --git a/text-highlights/info.json b/text-highlights/info.json new file mode 100644 index 0000000..5241571 --- /dev/null +++ b/text-highlights/info.json @@ -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." +} diff --git a/text-highlights/text-highlights.qml b/text-highlights/text-highlights.qml new file mode 100644 index 0000000..30196b0 --- /dev/null +++ b/text-highlights/text-highlights.qml @@ -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, "$1"); + html = html.replace("", stylesheet + ""); + 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; + } + } +}