Action Directory / mdTableGen(表格)

Install

Generate Markdown table

Shared by

Script

ui.input('Columns', 3, 'Enter number of columns', function(value) {
	if (value) {
		var cols = value;
		ui.input('Rows', 4, 'Enter number of rows', function(value) {
			if (value) {
				var rows = value;
				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.replaceSelection(headerOut + seperatorOut + rowOut);
			}
		})
	}
		
})