-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
279 lines (242 loc) · 8.89 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Markdown Viewer</title>
<meta name="version" content="9.1">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="assets/libs.js"></script>
<script type="text/javascript" src="assets/w3.js"></script>
</head>
<body>
<footer>
<!-- COPYRIGHT SECTION BEGIN -->
<!--
IMPORTANT:
Please, do not modify the copyright section.
The copyright parts of the markdown viewer software is about the technical software itself, not the markdown contents that it renders.
(The copyright fragments are not rendered in printing mode.)
As the credit goes to the team who have put time/effort to develop the tool, their names should not be removed.
Based on the license, the tool can be used/distributed while respecting the copyright notice.
More people/organization names may be added if they also have a contribution on this tool.
Development repository: https://github.com/ioi-2017/markdown-viewer
-->
<p id="copyright">@copyright IOI 2017</p>
<div class="credit" id="credit-container" style="width: 420px;">
<div style="width: 100%; margin-bottom: 6px;">
<div style="width: 100%; text-align: left;">
<span style="font-size:20px; font-weight:bold;">
Markdown Viewer
</span>
</div>
<div>
<span style="font-size:14px;">
<span>Version: </span><span id="span_version_content">?</span>
</span>
</div>
</div>
<div>
<p style="font-size:14px; padding:0; padding-right: 15px; text-align:left; margin: 0;">
<span style="font-size:16px; font-weight:bold;">Credits:</span>
<br/>
<a href="http://ioi2017.org/" target="_blank" style="font-size:20px;">IOI 2017 Iran</a>
<br/>
<span style="font-size:16px;">Host Technical Committee</span>
<br/>
Hamid Zarrabi-Zadeh
<br/>
Ali Yadegari
<br/>
Kian Mirjalali
<br/>
Navid Saleh
</p>
</div>
<div style="width:168px; float: right;">
<a href="http://ioi2017.org/" target="_blank">
<img src="assets/IOI-2017.svg" width="100%"/>
</a>
</div>
</div>
<!-- COPYRIGHT SECTION END -->
</footer>
<div id="main" class="markdown-body pdf">
<div w3-include-html="header.html"></div>
<div id="content" class="rendered_content" dir="ltr" lang="en"></div>
<div id="error-message" style="display: none;text-align: center; font-size: 24px;">
# Sorry!
File "`__MD_PLACEHOLDER__`" is not available.
It is either not found in the current directory or could not be opened.
Local HTML file cannot access the markdown file (or any other files in the same directory) in modern browsers due to security reasons.
This was possible in Firefox versions below 68.
There are now two methods to handle this:
## The secure method: HTTP server setup
Run a minimal HTTP server:
* Using node:
* Install [node](https://nodejs.org).
* Install `http-server` by running "`npm install -g http-server`".
* Start the HTTP server by executing "`http-server -p 8000`" in the directory of markdown viewer.
* Using python:
* Install [python 3](https://www.python.org/).
* Start the HTTP server by executing "`python -m http.server 8000`" in the directory of markdown viewer.
Then, open the markdown viewer HTML file using URL "`http://localhost:8000/__DOC_NAME_PLACEHOLDER__.html`".
You can replace 8000 with other available port numbers.
Note that a port number cannot be used more than once simultaneously in different servers.
If it is not pleasant
to run multiple HTTP servers with separate port numbers for rendering different markdown files in several directories,
you can run the HTTP server in a common parent directory,
and open the markdown viewer files with relative addresses,
e.g. "`http://localhost:8000/common/parent/path/to/__DOC_NAME_PLACEHOLDER__.html`".
You can also use browser extensions like
[Web Server for Chrome](https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb).
## The insecure method: Allow accessing local files
** Warning: **
This method makes you vulnerable to attacks from downloaded HTML documents.
** Firefox: **
Open "`about:config`" and accept the risk to edit the configurations.
Search for "`security.fileuri.strict_origin_policy`" and set its value to `false`
(the setting name was "`privacy.file_unique_origin`" in older versions of Firefox).
Other work-around ideas are welcome.
Contact through the issues in [the development repository](https://github.com/ioi-2017/markdown-viewer/).
</div>
<div w3-include-html="footer.html"></div>
</div>
<script>
w3.includeHTML();
var version_meta = document.querySelector('meta[name="version"]');
if (version_meta)
document.getElementById('span_version_content').textContent = version_meta.content;
// Initialize Marked.js Renderer
var renderer = new marked.Renderer();
var original_table_renderer = renderer.table;
// Enable resize option for images
renderer.image = function(href, title, text) {
var tags = '';
if (title) {
size = title.split('x');
if (size[1])
tags = 'width=' + size[0] + ' height=' + size[1];
else
tags = 'width=' + size[0];
} else if (href && href.indexOf('=') != -1) {
size = href.split('=')[1].split('x');
href = href.split('=')[0];
if (size[1])
tags = 'width=' + size[0] + ' height=' + size[1];
else
tags = 'width=' + size[0];
}
return ('<div style="page-break-inside:avoid"><img src="' + href + '" alt="' + text + '" ' + tags + '></div>');
};
renderer.table = function(header, body) {
var html = '';
var tags = 'style="page-break-inside:avoid;"';
if (header.search('%ltr%') < 0) {
tags += ' dir="ltr"';
} else {
header = header.replace('%ltr%', '');
}
html = '<div ' + tags + '>' + original_table_renderer(header, body) + '</div>';
return html;
}
// remove trailing newline in code blocks
renderer.code = function(code, language) {
return ('<pre style="page-break-inside:avoid;"><code>' + code + '</code></pre>');
};
// global options
marked.setOptions({
renderer: renderer,
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
var path = window.location.pathname;
var html = path.split("/").pop();
var docName = html.substr(0, html.lastIndexOf("."));
var md = docName + ".md";
var json_ = docName + ".json";
function renderMarkdownText(text) {
document.getElementById('content').innerHTML = marked(text);
renderMathInElement(document.getElementById('content'));
}
function readTextFile(file, allowingEnv) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4) {
if (rawFile.status === 200) {
renderMarkdownText(rawFile.responseText);
} else if (allowingEnv || (rawFile.status === 404)) {
document.getElementById("error-message").style.display = "block";
document.getElementById("error-message").textContent = "'" + md + "' not found";
} else {
var message = document.getElementById("error-message").textContent;
message = message.replace(/__MD_PLACEHOLDER__/g, md);
message = message.replace(/__DOC_NAME_PLACEHOLDER__/g, docName);
renderMarkdownText(message);
}
}
}
rawFile.send(null);
}
function readJsonProp(file) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
var props = JSON.parse(rawFile.responseText);
Object.keys(props).forEach(function(key) {
var elem = document.getElementById("prop_"+key);
if (elem)
elem.textContent = props[key];
})
document.title = props["html_title"] ? props["html_title"] : "Markdown Viewer";
}
}
}
rawFile.send(null);
}
showingCredit = false;
function showCredit() {
document.getElementById('credit-container').style.display = "block";
showingCredit=true;
}
function hideCredit(e) {
document.getElementById('credit-container').style.display = "none";
showingCredit=false;
}
function toggleCredit() {
if (showingCredit)
hideCredit();
else
showCredit();
}
document.addEventListener('click', function(e) {
if (e.target.id!='copyright')
hideCredit();
else
toggleCredit();
}, false);
function isOldFirefox() {
var ua = window.navigator.userAgent;
if (ua.toLowerCase().indexOf('firefox') <= -1)
return false;
var ua_match = ua.match(/Firefox\/([0-9]+)\./);
var ver = ua_match ? parseInt(ua_match[1]) : 0;
return (ver < 68);
}
function isLocalFile() {
var url = window.location.href.split("/")[0];
return (url == "file:");
}
readTextFile(md, !isLocalFile() || isOldFirefox());
readJsonProp(json_);
</script>
</body>
</html>