micromarkdown
Version:
converts markdown to html
175 lines (145 loc) • 6.5 kB
HTML
<html>
<head>
<meta charset="utf-8">
<title>micromarkdown.js</title>
<link href="./style.css" rel="stylesheet" type="text/css">
<link href="./mmd.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="./micromarkdown.js"></script>
<!--<script type="text/javascript" src="./dist/micromarkdown.min.js"></script>-->
<script>
function parseMD() {
if (document.getElementById('htmlcb').checked !== false) {
document.getElementById('htmlexport').className = 'source';
document.getElementById('htmlexport').innerHTML = micromarkdown.htmlEncode(micromarkdown.parse(document.getElementById('md').value));
} else {
document.getElementById('htmlexport').className = 'preview';
document.getElementById('htmlexport').innerHTML = micromarkdown.parse(document.getElementById('md').value);
}
}
function resizeTA() {
var parent, child, width, height;
parent = document.getElementById('markdown');
child = document.getElementById('md');
height = parent.clientHeight-50;
width = parent.clientWidth-50;
child.style.height = height+'px';
child.style.width = width+'px';
}
window.onload = function() {
input = document.getElementById('defaultmd').innerHTML.split('<!--')[1].split('-->')[0];
document.getElementById('md').value = input;
micromarkdown.useajax = function() {
parseMD();
};
if(window.attachEvent) {
window.attachEvent('onresize', function() {
resizeTA();
});
}
else if(window.addEventListener) {
window.addEventListener('resize', function() {
resizeTA();
}, true);
}
parseMD();
resizeTA();
}
</script>
</head>
<body>
<a class="ribbon" href="https://github.com/SimonWaldherr/micromarkdown.js" target="_blank">
<img alt="Fork micromarkdown.js on GitHub" src="http://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png">
</a>
<div id="html">
<input name="htmlcb" id="htmlcb" type="checkbox" onchange="javascript:parseMD();"><label for="htmlcb">‹/›</label>
</div>
<table id="table">
<tr>
<th>markdown</th><th>preview</th>
</tr>
<tr>
<td id="markdown"><textarea id="md" onkeyup="javascript:parseMD();"></textarea></td>
<td id="htmlexport"></td>
</tr>
</table>
<code id="defaultmd">
<!--
#
a tiny script to convert [markdown](http://en.wikipedia.org/wiki/Markdown) to [HTML](http://en.wikipedia.org/wiki/HTML) in under 5kb and under [MIT License](http://opensource.org/licenses/MIT).
```
[howto make a link in markdown](http://example.tld/)
```
[Lorem ipsum](http://en.wikipedia.org/wiki/Lorem_ipsum) **dolor** sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea **commodo** consequat. Duis *aute **irure dolor** in* reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint **occaecat cupidatat** non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo ~~inventore~~ inventari veritatis et quasi ***architecto beatae vitae dicta*** sunt, explicabo.
1. At vero eos et accusamus et iusto odio dignissimos ducimus
1. Qui blanditiis praesentium voluptatum deleniti atque corrupti
* Quos dolores et quas molestias excepturi sint
* Obcaecati *cupiditate **non** provident*
* Et harum quidem rerum facilis est et expedita distinctio
1. Neque porro quisquam
2. est qui dolorem ipsum
3. quia dolor sit amet
4. consectetur adipisci velit
1. Quis autem vel eum iure reprehenderit
1. qui in ea voluptate velit esse
Quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?
The previous text is only a lorem ipsum **placeholder text** to demonstrate **µmarkdown.js**. You can take a look at the code at <https://github.com/SimonWaldherr/micromarkdown.js> or view some of my other projects on [my GitHub page](https://github.com/SimonWaldherr/).
---
as an example of what you can do with markdown, here is a nice table:
this | *left* | center | right
-----|:-------|:--------:|------:
with | sample | content | for
lorem| ipsum | dolor | sit
sit | amet | sed | do
do | eiusom | tempor | with
you can also write down code-examples in markdown:
```
var md = document.getElementById("md").value,
html = micromarkdown.parse(md);
```
or include content from [other sources][source] *(this is only possible with micromarkdown)*:
[source]: http://cdn.simon.waldherr.eu/projects/majaX/content/data.csv
<include csv from http://cdn.simon.waldherr.eu/projects/majaX/content/data.csv>
to include µmarkdown on your page add
```
<script type="text/javascript"
src="http://simonwaldherr.github.io/micromarkdown.js/micromarkdown.js">
</script>
```
to your HTML Head and than use
```
var input = document.getElementById('input').value,
outputEle = document.getElementById('outEle');
outputEle.innerHTML = micromarkdown.parse(input);
```
to convert markdown to html.
please take a look at some of my other projects:
* [selfCSS](http://selfcss.org/)
* [PodloveWebPlayer](http://podlove.org/podlove-web-player/)
* [Shownot.es](http://shownot.es/)
* [FAMOUS](http://famous-project.org/)
* and many more on [github.com](https://github.com/SimonWaldherr?tab=repositories)
you can find me on:
* App.net @SimonWaldherr@adn
* Twitter @SimonWaldherr@t
* GitHub @SimonWaldherr@gh
* Facebook @SimonWaldherr@fb
* Google+ @SimonWaldherr@gp
most markdown scripts also allow to include HTML:
---
<span style="position:absolute;right:25px;">micromarkdown.js</span>
-->
</code>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33526676-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>