diff options
Diffstat (limited to 'plugin/markdown')
-rw-r--r-- | plugin/markdown/example.html | 41 | ||||
-rwxr-xr-x | plugin/markdown/markdown.js | 70 |
2 files changed, 78 insertions, 33 deletions
diff --git a/plugin/markdown/example.html b/plugin/markdown/example.html index 0b07aa5..364e866 100644 --- a/plugin/markdown/example.html +++ b/plugin/markdown/example.html @@ -8,6 +8,8 @@ <link rel="stylesheet" href="../../css/reveal.css"> <link rel="stylesheet" href="../../css/theme/default.css" id="theme"> + + <link rel="stylesheet" href="../../lib/css/zenburn.css"> </head> <body> @@ -17,7 +19,7 @@ <div class="slides"> <!-- Use external markdown resource, separate slides by three newlines; vertical slides by two newlines --> - <section data-markdown="example.md" data-separator="^\n\n\n" data-vertical="^\n\n"></section> + <section data-markdown="example.md" data-separator="^\n\n\n" data-separator-vertical="^\n\n"></section> <!-- Slides are separated by three dashes (quick 'n dirty regular expression) --> <section data-markdown data-separator="---"> @@ -34,7 +36,7 @@ </section> <!-- Slides are separated by newline + three dashes + newline, vertical slides identical but two dashes --> - <section data-markdown data-separator="^\n---\n$" data-vertical="^\n--\n$"> + <section data-markdown data-separator="^\n---\n$" data-separator-vertical="^\n--\n$"> <script type="text/template"> ## Demo 2 Slide 1.1 @@ -66,6 +68,37 @@ </script> </section> + <!-- Slide attributes --> + <section data-markdown> + <script type="text/template"> + <!-- .slide: data-background="#000000" --> + ## Slide attributes + </script> + </section> + + <!-- Element attributes --> + <section data-markdown> + <script type="text/template"> + ## Element attributes + - Item 1 <!-- .element: class="fragment" data-fragment-index="2" --> + - Item 2 <!-- .element: class="fragment" data-fragment-index="1" --> + </script> + </section> + + <!-- Code --> + <section data-markdown> + <script type="text/template"> + ```php + public function foo() + { + $foo = array( + 'bar' => 'bar' + ) + } + ``` + </script> + </section> + </div> </div> @@ -80,14 +113,12 @@ history: true, center: true, - theme: Reveal.getQueryHash().theme, - transition: Reveal.getQueryHash().transition || 'default', - // Optional libraries used to extend on reveal.js dependencies: [ { src: '../../lib/js/classList.js', condition: function() { return !document.body.classList; } }, { src: 'marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, { src: 'markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, + { src: '../highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, { src: '../notes/notes.js' } ] }); diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index 23a3ed4..718475b 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -27,8 +27,9 @@ } var DEFAULT_SLIDE_SEPARATOR = '^\n---\n$', - DEFAULT_NOTES_SEPARATOR = 'note:'; - DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '{_\s*?([^}]+?)}'; + DEFAULT_NOTES_SEPARATOR = 'note:', + DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$', + DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\\.slide:\\\s*?(\\\S.+?)$'; /** @@ -219,10 +220,11 @@ xhr.onreadystatechange = function() { if( xhr.readyState === 4 ) { if ( xhr.status >= 200 && xhr.status < 300 ) { + section.outerHTML = slidify( xhr.responseText, { separator: section.getAttribute( 'data-separator' ), - verticalSeparator: section.getAttribute( 'data-vertical' ), - notesSeparator: section.getAttribute( 'data-notes' ), + verticalSeparator: section.getAttribute( 'data-separator-vertical' ), + notesSeparator: section.getAttribute( 'data-separator-notes' ), attributes: getForwardedAttributes( section ) }); @@ -249,20 +251,18 @@ } } - else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-vertical' ) || section.getAttribute( 'data-notes' ) ) { + else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-separator-vertical' ) || section.getAttribute( 'data-separator-notes' ) ) { section.outerHTML = slidify( getMarkdownFromSlide( section ), { separator: section.getAttribute( 'data-separator' ), - verticalSeparator: section.getAttribute( 'data-vertical' ), - notesSeparator: section.getAttribute( 'data-notes' ), + verticalSeparator: section.getAttribute( 'data-separator-vertical' ), + notesSeparator: section.getAttribute( 'data-separator-notes' ), attributes: getForwardedAttributes( section ) }); } else { - section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) ); - } } @@ -287,40 +287,51 @@ var classes = matches[1]; nodeValue = nodeValue.substring( 0, matches.index ) + nodeValue.substring( mardownClassesInElementsRegex.lastIndex ); node.nodeValue = nodeValue; - while( matchesClass = mardownClassRegex.exec( classes ) ) { elementTarget.setAttribute( matchesClass[1], matchesClass[2] ); } + return true; } - + return false; } /** * Add attributes to the parent element of a text node, * or the element of an attribute node. */ - function addAttributes( element, separator ) { + function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) { - if( element.childNodes.length > 0 ) { + if ( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) { + previousParentElement = element; for( var i = 0; i < element.childNodes.length; i++ ) { - addAttributes( element.childNodes[i], separator ); + childElement = element.childNodes[i]; + if ( i > 0 ) { + j = i - 1; + while ( j >= 0 ) { + aPreviousChildElement = element.childNodes[j]; + if ( typeof aPreviousChildElement.setAttribute == 'function' && aPreviousChildElement.tagName != "BR" ) { + previousParentElement = aPreviousChildElement; + break; + } + j = j - 1; + } + } + parentSection = section; + if( childElement.nodeName == "section" ) { + parentSection = childElement ; + previousParentElement = childElement ; + } + if ( typeof childElement.setAttribute == 'function' || childElement.nodeType == Node.COMMENT_NODE ) { + addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes ); + } } } - var nodeValue; - var elementTarget; - - // From http://stackoverflow.com/questions/9178174/find-all-text-nodes - if( element.nodeType == Node.TEXT_NODE && /\S/.test(element.nodeValue) ) { - addAttributeInElement( element, element.parentNode, separator ); - } - if( element.nodeType == Node.ELEMENT_NODE && element.attributes.length > 0 ) { - for( var j = 0; j < element.attributes.length; j++ ){ - var attr = element.attributes[j]; - addAttributeInElement( attr, element, separator ); + if ( element.nodeType == Node.COMMENT_NODE ) { + if ( addAttributeInElement( element, previousElement, separatorElementAttributes ) == false ) { + addAttributeInElement( element, section, separatorSectionAttributes ); } } - } /** @@ -344,9 +355,12 @@ var markdown = getMarkdownFromSlide( section ); section.innerHTML = marked( markdown ); - addAttributes( section, section.getAttribute( 'data-element-attributes' ) || + addAttributes( section, section, null, section.getAttribute( 'data-element-attributes' ) || section.parentNode.getAttribute( 'data-element-attributes' ) || - DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR ); + DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR, + section.getAttribute( 'data-attributes' ) || + section.parentNode.getAttribute( 'data-attributes' ) || + DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR); // If there were notes, we need to re-add them after // having overwritten the section's HTML |