JSFiddle - React, Tailwind, and code Playground
by epinapala
HTML
<textarea class="text_edit" id="wikiText" rows="20" cols="40"></textarea>
JavaScript
var textArea = document.getElementById('wikiText');
textArea.value = createWikiTable(3, 3, "Example");
function createWikiTable(rows, cols, exampleText, headerText) {
var br = "\n";
var table = "{|" + br;
for (i = 0; i < rows; i++) {
if (headerText && i == 0) {
table = table + "|- " + br;
table = table + "! ";
for (j = 0; j < cols; j++) {
table = table + headerText + " ";
if (j < (cols - 1)) {
table = table + "!!" + " ";
} else {
table = table + br;
}
}
}
table = table + "|- " + br;
table = table + "| ";
for (j = 0; j < cols; j++) {
table = table + exampleText + " ";
if (j < (cols - 1)) {
table = table + "||" + " ";
} else {
table = table + br;
}
}
}
table = table + "|}";
return table;
}