aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorVonC <vonc@laposte.net>2013-10-24 22:37:55 +0200
committerVonC <vonc@laposte.net>2013-10-27 22:49:41 +0100
commit0bc3a836fc62a25a72ea46758c82b8617d5e93c0 (patch)
treef57132b0bfea20b387fd714158b4f8da11d968c5 /plugin
parent82d2ae654d0fbde915dc6481631a8da867eaa994 (diff)
downloadfosdem-2018-presentation-0bc3a836fc62a25a72ea46758c82b8617d5e93c0.tar
fosdem-2018-presentation-0bc3a836fc62a25a72ea46758c82b8617d5e93c0.tar.gz
First implem for adding classes to enclosing elts.
Extra text representing classes is detected and correctly removed. Adding attributes isn't working yet.
Diffstat (limited to 'plugin')
-rwxr-xr-xplugin/markdown/markdown.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js
index 61d6987..3b71c42 100755
--- a/plugin/markdown/markdown.js
+++ b/plugin/markdown/markdown.js
@@ -269,6 +269,42 @@
}
/**
+ * 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.
*/
@@ -289,6 +325,7 @@
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