forked from AnnatarHe/AnnatarHe.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler-to-github-markdown.html
67 lines (61 loc) · 2.49 KB
/
compiler-to-github-markdown.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>compiler to github markdown</title>
<link href="https://cdn.bootcss.com/semantic-ui/2.1.6/semantic.min.css" rel="stylesheet">
</head>
<body>
<div class="ui grid container">
<div class="row">
<div class="column">
<div class="ui message">
<h1 class="ui header">jekyll博客代码转换器</h1>
<p>简单的通过js将jekyll博客中的代码段转换为github所可以识别的内容</p>
</div>
</div>
</div>
</div>
<div class="container four ui two column doubling grid">
<div class="column">
<div class="ui form">
<div class="field">
<label for="text">转换的内容</label>
<textarea id="src" rows="100"></textarea>
</div>
</div>
</div>
<div class="column">
<div id="dist_container" class="ui padded segment piled">
<div class="ui form">
<div class="field">
<textarea id="dist" rows="100"></textarea>
</div>
</div>
<button class="ui primary button" data-clipboard-target="#dist">复制</button>
</div>
</div>
</div>
<script type="text/javascript" src="https://cdn.bootcss.com/clipboard.js/1.5.5/clipboard.min.js"></script>
<script>
'use strict';
document.addEventListener('DOMContentLoaded', () => {
let hightlight = /\{% highlight (\w+) %\}/g;
let endhighlight = /\{% endhighlight %\}/g;
let n = /\n/g;
let space = / /g;
let src = document.querySelector('#src');
let dist = document.querySelector('#dist');
src.addEventListener('input', () => {
let content = src.value
.replace(hightlight, '```$1')
.replace(endhighlight, '```\n');
// .replace(n, '<br/>')
// .replace(space, ' ');
console.log(content);
dist.value = content;
});
});
</script>
</body>
</html>