modified data-markdown to support markdown indented with tabs
This commit is contained in:
parent
ff567372c0
commit
0a440cee6c
|
@ -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.
|
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
|
```html
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
|
|
|
@ -122,8 +122,8 @@
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
## Markdown support
|
## Markdown support
|
||||||
|
|
||||||
For those of you who like that sort of thing. Instructions and a bit more info
|
For those of you who like that sort of thing.
|
||||||
available [here](https://github.com/hakimel/reveal.js#markdown).
|
Instructions and a bit more info available [here](https://github.com/hakimel/reveal.js#markdown).
|
||||||
|
|
||||||
<pre><code contenteditable style="margin-top: 20px;"><section data-markdown>
|
<pre><code contenteditable style="margin-top: 20px;"><section data-markdown>
|
||||||
## Markdown support
|
## Markdown support
|
||||||
|
@ -326,6 +326,6 @@ function linkify( selector ) {
|
||||||
hljs.initHighlightingOnLoad();
|
hljs.initHighlightingOnLoad();
|
||||||
} );
|
} );
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,5 +1,5 @@
|
||||||
/*!
|
/*!
|
||||||
* reveal.js 1.5 r6
|
* reveal.js 1.5 r7
|
||||||
* http://lab.hakim.se/reveal-js
|
* http://lab.hakim.se/reveal-js
|
||||||
* MIT licensed
|
* MIT licensed
|
||||||
*
|
*
|
||||||
|
|
|
@ -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(){
|
(function(){
|
||||||
|
|
||||||
[].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){
|
[].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){
|
||||||
|
|
||||||
// strip leading whitespace so it isn't evaluated as code
|
// strip leading whitespace so it isn't evaluated as code
|
||||||
var text = elem.innerHTML.replace(/\n\s*\n/g,'\n'),
|
var text = elem.innerHTML;
|
||||||
// set indentation level so your markdown can be indented within your HTML
|
|
||||||
leadingws = text.match(/^\n?(\s*)/)[1].length,
|
var leadingWs = text.match(/^\n?(\s*)/)[1].length,
|
||||||
regex = new RegExp('\\n?\\s{' + leadingws + '}','g'),
|
leadingTabs = text.match(/^\n?(\t*)/)[1].length;
|
||||||
md = text.replace(regex,'\n'),
|
|
||||||
html = (new Showdown.converter()).makeHtml(md);
|
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
|
// here, have sum HTML
|
||||||
elem.innerHTML = html;
|
elem.innerHTML = (new Showdown.converter()).makeHtml(text);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user