mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 07:58:08 +00:00
added the paste-latex-image script
This commit is contained in:
parent
1413ab5b14
commit
8b02b4d0a2
2 changed files with 45 additions and 0 deletions
7
paste-latex-image/info.json
Normal file
7
paste-latex-image/info.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "Paste Latex Image",
|
||||
"identifier": "paste-latex-image",
|
||||
"script": "paste-latex-image.qml",
|
||||
"version": 0.1,
|
||||
"description" : "This script creates a menu item and a button that generates and pastes an image from Latex code in the clipboard",
|
||||
}
|
38
paste-latex-image/paste-latex-image.qml
Normal file
38
paste-latex-image/paste-latex-image.qml
Normal file
|
@ -0,0 +1,38 @@
|
|||
import QtQml 2.0
|
||||
import com.qownnotes.noteapi 1.0
|
||||
|
||||
/**
|
||||
* This script creates a menu item and a button that generates and pastes an image from
|
||||
* Latex code in the clipboard
|
||||
*/
|
||||
QtObject {
|
||||
/**
|
||||
* Initializes the custom action
|
||||
*/
|
||||
function init() {
|
||||
// create a menu entry to paste Latex code as an image
|
||||
script.registerCustomAction("pasteLatexImage", "Paste Latex image", "Latex", "insert-image", 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) {
|
||||
switch (identifier) {
|
||||
case "pasteLatexImage":
|
||||
// get the text that is currently in the clipboard
|
||||
var text = script.clipboard();
|
||||
|
||||
// use the webservice to generate and download the image
|
||||
var url = "http://latex.codecogs.com/gif.latex?" + text;
|
||||
var markdown = script.downloadUrlToMedia(url);
|
||||
|
||||
// write the image markdown to the note
|
||||
script.noteTextEditWrite(markdown);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue