modified data-markdown to support markdown indented with tabs

This commit is contained in:
Hakim El Hattab 2012-07-31 23:47:09 -04:00
parent ff567372c0
commit 0a440cee6c
4 changed files with 19 additions and 13 deletions

View File

@ -28,7 +28,7 @@ Markup heirarchy needs to be ``<div class="reveal"> <div class="slides"> <sectio
It's possible to write your slides using Markdown. To enable Markdown simply add the ```data-markdown``` attribute to your ```<section>``` elements and reveal.js will automatically load the JavaScript parser.
This is based on [data-markdown](https://gist.github.com/1343518) from [Paul Irish](https://github.com/paulirish) which in turn uses [showdown](https://github.com/coreyti/showdown/). Syntax support seems limited judging by my initial tests, this may be due to conflicts with the reveal.js styles. Updates to come.
This is based on [data-markdown](https://gist.github.com/1343518) from [Paul Irish](https://github.com/paulirish) which in turn uses [showdown](https://github.com/coreyti/showdown/). This is sensitive to indentation (avoid mixing tabs and spaces) and line breaks (avoid consecutive breaks). Updates to come.
```html
<section data-markdown>

View File

@ -122,8 +122,8 @@
<section data-markdown>
## Markdown support
For those of you who like that sort of thing. Instructions and a bit more info
available [here](https://github.com/hakimel/reveal.js#markdown).
For those of you who like that sort of thing.
Instructions and a bit more info available [here](https://github.com/hakimel/reveal.js#markdown).
<pre><code contenteditable style="margin-top: 20px;">&lt;section data-markdown&gt;
## Markdown support
@ -326,6 +326,6 @@ function linkify( selector ) {
hljs.initHighlightingOnLoad();
} );
</script>
</body>
</html>

View File

@ -1,5 +1,5 @@
/*!
* reveal.js 1.5 r6
* reveal.js 1.5 r7
* http://lab.hakim.se/reveal-js
* MIT licensed
*

View File

@ -1,18 +1,24 @@
// From https://gist.github.com/1343518, modified to not load showdown
// From https://gist.github.com/1343518
// Modified by Hakim to handle markdown indented with tabs
(function(){
[].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){
// strip leading whitespace so it isn't evaluated as code
var text = elem.innerHTML.replace(/\n\s*\n/g,'\n'),
// set indentation level so your markdown can be indented within your HTML
leadingws = text.match(/^\n?(\s*)/)[1].length,
regex = new RegExp('\\n?\\s{' + leadingws + '}','g'),
md = text.replace(regex,'\n'),
html = (new Showdown.converter()).makeHtml(md);
var text = elem.innerHTML;
var leadingWs = text.match(/^\n?(\s*)/)[1].length,
leadingTabs = text.match(/^\n?(\t*)/)[1].length;
if( leadingTabs > 0 ) {
text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
}
else if( leadingWs > 1 ) {
text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' );
}
// here, have sum HTML
elem.innerHTML = html;
elem.innerHTML = (new Showdown.converter()).makeHtml(text);
});