Created
February 15, 2014 23:04
-
-
Save mcburton/9026469 to your computer and use it in GitHub Desktop.
An editorial workflow for adding Pandoc formatted citations to your document. Parses a BibTeX file for citekeys.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------ BEGIN WORKFLOW ------------ | |
{ | |
"actions" : [ | |
{ | |
"class" : "WorkflowActionStoreVariable", | |
"pauseBeforeRunning" : false, | |
"customTitle" : "Set Bibliography Filename", | |
"parameters" : { | |
"name" : "Bibliography Filename", | |
"value" : { | |
"tokenRanges" : { | |
}, | |
"type" : "advancedText", | |
"text" : "*.bib" | |
} | |
}, | |
"pauseWithoutShowingParameters" : false | |
}, | |
{ | |
"class" : "WorkflowActionRunScript", | |
"pauseBeforeRunning" : false, | |
"customTitle" : "Get Current Working Directory", | |
"parameters" : { | |
"script" : "#coding: utf-8\nimport workflow\nimport editor\n# Get the current file path\nfile_path = editor.get_path()\n# remove filename to get path\ncurrent_dir = ''.join(file_path.rpartition('\/')[0:2])\nworkflow.set_output(current_dir)\n" | |
}, | |
"pauseWithoutShowingParameters" : false | |
}, | |
{ | |
"class" : "WorkflowActionRunScript", | |
"pauseBeforeRunning" : false, | |
"customTitle" : "Get bibliography file list", | |
"parameters" : { | |
"script" : "#coding: utf-8\nimport workflow\nfrom glob import glob\nimport console\n\ncwd_path = workflow.get_input()\nbib_filename = workflow.get_variable(\"Bibliography Filename\")\nbib_path = ''.join([cwd_path, bib_filename]) \nbib_path = glob(bib_path) \n\nif not bib_path:\n\tconsole.hud_alert(\"No bibliography file(s) found.\")\n\tworkflow.stop()\n\naction_out = '\\n'.join(bib_path)\nworkflow.set_output(action_out)\n\n" | |
}, | |
"pauseWithoutShowingParameters" : false | |
}, | |
{ | |
"class" : "WorkflowActionRunScript", | |
"pauseBeforeRunning" : false, | |
"customTitle" : "Parse .bib files", | |
"parameters" : { | |
"script" : "#coding: utf-8\nimport workflow\nimport editor\nimport fileinput\nimport console\n\nbib_path = workflow.get_input().split('\\n')\n\n# use fileinput to iterate over each line of each file \ncitekeys = \"\".join([line.split(\"{\")[1].replace(\",\",\"\") for line in fileinput.input(bib_path) if line.startswith(\"@\")])\nfileinput.close()\n\nworkflow.set_output(citekeys) #output newline string\n" | |
}, | |
"pauseWithoutShowingParameters" : false | |
}, | |
{ | |
"class" : "WorkflowActionSelectFromList", | |
"pauseBeforeRunning" : false, | |
"customTitle" : "Display Citekeys", | |
"parameters" : { | |
"title" : "Select Citekeys", | |
"allowMultipleSelection" : false, | |
"showInPopover" : true, | |
"list" : { | |
"tokenRanges" : { | |
"{0, 1}" : "Input" | |
}, | |
"type" : "advancedText", | |
"text" : "?" | |
} | |
}, | |
"pauseWithoutShowingParameters" : false | |
}, | |
{ | |
"class" : "WorkflowActionReplaceSelectedText", | |
"pauseBeforeRunning" : false, | |
"customTitle" : "Insert Citekeys", | |
"parameters" : { | |
"replacement" : { | |
"tokenRanges" : { | |
"{1, 1}" : "Input" | |
}, | |
"type" : "advancedText", | |
"text" : "@?" | |
} | |
}, | |
"pauseWithoutShowingParameters" : false | |
} | |
], | |
"name" : "Insert BibTex Citekey" | |
} | |
------------- END WORKFLOW ------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment