Drafts Action Directory

Footnote

Posted by Colin Walker, Last updated: 2018-07-03 23:54:17 UTC

Prompts for the footnote text and adds both the inline element ( [^1] ) and footnote at end of draft ( [^1]: )

Returns you to where you left off to continue typing.

Install

Steps

  • script

    var p = Prompt.create();
    p.isCancellable = "true";
    p.title = "Enter the footnote text";
    p.addTextView("footnote","","", {
    	"height": 100.0
    });
    p.addButton("Add");
    
    if (p.show()) {
    
      var content = editor.getText();
      var count = (content.match(/\[\^/g) || []).length;
      var fn = (count/2) + 1;
    
      var selRange = editor.getSelectedRange();
      
      editor.focus();
      var inline = "[^"+fn+"]";
      if (fn == 1) {
        var footnote = "\n\n\n[^"+fn+"]: "+p.fieldValues["footnote"];
      } else {
        var footnote = "\n[^"+fn+"]: "+p.fieldValues["footnote"];
      }
    
      if (p.buttonPressed == "Add") {
        editor.setSelectedText(inline);
    
        content = editor.getText() + footnote;
        editor.setText(content);
        editor.setSelectedRange(selRange[0]+inline.length,0);
    
      }
    
    }

Options

  • After Success Nothing
    Notification None
    Log Level None

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.