Action

Create MMD Table

Posted by derick, Last update over 6 years ago

Create a multimarkdown table. Based on http://1writerapp.com/action/cb6bd

Steps

  • script

    // See online documentation for examples
    // http://getdrafts.com/scripting
    
    // adapted from http://1writerapp.com/action/cb6bd
    				
    var p = Prompt.create();
    p.title="MD Table";
    p.addTextField("c","Columns","");
    p.addTextField("r","   Rows","");		
    p.addButton("Go");
    p.show();
    
    if (p.buttonPressed == "Go") {
    
    var cols = p.fieldValues["c"];
    var rows = p.fieldValues["r"];
    				
    				var headerOut = "|";
    				var seperatorOut = "|";
    				var rowOut = "|";
    				// build head row
    				for(i=0; i < cols; i++) {
    					headerOut = headerOut + "\t\t\t|";
    				}
    				headerOut += "\n";
    				// build seperator row
    				for(i=0; i < cols; i++) {
    					seperatorOut = seperatorOut + "----\t\t|";
    				}
    				seperatorOut += "\n";
    				// build rows
    				for(n=0; n < rows; n++) {
    					for(i=0; i < cols; i++) {
    				 		rowOut = rowOut + "\t\t\t|";
    					}
    				  if (n == rows-1) {
    				  	rowOut += "\n";
    				  } else {
    				  	rowOut += "\n|";
    				  }
    				}
    				editor.setSelectedText (headerOut + seperatorOut + rowOut);
    		}

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.