Skip to content

Instantly share code, notes, and snippets.

@njjerrysmith
Last active January 17, 2022 22:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save njjerrysmith/dc8d52a1a1c66c49002d651206752f14 to your computer and use it in GitHub Desktop.
Save njjerrysmith/dc8d52a1a1c66c49002d651206752f14 to your computer and use it in GitHub Desktop.
TextExpander Javascript Markdown Table Generator
var rows = Number(%filltext:name=bodyrows:default=2:width=5%); //body of table rows
var cols = Number(%filltext:name=cols:default=4:width=5%); //columns of table
var rows = rows + 2; //add a rows to account for header and seperator
var text = ''; //variable to store the output
for (rCount = 1; rCount <= rows; rCount++) {
for (cCount = 1; cCount <= cols; cCount++) {
if (rCount == 1) { // Header Row Output
if (cCount == 1) {
text += '**%|** |';
}
else if (cCount == cols) {
text += ' **Header**';
}
else {
text += ' **Header** |';
}
}
else if (rCount == 2) { // seperator row output
if (cCount == 1) {
text += '-- |';
}
else if (cCount == cols) {
text += ' --';
}
else {
text += ' -- |';
}
}
else { //content row outputs
if (cCount == 1) {
text += (rCount-2).toString() + 'x' + cCount.toString() + ' |';
}
else if (cCount == cols) {
text += ' ' + (rCount-2).toString() + 'x' + cCount.toString();
}
else {
text += ' ' + (rCount-2).toString() + 'x' + cCount.toString() + ' |';
}
}
}
text += '\n';
}
TextExpander.appendOutput(text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment