-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
199 lines (172 loc) · 8.42 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="css/sticky-footer-navbar.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.11/ace.js" integrity="sha256-Kr5Mbwq/xwJYw6XU4NR519/iosGvECYMyMU8IZ/rQok=" crossorigin="anonymous"></script>
<script src="libraries/vkbeautify.js"></script>
<script src="libraries/style-formatter.js"></script>
<style>
nav {
background-color: #2D98E0;
}
.btn {
white-space: nowrap;
}
</style>
<link rel="icon" type="image/png" href="images/favicon-32x32.png">
<title>CSL Style Formatter</title>
</head>
<body class="d-flex flex-column h-100">
<header>
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark">
<span class="navbar-brand mb-0 h1"><img src="images/logo.svg" width="30" height="30" class="d-inline-block align-middle mr-2" alt="">CSL Style Formatter</span>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="https://citationstyles.org/" target="_blank">CitationStyles.org</a>
</li>
</ul>
</div>
</nav>
</header>
<!-- Begin page content -->
<main role="main" class="flex-shrink-0">
<div class="container-fluid">
<div class="row my-3">
<div class="col-md-8 offset-md-1 alert alert-danger d-none" role="alert" id="alert">
<strong>Error.</strong> Text is invalid XML.
</div>
</div>
<div class="row my-3">
<div class="col-md-8 offset-md-1">
<div id="source-text" class="source-input border" title="The CSL style to reformat."></div>
</div>
</div>
<div class="row my-3">
<div class="col-md-1 offset-md-1">
<button id="doFormat" type="button" class="btn btn-primary btn-lg" data-style="expand-left">Reformat</button>
</div>
<div class="col-md-5 offset-md-2">
<div class="custom-file">
<input type="file" class="custom-file-input" id="fileBrowser">
<label class="custom-file-label" for="fileBrowser" id="fileBrowserLabel">No file selected</label>
</div>
</div>
</div>
<div class="row my-3">
<div class="col-lg-6 offset-lg-1">
<hr>
<h4>About CSL Style Formatter</h4>
<p>The CSL Style Formatter reformats <a href="https://citationstyles.org/" target="_blank">Citation Style Language (CSL)</a> styles according to our
<a href="https://github.com/citation-style-language/styles/" target="_blank">repository</a>
standards and can be used to prepare your style for
<a href="https://github.com/citation-style-language/styles/blob/master/CONTRIBUTING.md#guide-to-submitting-csl-styles-and-csl-locales" target="_blank">submission</a>.
For best results, first make sure your style validates against our <a href="https://validator.citationstyles.org/" target="_blank">CSL style validator</a>.</p>
<p>To use the tool, either paste your XML style code into the editor window above or click the "Browse" button to select a style file on your computer, click the "Reformat" button,
and copy the reformatted style to your destination of choice.</p>
<p>Formatting changes include:</p>
<ul>
<li>Standard indentation</li>
<li>Escaping of certain characters that are hard to identify by eye, like non-breaking spaces and the various dashes</li>
<li>Standard ordering the child elements of <code><info/></code></li>
<li>Standard ordering of attributes on <code><style/></code> and <code><link/></code> elements</li>
</ul>
</div>
</div>
</div>
</main>
<footer class="footer mt-auto py-3">
<div class="container-fluid">
<span class="text-muted">Created by <a href="https://rintze.zelle.me/" target="_blank">Rintze M. Zelle</a> (<a href="https://twitter.com/rintzezelle/" target="_blank"><img src="images/Twitter_Logo_Blue.svg" width="25" height="25"/></a>). Powered by GitHub Pages. <a href="https://github.com/citation-style-language/formatter">Code</a> on GitHub.</span>
</div>
</footer>
<script>
// Initialize Ace editor
window.editor = ace.edit("source-text");
editor.getSession().setUseWrapMode(true);
editor.setHighlightActiveLine(true);
editor.setShowPrintMargin(false);
editor.setTheme("ace/theme/eclipse");
editor.getSession().setMode("ace/mode/xml");
editor.focus();
document.getElementById("doFormat").addEventListener("click", doFormat, false);
var inputElement = document.getElementById("fileBrowser");
inputElement.addEventListener("change", handleFileSelect, false);
function handleFileSelect(event) {
var file = event.target.files[0];
var maxSize = 256; // in kb
var fileSize = file.size; // in bytes
if (fileSize > (maxSize * 1000)){
alert('Selected file is larger than ' + maxSize + ' kb. Did you select a CSL style?');
} else {
var reader = new FileReader();
reader.onload = function(e) {
editor.setValue(e.target.result);
};
reader.readAsText(file);
var browseButton = document.getElementById("fileBrowserLabel");
browseButton.textContent = file.name;
}
}
// Reset button when user changes the editor content
editor.getSession().on('change', function(e) {
var formatButton = document.getElementById("doFormat");
formatButton.setAttribute("class", "btn btn-primary btn-lg");
formatButton.removeAttribute("disabled");
formatButton.textContent = "Reformat";
});
// Always try to keep height of editor maximized
window.addEventListener("load", resizeMe, false);
window.addEventListener("resize", resizeMe, false);
var originalTargetHeight = $("#source-text").height();
function resizeMe() {
$("#source-text").each(function() {
var currentTargetHeight = $(this).height();
var maxBodyHeight = document.documentElement.clientHeight - $("header").height() - $("footer").height();
var currentBodyHeight = document.body.scrollHeight;
var availableBodyHeight = maxBodyHeight - currentBodyHeight;
var newTargetHeight = Math.max(250, currentTargetHeight + availableBodyHeight);
$(this).attr('style', 'height:' + newTargetHeight + 'px;');
editor.resize();
});
}
function doFormat() {
// Hide XML validation error alert
var alertDiv = document.getElementById("alert");
alertDiv.classList.add("d-none");
// Get editor content
var inputString = editor.getValue();
// Reformat style
var outputString;
try {
outputString = formatStyle(inputString);
}
catch(e) {
if (e == "invalidXML") {
var alertDiv = document.getElementById("alert");
alertDiv.classList.remove("d-none");
}
throw "Reformatting error";
}
// Show result and scroll to top of editor
editor.setValue(outputString);
editor.clearSelection();
editor.scrollToLine(0);
editor.navigateFileStart();
editor.focus();
// Disable button on success
var formatButton = document.getElementById("doFormat");
formatButton.setAttribute("class", "btn btn-success btn-lg");
formatButton.setAttribute("disabled", "disabled");
formatButton.textContent = "Reformat Successful";
}
</script>
</body>
</html>