-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
56 lines (53 loc) · 2.07 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>regex2dfa</title>
<link rel="stylesheet" type="text/css" href="assets/main.css">
<link rel="stylesheet" type="text/css" href="assets/gh-fork-ribbon.css">
<script src="assets/regex2dot.js"></script>
<script src="assets/viz.js"></script>
<script src="assets/lite.render.js"></script>
<script>
const viz = new Viz();
const render = async () => {
const regex = document.getElementById('regex').value;
const dot = Module.regex2dot(regex);
const svg = (await viz.renderSVGElement(dot)).outerHTML;
document.getElementById('dfa').innerHTML = svg;
document.getElementById('button').style.display = 'block';
document.getElementById('getDot').setAttribute('download', 'dfa.dot');
document.getElementById('getDot').setAttribute('href', 'data:text/vnd.graphviz;charset=utf-8,' + dot);
document.getElementById('getSvg').setAttribute('download', 'dfa.svg');
document.getElementById('getSvg').setAttribute('href', 'data:image/svg+xml;charset=utf-8,' + escape(svg));
};
window.onload = () => {
const url = new URL(window.location.href);
let param = url.searchParams.get('regex');
if (param === null)
param = '(a|b)?(b|c)(c|d)*(d|e)(e|f)+(f|g)';
document.getElementById('regex').value = param;
};
</script>
</head>
<body>
<input id="regex" type="text" placeholder="regular expression here"
onkeypress="if(event.keyCode===13) render()"></input>
<div id="button">
<a id="getDot">DOT</a>
<a id="getSvg">SVG</a>
</div>
<div id="dfa">
⇪ <em>input regular expression here and press enter.</em> ⇪
<br>
<br>
Only concatenation, alternation (<code>|</code>), Kleene star(<code>*</code>), and metacharacters <code>?</code>,
<code>+</code> are supported.
</div>
<div class="github-fork-ribbon-wrapper left-bottom">
<div class="github-fork-ribbon">
<a href="https://github.com/nerdDan/RegEx2DFA" rel="noopener noreferrer" target="_blank">Fork me on GitHub</a>
</div>
</div>
</body>
</html>