forked from donatj/CsvToMarkdownTable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
104 lines (89 loc) · 2.96 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
<html>
<style type="text/css">
textarea {
font-family: monospace;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools-yui-compressed.js"></script>
<script src="src/CsvToMarkdown.js"></script>
<script>
"use strict";
window.addEvent('domready', 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 = $('tsv-input');
var output = $('table-output');
var headerCheckbox = $('has-headers');
var delimiterMarker = $('delimiter-marker');
var getDelimiter = function() {
var delim = delimiterMarker.get('value');
if( delim == 'tab' ) {
delim = "\t";
}
return delim;
};
var populateData = $('populate-data');
input.addEvent('keydown', function( e ) {
if( e.key == 'tab' ) {
e.stop();
insertAtCursor(e.target, "\t");
}
});
var renderTable = function() {
var value = input.get('value').trim();
var hasHeader = headerCheckbox.get('checked');
output.set('value', csvToMarkdown(value, getDelimiter(), hasHeader));
};
input.addEvent('keyup', renderTable);
headerCheckbox.addEvent('change', renderTable);
delimiterMarker.addEvent('change', renderTable);
populateData.addEvent('change', function() {
input.set('value', populateData.get('value').split("|").join(getDelimiter()) + "\n");
headerCheckbox.set('checked', 'checked');
populateData.selectedIndex = 0;
renderTable();
if( typeof input.selectionStart != 'undefined' ) {
input.select();
input.selectionEnd = input.selectionStart = input.get('value').length;
}
});
output.addEvent('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>