Created
October 6, 2014 19:53
-
-
Save JosePedroDias/a4627af7ed70528884fb to your computer and use it in GitHub Desktop.
commonmark usage demo // source http://jsbin.com/fegihu/5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>commonmark usage demo</title> | |
<script src="http://jgm.github.io/stmd/js/stmd.js"></script> | |
<style id="jsbin-css"> | |
* { box-sizing: border-box } | |
body { | |
font-family: sans-serif; | |
height: 100%; | |
overflow: hidden; | |
padding: 0; | |
margin: 0; | |
} | |
#in, | |
#out { | |
position: fixed; | |
width: 50%; | |
height: 100%; | |
top: 0; | |
padding: 10px; | |
} | |
#in { | |
left: 0; | |
background-color: #EEF; | |
border-width: 0; | |
} | |
#out { | |
right: 0; | |
background-color: #EFE; | |
} | |
#in:after, | |
#out:after { | |
position: absolute; | |
right: 0; | |
top: 0; | |
color: #000; | |
z-index: 1; | |
font-weight: bold; | |
padding: 2px 4px; | |
background: #FFF; | |
} | |
#in:after { | |
content: 'MARKDOWN'; | |
} | |
#out:after { | |
content: 'HTML'; | |
} | |
</style> | |
</head> | |
<body> | |
<textarea id="in" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"># commonmark usage demo | |
[commonmark](http://commonmark.org/) fixes unifies markdown parsing. | |
To use it on your page: | |
1. insert script on head; | |
1. insert script snippet on body; | |
1. call markdown2html to convert markdown to html. | |
## 1) stmd.js script | |
script src="http://jgm.github.io/stmd/js/stmd.js" | |
## 2) snippet | |
``` | |
(function() { | |
var writer = new stmd.HtmlRenderer(); | |
var reader = new stmd.DocParser(); | |
window.markdown2html = function(md) { | |
var parsed = reader.parse(md); | |
return writer.renderBlock(parsed); | |
}; | |
})(); | |
``` | |
## 3) get HTML out | |
``` | |
var md = '# hi\n* one\n* two'; | |
var html = markdown2html(md); | |
alert(html); // should output h1 and 2 ul grouped lis. | |
```</textarea> | |
<div id="out"></div> | |
<script id="jsbin-javascript"> | |
// the markdown magic | |
(function() { | |
var writer = new stmd.HtmlRenderer(); | |
var reader = new stmd.DocParser(); | |
window.markdown2html = function(md) { | |
var parsed = reader.parse(md); | |
return writer.renderBlock(parsed); | |
}; | |
})(); | |
// gluing it to the demo | |
var inEl = document.getElementById('in'); | |
var outEl = document.getElementById('out'); | |
var update = function() { | |
outEl.innerHTML = markdown2html(inEl.value); | |
}; | |
update(); | |
// TODO this could be throttled | |
window.addEventListener('keyup', update); | |
</script> | |
<script id="jsbin-source-css" type="text/css">* { box-sizing: border-box } | |
body { | |
font-family: sans-serif; | |
height: 100%; | |
overflow: hidden; | |
padding: 0; | |
margin: 0; | |
} | |
#in, | |
#out { | |
position: fixed; | |
width: 50%; | |
height: 100%; | |
top: 0; | |
padding: 10px; | |
} | |
#in { | |
left: 0; | |
background-color: #EEF; | |
border-width: 0; | |
} | |
#out { | |
right: 0; | |
background-color: #EFE; | |
} | |
#in:after, | |
#out:after { | |
position: absolute; | |
right: 0; | |
top: 0; | |
color: #000; | |
z-index: 1; | |
font-weight: bold; | |
padding: 2px 4px; | |
background: #FFF; | |
} | |
#in:after { | |
content: 'MARKDOWN'; | |
} | |
#out:after { | |
content: 'HTML'; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// the markdown magic | |
(function() { | |
var writer = new stmd.HtmlRenderer(); | |
var reader = new stmd.DocParser(); | |
window.markdown2html = function(md) { | |
var parsed = reader.parse(md); | |
return writer.renderBlock(parsed); | |
}; | |
})(); | |
// gluing it to the demo | |
var inEl = document.getElementById('in'); | |
var outEl = document.getElementById('out'); | |
var update = function() { | |
outEl.innerHTML = markdown2html(inEl.value); | |
}; | |
update(); | |
// TODO this could be throttled | |
window.addEventListener('keyup', update); | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { box-sizing: border-box } | |
body { | |
font-family: sans-serif; | |
height: 100%; | |
overflow: hidden; | |
padding: 0; | |
margin: 0; | |
} | |
#in, | |
#out { | |
position: fixed; | |
width: 50%; | |
height: 100%; | |
top: 0; | |
padding: 10px; | |
} | |
#in { | |
left: 0; | |
background-color: #EEF; | |
border-width: 0; | |
} | |
#out { | |
right: 0; | |
background-color: #EFE; | |
} | |
#in:after, | |
#out:after { | |
position: absolute; | |
right: 0; | |
top: 0; | |
color: #000; | |
z-index: 1; | |
font-weight: bold; | |
padding: 2px 4px; | |
background: #FFF; | |
} | |
#in:after { | |
content: 'MARKDOWN'; | |
} | |
#out:after { | |
content: 'HTML'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the markdown magic | |
(function() { | |
var writer = new stmd.HtmlRenderer(); | |
var reader = new stmd.DocParser(); | |
window.markdown2html = function(md) { | |
var parsed = reader.parse(md); | |
return writer.renderBlock(parsed); | |
}; | |
})(); | |
// gluing it to the demo | |
var inEl = document.getElementById('in'); | |
var outEl = document.getElementById('out'); | |
var update = function() { | |
outEl.innerHTML = markdown2html(inEl.value); | |
}; | |
update(); | |
// TODO this could be throttled | |
window.addEventListener('keyup', update); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment