-
Notifications
You must be signed in to change notification settings - Fork 1
/
autoformat.html
89 lines (82 loc) · 3.78 KB
/
autoformat.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://github.com/stan-dev/stanc3/releases/download/nightly/stanc.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="prism/prism.css">
<link rel="stylesheet" href="https://prismjs.com/plugins/line-numbers/prism-line-numbers.css">
<link rel="stylesheet" href="prism/prism-live.css">
<link rel="stylesheet" href="style.css">
<script src="demo.js"></script>
</head>
<body>
<main>
<div class="page-links"><a href="index.html">Print C++</a></div>
<div class="page-links"><a href="pedantic.html">Pedantic check</a></div>
<div class="page-links"><a href="signatures.html">Supported signatures</a></div>
<div class="page-links"><a href="optimization.html">Optimization diff</a></div>
<div class="page-links selected-link"><a class="selected" href="autoformat.html">Auto format</a></div>
<div class="page-links"><a href="canonicalizer.html">Canonicalizer</a></div>
<div style="clear:both;"></div>
<textarea id="model" class="prism-live line-numbers language-stan" spellcheck="false"></textarea>
<div class="buttons">
<div class="action_btn">
<button id="compile" class="action_btn submit">Auto-format</button>
<button id="url" class="action_btn cancel">Generate URL</button>
Line length limit: <input type="number" id="line-length" value="78" style="width: 60px;" />
<p id="saved"></p>
</div>
</div>
<div id="url-box" class="error-box"></div>
<div id="error" class="error-box"></div>
<pre><code id = "result" class="language-stan"></code></pre>
</main>
</body>
<script>
function auto_format(line_length) {
let line_length_arg = "max-line-length=" + line_length.toString()
var model = stanc("test_model", $("#model").val(), ["auto-format", line_length_arg]);
if (model.errors) {
$("#error").html(model.errors[1].replace(/\n/g, "<br/>").replace(/\s/g, ' '));
$("#result").html("");
} else {
$("#result").html(Prism.highlight(model.result, Prism.languages.stan, 'stan'));
$("#error").html("");
}
}
$(document).ready(function () {
let model_url = GetURLParameter("model")
let line_length = GetURLParameter("line_length")
if (!line_length) {
line_length = 78
} else {
$("#line-length").val(line_length)
}
let model = "dHJhbnNmb3JtZWQgZGF0YXsKcmVhbCBtID0gMDsKZm9yKGkgaW4gMTo1KQp7Cm0gKz0gMS4xKiBpOwp9Cn0KcGFyYW1ldGVycyB7CnJlYWwKeTsgLy8gY29tbWVudAp9Cm1vZGVsIHsKeQp%2BIHN0ZF9ub3JtYWwoKTsKfQ%3D%3D"
if (model_url) {
model = model_url
}
decoded_model = atob(decodeURIComponent(model))
$("#model").val(decoded_model)
$("code", $("#model").prev()).html(decoded_model)
Prism.highlightAll()
$("#model").focus(function () {
$("#url-box").html("");
})
$("#compile").click(function () {
line_length = $("#line-length").val()
auto_format(line_length);
});
auto_format(line_length);
$("#url").click(function () {
let url = window.location.href.split('?')[0] + "?line_length=" + $("#line-length").val() + "&model=" + encodeURIComponent(btoa($("#model").val()))
$("#url-box").html(url);
});
});
</script>
<script src="https://blissfuljs.com/bliss.shy.min.js"></script>
<script src="prism/prism.js"></script>
<script src="https://prismjs.com/plugins/line-numbers/prism-line-numbers.js"></script>
<script src="prism/prism-live.js"></script>
</html>