Action

Footnote

Posted by Colin Walker, Last update over 5 years ago

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.

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
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.