-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
example.html
106 lines (88 loc) · 3 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<html>
<style type="text/css">
textarea {
font-family: monospace;
}
</style>
<script src="lib/CsvToMarkdown.js"></script>
<script>
"use strict";
window.addEventListener('DOMContentLoaded', function () {
var insertAtCursor = function (myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
myField.selectionEnd = myField.selectionStart = startPos + myValue.length;
} else {
myField.value += myValue;
}
};
var input = document.getElementById('tsv-input');
var output = document.getElementById('table-output');
var headerCheckbox = document.getElementById('has-headers');
var delimiterMarker = document.getElementById('delimiter-marker');
var getDelimiter = function () {
var delim = delimiterMarker.value;
if (delim == 'tab') {
delim = "\t";
}
return delim;
};
var populateData = document.getElementById('populate-data');
input.addEventListener('keydown', function (e) {
if (e.key.toLowerCase() == 'tab') {
e.preventDefault();
insertAtCursor(e.target, "\t");
}
});
var renderTable = function () {
var value = input.value.trim();
var hasHeader = headerCheckbox.checked;
output.value = csvToMarkdown(value, getDelimiter(), hasHeader);
};
input.addEventListener('keyup', renderTable);
headerCheckbox.addEventListener('change', renderTable);
delimiterMarker.addEventListener('change', renderTable);
populateData.addEventListener('change', function () {
input.value = populateData.value.split("|").join(getDelimiter()) + "\n";
headerCheckbox.checked = true;
populateData.selectedIndex = 0;
renderTable();
if (typeof input.selectionStart != 'undefined') {
input.select();
input.selectionEnd = input.selectionStart = input.value.length;
}
});
output.addEventListener('click', function (e) {
e.target.select();
});
renderTable();
});
</script>
<body>
<textarea style="width: 100%; height: 200px;" id="tsv-input"></textarea>
<label><input type="checkbox" id="has-headers" /> Use first line as headers</label>
<select id="delimiter-marker">
<option value="tab">Tab Separated</option>
<option value=",">Comma Separated</option>
<option value=";">Semicolon Separated</option>
</select>
<select id="populate-data">
<option>-- Populate With --</option>
<option value="id|select_type|table|type|possible_keys|key|key_len|ref|rows|extra">MySQL EXPLAIN Headers</option>
<option value="id|select_type|table|type|possible_keys|key|key_len|ref|rows|filtered|extra">MySQL EXPLAIN EXTENDED
Headers
</option>
</select>
<hr>
<textarea style="width: 100%; height: 200px;" id="table-output" readonly></textarea>
</body>
</html>