Skip to content

Instantly share code, notes, and snippets.

@wolkenschieber
Created August 22, 2016 06:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolkenschieber/e0f5172a7aaacd8e177c587e73f0b1d9 to your computer and use it in GitHub Desktop.
Save wolkenschieber/e0f5172a7aaacd8e177c587e73f0b1d9 to your computer and use it in GitHub Desktop.
QML-script to convert markdown from QOwnNotes to MediaWiki
import QtQml 2.0
import com.qownnotes.noteapi 1.0
QtObject {
function init() {
script.registerCustomAction("convertToMediaWiki", "Convert note to MediaWiki", "Convert to MediaWiki" );
}
function customActionInvoked(identifier) {
script.log("customActionInvoked - " + identifier);
switch (identifier) {
case "convertToMediaWiki":
var note = script.currentNote();
var nodeName = note.name;
var currentDate = new Date();
var dateString = currentDate.toLocaleString(Qt.locale(), "yyyy-MM-ddThh:mm:ss.zzz");
var tmpFile = "/tmp/"+nodeName+"-mediawiki-"+dateString+".conv";
var fullFileName = note.fullNoteFilePath;
var pandocArgs = [fullFileName, "-f", "markdown", "-t", "mediawiki", "-o", tmpFile];
script.startDetachedProcess("pandoc", pandocArgs);
script.startDetachedProcess("kate", [tmpFile]);
break;
}
}
}
@pbek
Copy link

pbek commented Aug 22, 2016

Looking good!

@wolkenschieber
Copy link
Author

From version 16.08.17, buttons can be added to the custon action:

    function init() {
        script.registerCustomAction("convertToMediaWiki", "Convert note to MediaWiki", "Convert to MediaWiki", "/usr/share/icons/breeze/actions/24/quickopen-file.svg" );
    }

@pbek
Copy link

pbek commented Aug 22, 2016

I guess you should also be able to just write quickopen-file for the icon.

@wolkenschieber
Copy link
Author

Using the icon filename directly also chooses the best matching size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment