' +
'ERROR: The attempt to fetch ' + url + ' failed with HTTP status ' + xhr.status + '.' +
'Check your browser\'s JavaScript console for more details.' +
'Remember that you need to serve the presentation HTML from a HTTP server.
' +
'';
}
}
};
xhr.open( 'GET', url, false );
try {
xhr.send();
}
catch ( e ) {
alert( 'Failed to get the Markdown file ' + url + '. Make sure that the presentation and the file are served by a HTTP server and the file can be found there. ' + e );
}
}
else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-vertical' ) || section.getAttribute( 'data-notes' ) ) {
section.outerHTML = slidify( getMarkdownFromSlide( section ), {
separator: section.getAttribute( 'data-separator' ),
verticalSeparator: section.getAttribute( 'data-vertical' ),
notesSeparator: section.getAttribute( 'data-notes' ),
attributes: getForwardedAttributes( section )
});
}
else {
section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) );
}
}
}
/**
* Add classes to the parent element of a text node
* From http://stackoverflow.com/questions/9178174/find-all-text-nodes
*/
function addClasses(element)
{
var mardownClassesInElementsRegex = new RegExp( "{\\\.\s*?([^}]+?)}", 'mg' );
var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"=]+?)\"", 'mg' );
if ( element.childNodes.length > 0 ) {
for (var i = 0; i < element.childNodes.length; i++) {
addClasses(element.childNodes[i]);
}
}
if (element.nodeType == Node.TEXT_NODE && /\S/.test(element.nodeValue)) {
var nodeValue = element.nodeValue;
if ( matches = mardownClassesInElementsRegex.exec( nodeValue ) ) {
var classes = matches[1];
console.log("'" + classes + "'");
nodeValue = nodeValue.substring(0,matches.index) + nodeValue.substring(mardownClassesInElementsRegex.lastIndex) + "ee";
console.log("'" + nodeValue + "'");
element.nodeValue = nodeValue;
console.log("'" + element.parentNode.tagName + "'");
while( matchesClass = mardownClassRegex.exec( classes ) ) {
console.log("attr='" + matchesClass[1] + "'='" + matchesClass[2] + "'");
element.parentNode.attributes[matchesClass[1]] = matchesClass[2];
console.log("=>'" + element.parentNode.attributes[matchesClass[1]] + "'");
}
}
}
}
/**
* Converts any current data-markdown slides in the
* DOM to HTML.
*/
function convertSlides() {
var sections = document.querySelectorAll( '[data-markdown]');
for( var i = 0, len = sections.length; i < len; i++ ) {
var section = sections[i];
// Only parse the same slide once
if( !section.getAttribute( 'data-markdown-parsed' ) ) {
section.setAttribute( 'data-markdown-parsed', true )
var notes = section.querySelector( 'aside.notes' );
var markdown = getMarkdownFromSlide( section );
section.innerHTML = marked( markdown );
addClasses(section);
// If there were notes, we need to re-add them after
// having overwritten the section's HTML
if( notes ) {
section.appendChild( notes );
}
}
}
}
// API
return {
initialize: function() {
processSlides();
convertSlides();
},
// TODO: Do these belong in the API?
processSlides: processSlides,
convertSlides: convertSlides,
slidify: slidify
};
}));