From a715f6df902a16fb8d3d856340c9e1cde80df2b9 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle Date: Sat, 20 May 2017 13:04:53 +0200 Subject: [PATCH] updated script --- selected-markdown-to-bbcode-dev/info.json | 10 -- .../selected-markdown-to-bbcode.qml | 94 ------------------- selected-markdown-to-bbcode/info.json | 7 +- .../panbbcode.lua | 0 .../selected-markdown-to-bbcode.qml | 15 ++- 5 files changed, 11 insertions(+), 115 deletions(-) delete mode 100644 selected-markdown-to-bbcode-dev/info.json delete mode 100644 selected-markdown-to-bbcode-dev/selected-markdown-to-bbcode.qml rename {selected-markdown-to-bbcode-dev => selected-markdown-to-bbcode}/panbbcode.lua (100%) diff --git a/selected-markdown-to-bbcode-dev/info.json b/selected-markdown-to-bbcode-dev/info.json deleted file mode 100644 index f622e8f..0000000 --- a/selected-markdown-to-bbcode-dev/info.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "Selected Markdown to BBCode Dev Version", - "identifier": "selected-markdown-to-bbcode-dev", - "script": "selected-markdown-to-bbcode.qml", - "resources": ["panbbcode.lua"], - "authors": ["@pbek"], - "version": "0.0.1", - "minAppVersion": "17.05.8", - "description" : "With this script you can right click the selected text and convert it to BBCode Code.\n\nDependencies\nPandoc\npanbbcode.lua (bundled with the script)\n\nInstallation\nAfter you have installed Pandoc you have to configure its path in the script settings." -} diff --git a/selected-markdown-to-bbcode-dev/selected-markdown-to-bbcode.qml b/selected-markdown-to-bbcode-dev/selected-markdown-to-bbcode.qml deleted file mode 100644 index f665e82..0000000 --- a/selected-markdown-to-bbcode-dev/selected-markdown-to-bbcode.qml +++ /dev/null @@ -1,94 +0,0 @@ -import QtQml 2.0 - -/** - * This script creates a menu item and a button that converts the selected Markdown - * text to BBCode in the clipboard - * - * Dependencies: - * http://pandoc.org - * https://github.com/2ion/pandoc-bbcode - */ -QtObject { - property string pandocPath; - - // register your settings variables so the user can set them in the script settings - property variant settingsVariables: [ - { - "identifier": "pandocPath", - "name": "Pandoc path", - "description": "Please select the path to your Pandoc executable:", - "type": "file", - "default": "pandoc", - }, - ]; - - // the path to the script's directory will be set here - property string scriptDirPath; - - - /** - * Initializes the custom action - */ - function init() { - script.registerCustomAction("markdownToBBCode", "Markdown to BBCode", "BBCode", "edit-copy", true, true); - } - - /** - * This function is invoked when a custom action is triggered - * in the menu or via button - * - * @param identifier string the identifier defined in registerCustomAction - */ - function customActionInvoked(identifier) { - if (identifier != "markdownToBBCode") { - return; - } - - // get the selected text from the note text edit - var text = script.noteTextEditSelectedText(); - - // get the path of the lua script - var panbbcodePath = scriptDirPath + script.dirSeparator() + "panbbcode.lua"; - - // you need pandoc and the BBCode writer from https://github.com/2ion/pandoc-bbcode - // to convert Markdown to BBCode - var params = ["-t", panbbcodePath, "-f", "markdown"]; - var result = script.startSynchronousProcess(pandocPath, params, text); - - // do some code list cleanup - result = replaceAll(result, "[list=*]", "[list]"); - result = replaceAll(result, "[/*]", ""); - - // convert inline code blocks to italic - // do this 10 times to take care of multiple code blocks in a line - for (var i = 0; i < 10; i++) { - result = result.replace(/^(.+?)\[code\](.+?)\[\/code\]/img, "$1[i]$2[/i]"); - } - - // convert headlines to bold - result = replaceAll(result, "[h]", "[b]"); - result = replaceAll(result, "[/h]", "[/b]"); - - // convert `em` to `i` - result = replaceAll(result, "[em]", "[i]"); - result = replaceAll(result, "[/em]", "[/i]"); - - // link some users - result = replaceAll(result, "@Georg", "[USER=1]Georg[/USER]"); - result = replaceAll(result, "@Sören", "[USER=2]Sören[/USER]"); - result = replaceAll(result, "@Robert", "[USER=16]Robert[/USER]"); - result = replaceAll(result, "@Stephan", "[USER=8]Stephan[/USER]"); - result = replaceAll(result, "@Gunnar", "[USER=14]Gunnar[/USER]"); - - // put the result into the clipboard - script.setClipboardText(result); - } - - function replaceAll(str, find, replace) { - return String(str).replace(new RegExp(escapeRegExp(find), 'g'), replace); - } - - function escapeRegExp(str) { - return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); - } -} diff --git a/selected-markdown-to-bbcode/info.json b/selected-markdown-to-bbcode/info.json index 6646b1b..4286a19 100644 --- a/selected-markdown-to-bbcode/info.json +++ b/selected-markdown-to-bbcode/info.json @@ -2,8 +2,9 @@ "name": "Selected Markdown to BBCode", "identifier": "selected-markdown-to-bbcode", "script": "selected-markdown-to-bbcode.qml", + "resources": ["panbbcode.lua"], "authors": ["@pbek"], - "version": "0.0.1", - "minAppVersion": "17.05.7", - "description" : "With this script you can right click the selected text and convert it to BBCode Code.\n\nDependencies\nPancode\npanbbcode.lua\n\nInstallation\nAfter you have installed Pancode you have to download the lua script panbbcode.lua and configure both paths in the script settings." + "version": "0.0.2", + "minAppVersion": "17.05.8", + "description" : "With this script you can right click the selected text and convert it to BBCode Code.\n\nDependencies\nPandoc\npanbbcode.lua (bundled with the script)\n\nInstallation\nAfter you have installed Pandoc you have to configure its path in the script settings." } diff --git a/selected-markdown-to-bbcode-dev/panbbcode.lua b/selected-markdown-to-bbcode/panbbcode.lua similarity index 100% rename from selected-markdown-to-bbcode-dev/panbbcode.lua rename to selected-markdown-to-bbcode/panbbcode.lua diff --git a/selected-markdown-to-bbcode/selected-markdown-to-bbcode.qml b/selected-markdown-to-bbcode/selected-markdown-to-bbcode.qml index dae3aef..f665e82 100644 --- a/selected-markdown-to-bbcode/selected-markdown-to-bbcode.qml +++ b/selected-markdown-to-bbcode/selected-markdown-to-bbcode.qml @@ -9,7 +9,6 @@ import QtQml 2.0 * https://github.com/2ion/pandoc-bbcode */ QtObject { - property string panbbcodePath; property string pandocPath; // register your settings variables so the user can set them in the script settings @@ -21,15 +20,12 @@ QtObject { "type": "file", "default": "pandoc", }, - { - "identifier": "panbbcodePath", - "name": "panbbcode path", - "description": "Please select the path to your panbbcode.lua executable:", - "type": "file", - "default": "/opt/scripts/panbbcode.lua", - }, ]; + // the path to the script's directory will be set here + property string scriptDirPath; + + /** * Initializes the custom action */ @@ -51,6 +47,9 @@ QtObject { // get the selected text from the note text edit var text = script.noteTextEditSelectedText(); + // get the path of the lua script + var panbbcodePath = scriptDirPath + script.dirSeparator() + "panbbcode.lua"; + // you need pandoc and the BBCode writer from https://github.com/2ion/pandoc-bbcode // to convert Markdown to BBCode var params = ["-t", panbbcodePath, "-f", "markdown"];