This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
209 lines (196 loc) · 8.04 KB
/
index.php
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
declare(strict_types = 1);
/*
* AUTHOR : AVONTURE Christophe
*
* Written date : 3 october 2018
*
* Excel raw table to markdown converter
* Simply copy, from Excel, a table and paste here to convert
* table to markdown
*
* The javascript has been written by `Jonathan Hoyt` and available on GitHub:
* https://github.com/jonmagic/copy-excel-paste-markdown.
*
* JS script updated to:
* - Call marked.js (https://www.npmjs.com/package/marked) to render the table from markdown
* to html
* - Add bootstrap class to the rendered table
*
* Last mod:
* 2019-01-01 - Abandonment of jQuery and migration to vue.js
*/
define('REPO', 'https://github.com/cavo789/marknotes_xls2md');
// Get the GitHub corner
$github = '';
if (is_file($cat = __DIR__ . DIRECTORY_SEPARATOR . 'octocat.tmpl')) {
$github = str_replace('%REPO%', REPO, file_get_contents($cat));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="author" content="Christophe Avonture" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
<title>Marknotes - XLS2MD - Convert Excel raw table to Markdown table</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<style>
textarea {
margin-top:10px;
font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
}
details {
margin: 1rem;
}
summary {
font-weight: bold;
}
.form-control {
padding: none;
font-size: 0.8em;
}
</style>
</head>
<body>
<?php echo $github; ?>
<div class="container">
<div class="page-header"><h1>Marknotes - XLS2MD</h1></div>
<div class="container" id="app">
<div class="form-group">
<how-to-use demo="https://raw.githubusercontent.com/cavo789/marknotes_xls2md/master/image/demo.gif">
<ol>
<li>In your Excel worksheet, select a range like f.i.
$A$1:$H:$25 (first row need to contains column's headings).</li>
<li>Press <kbd>CTRL</kbd><kbd>C</kbd></li>
<li>In this form, click in the text area here below</li>
<li>Press <kbd>CTRL</kbd><kbd>V</kbd></li>
</ol>
<p>The copied data will be immediately converted to a markdown table
and a HTML preview will be rendered.</p>
<p>Adjust the markdown syntax if needed and copy/paste into your
notes.</p>
</how-to-use>
<label for="editor">Simply copy, from Excel, a table and paste here to convert
table to markdown.</label>
<textarea class="form-control" rows="5" v-model="editor" name="editor" @change="onChange" @paste="onPaste"></textarea>
</div>
<hr/>
<div v-if="Markdown!==''">
<h2 id="markdown">Markdown code <small style="font-size:0.4em"><a href="#html">See HTML rendering</a></small></h2>
<pre v-html="Markdown"></pre>
<hr/>
</div>
<div v-if="HTML!==''">
<h2 id="html">HTML rendering <small style="font-size:0.4em"><a href="#markdown">See Markdown code</a></small></h2>
<pre v-html="HTML"></pre>
<hr/>
</div>
</div>
</div>
<script src="https://unpkg.com/vue@2"></script>
<script src="https://unpkg.com/marked@0.3.6"></script>
<script type="text/javascript">
function columnWidth(rows, columnIndex) {
return Math.max.apply(
null,
rows.map(function(row) {
return row[columnIndex].length;
})
);
}
function getMarkdown(data) {
var rows = data.split(/[\n\u0085\u2028\u2029]|\r\n?/g).map(function(row) {
return row.split("\t");
});
var columnWidths = rows[0].map(function(column, columnIndex) {
return columnWidth(rows, columnIndex);
});
var markdownRows = rows.map(function(row, rowIndex) {
// | Name | Title | Email Address |
// |--------------|-------|----------------|
// | Jane Atler | CEO | jane@acme.com |
// | John Doherty | CTO | john@acme.com |
// | Sally Smith | CFO | sally@acme.com |
return (
"| " +
row
.map(function(column, index) {
return (
column + Array(columnWidths[index] - column.length).join(" ")
);
})
.join(" | ") +
" |"
);
row.map;
});
markdownRows.splice(
1,
0,
"| " +
columnWidths
.map(function(width, index) {
return Array(columnWidths[index]).join("-");
})
.join(" | ") +
" |"
);
// Get the markdown representation of the pasted info
return markdownRows.join("\n");
}
Vue.component('how-to-use', {
props: {
demo: {
type: String,
required: true
}
},
template:
`<details>
<summary>How to use?</summary>
<div class="row">
<div class="col-sm">
<slot></slot>
</div>
<div class="col-sm"><img v-bind:src="demo" alt="Demo"></div>
</div>
</div>
</details>`
});
var app = new Vue({
el: '#app',
data: {
editor: '',
Markdown: ''
},
methods: {
onChange(event) {
this.Markdown = getMarkdown(this.editor);
},
onPaste(event) {
event.preventDefault();
var clipboard = event.clipboardData;
this.editor = clipboard.getData("text/plain").trim();
this.Markdown = getMarkdown(this.editor);
}
},
computed: {
HTML() {
if (this.Markdown == '') {
return '';
}
// Call marked() to convert the MD string into a HTML table
var mdTable = marked(this.Markdown, { sanitize: true });
// Add Boostrap classes
mdTable = mdTable.replace('<table>', '<table class="table table-hover table-striped">');
return mdTable;
}
}
});
</script>
</body>
</html>