Skip to content

Instantly share code, notes, and snippets.

@matobaa
Created February 13, 2019 12:31
Show Gist options
  • Save matobaa/e946bece68e82fa6b9db3313df996bc9 to your computer and use it in GitHub Desktop.
Save matobaa/e946bece68e82fa6b9db3313df996bc9 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Marked reader</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />
<script src="js/marked.js"></script>
</head>
<body>
<div id="debug"></div>
<div id="placeholder"></div>
<script>
if (!String.prototype.wikify) {
String.prototype.wikify = function () { // transform [word] to link
// return this.replace(/([^A-Za-z0-9_[])([A-Z][a-z]+([A-Z][a-z]+)+)/g, '$1<a href="#$2.md">$2</a>');
return this.replace(/\[([^\]]+)\]/g, '<a class="wikiname" href="#$1.md">$1</a>')
}
}
window.onhashchange = function (e) {
var xhr = null
var hash = window.location.hash.substr(1)
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { xhr = new XMLHttpRequest(); }
xhr.open('GET', hash, true);
xhr.onreadystatechange = function (e) {
if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
document.getElementById('placeholder').innerHTML = marked(xhr.responseText.replace(/[^(]*.md/g, '#$0'))
.wikify()
}
}
try {
xhr.send(null);
} catch (e) {
document.getElementById('placeholder').innerHTML = marked('<div>404 not found<br/>' + e + hash + '<br/><a href="#index.md">return</a></div>');
}
}
document.location.hash ? window.onhashchange() : document.location.hash = '#index.md'
</script>
</body>
</html>
@matobaa
Copy link
Author

matobaa commented Mar 19, 2019

see also: mdwiki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment