marked/docs/index.html

172 lines
4.7 KiB
HTML
Raw Normal View History

2018-03-11 18:43:26 -04:00
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Marked.js Documentation</title>
<style>
body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
font-size: 16px;
line-height: 1.5;
word-wrap: break-word;
}
#container {
2018-03-22 14:22:57 -05:00
position: relative;
2018-03-11 18:43:26 -04:00
max-width: 800px;
margin: auto;
padding: 10px;
border: 1px solid #ddd;
border-radius: 3px;
}
header { display: flex; }
header h1 { margin: 0; }
table {
border-spacing: 0;
border-collapse: collapse;
border: 1px solid #ddd;
}
td, th {
border: 1px solid #ddd;
padding: 5px;
}
a {
color: #0366d6;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
pre {
font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f6f8fa;
border-radius: 3px;
}
code:not([class]) {
padding: 0.2em 0.4em;
margin: 0;
font-size: 85%;
background-color: rgba(27,31,35,0.05);
border-radius: 3px;
}
2018-03-22 14:22:57 -05:00
.github-ribbon {
position: absolute;
top: 0;
right: 0;
border: 0;
}
2018-03-11 18:43:26 -04:00
</style>
</head>
<body>
<div id="container">
<header>
2018-03-27 14:06:54 -05:00
<a href="#/README.md">
2018-03-22 13:49:47 -05:00
<img src="img/logo-black.svg" height="64px" width="64px" />
</a>
2018-03-11 18:43:26 -04:00
<h1>Marked.js Documentation</h1>
</header>
2018-03-22 13:49:47 -05:00
2018-03-22 14:22:57 -05:00
<a href="https://github.com/markedjs/marked">
<img class="github-ribbon" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub">
</a>
2018-03-11 18:43:26 -04:00
<div id="content"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.js"></script>
<script src="https://cdn.jsdelivr.net/npm/unfetch/dist/unfetch.umd.js"></script>
<script>
2018-03-26 10:43:37 -05:00
if (!window.Promise) {
window.Promise = ES6Promise;
}
if (!window.fetch) {
window.fetch = unfetch;
}
2018-03-27 10:19:31 -05:00
var content = document.querySelector('#content');
var body = document.querySelector('html');
2018-03-27 10:34:52 -05:00
var currentPage = 'README.md';
2018-03-27 10:19:31 -05:00
var currentHash = '';
2018-03-27 10:34:52 -05:00
var renderedPage = '';
2018-03-26 11:01:33 -05:00
2018-03-27 10:34:52 -05:00
function hashChange() {
2018-03-27 10:19:31 -05:00
var hash = location.hash.slice(1);
if (!hash) {
hash = 'README.md';
2018-03-26 11:01:33 -05:00
}
2018-03-27 10:19:31 -05:00
var uri = hash.split('#');
2018-03-11 18:43:26 -04:00
2018-03-27 14:06:54 -05:00
if (uri[0].match(/^\//)) {
currentPage = uri[0].slice(1);
2018-03-27 10:19:31 -05:00
if (uri.length > 1) {
currentHash = uri[1];
} else {
currentHash = '';
2018-03-11 18:43:26 -04:00
}
2018-03-27 10:19:31 -05:00
} else {
currentHash = uri[0];
2018-03-11 18:43:26 -04:00
}
2018-03-27 10:19:31 -05:00
2018-03-27 14:06:54 -05:00
fetchPage(currentPage).then(function () {
fetchAnchor(currentHash)
});
2018-03-27 10:34:52 -05:00
2018-03-27 14:06:54 -05:00
history.replaceState('', document.title, '#/' + currentPage + (currentHash ? '#' + currentHash : ''));
2018-03-27 10:19:31 -05:00
}
2018-03-27 14:06:54 -05:00
function fetchAnchor(anchor) {
if (!anchor) {
return;
}
var hashElement = document.getElementById(anchor);
if (hashElement) {
hashElement.scrollIntoView();
}
}
2018-03-11 18:43:26 -04:00
function fetchPage(page) {
2018-03-27 10:34:52 -05:00
if (page === renderedPage) {
return Promise.resolve();
}
2018-03-26 11:01:33 -05:00
return fetch(page)
2018-03-27 10:52:41 -05:00
.then(function (res) {
if (!res.ok) {
throw new Error('Error ' + res.status + ': ' + res.statusText);
}
return res.text();
})
2018-03-26 10:43:37 -05:00
.then(function (text) {
2018-03-27 10:34:52 -05:00
renderedPage = page;
2018-03-11 18:43:26 -04:00
content.innerHTML = marked(text);
body.scrollTop = 0;
2018-03-26 10:43:37 -05:00
}).catch(function (e) {
2018-03-11 18:43:26 -04:00
content.innerHTML = '<p>Oops! There was a problem rendering the page.</p>'
+ '<p>' + e.message + '</p>';
});
}
2018-03-22 14:22:57 -05:00
2018-03-27 14:06:54 -05:00
window.addEventListener('hashchange', function (e) {
e.preventDefault();
hashChange();
});
2018-03-27 10:19:31 -05:00
hashChange();
2018-03-11 18:43:26 -04:00
</script>
</body>
2018-03-22 14:22:57 -05:00
</html>