Skip to content

Commit dd9fa3e

Browse files
committed
First refactoring
1 parent 3d2549d commit dd9fa3e

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

plugin/markdown/markdown.js

+32-11
Original file line numberDiff line numberDiff line change
@@ -323,33 +323,50 @@
323323
while( matchesClass = mardownClassRegex.exec( classes ) ) {
324324
elementTarget.setAttribute( matchesClass[1], matchesClass[2] );
325325
}
326+
return true;
326327
}
327-
328+
return false;
328329
}
329330

330331
/**
331332
* Add attributes to the parent element of a text node,
332333
* or the element of an attribute node.
333334
*/
334-
function addAttributes( element, separator ) {
335+
function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) {
335336

336-
if( element.childNodes.length > 0 ) {
337+
console.log("element='" + element.innerHTML + "', nodeType='" + element.nodeType + "'");
338+
console.log("previousElement="+previousElement)
339+
console.log("section=****"+section.outerHTML+"****");
340+
if( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) {
341+
previousParentElement = element;
337342
for( var i = 0; i < element.childNodes.length; i++ ) {
338-
addAttributes( element.childNodes[i], separator );
343+
childElement = element.childNodes[i];
344+
console.log(" Child element='" + childElement.innerHTML + "'");
345+
if ( i > 0 ) {
346+
previousParentElement = element.childNodes[i-1];
347+
}
348+
parentSection = section;
349+
if( childElement.nodeName == "section" ) {
350+
parentSection = childElement ;
351+
previousParentElement = childElement ;
352+
}
353+
addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes );
339354
}
340355
}
341356

342-
var nodeValue;
343-
var elementTarget;
344-
357+
if ( element.nodeType == Node.COMMENT_NODE ) {
358+
if ( addAttributeInElement( element, previousElement, separatorElementAttributes ) == false ) {
359+
addAttributeInElement( element, section, separatorSectionAttributes);
360+
}
361+
}
345362
// From http://stackoverflow.com/questions/9178174/find-all-text-nodes
346363
if( element.nodeType == Node.TEXT_NODE && /\S/.test(element.nodeValue) ) {
347-
addAttributeInElement( element, element.parentNode, separator );
364+
addAttributeInElement( element, element.parentNode, separatorElementAttributes );
348365
}
349366
if( element.nodeType == Node.ELEMENT_NODE && element.attributes.length > 0 ) {
350367
for( var j = 0; j < element.attributes.length; j++ ){
351368
var attr = element.attributes[j];
352-
addAttributeInElement( attr, element, separator );
369+
addAttributeInElement( attr, element, separatorElementAttributes );
353370
}
354371
}
355372

@@ -376,9 +393,13 @@
376393
var markdown = getMarkdownFromSlide( section );
377394

378395
section.innerHTML = marked( markdown );
379-
addAttributes( section, section.getAttribute( 'data-element-attributes' ) ||
396+
//console.log("markdown="+markdown);
397+
addAttributes( section, section, null, section.getAttribute( 'data-element-attributes' ) ||
380398
section.parentNode.getAttribute( 'data-element-attributes' ) ||
381-
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR );
399+
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR,
400+
section.getAttribute( 'data-attributes' ) ||
401+
section.parentNode.getAttribute( 'data-attributes' ) ||
402+
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR);
382403

383404
// If there were notes, we need to re-add them after
384405
// having overwritten the section's HTML

test/test-markdown-attributes.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div id="qunit"></div>
1616
<div id="qunit-fixture"></div>
1717

18-
<div class="reveal" style="display: none;">
18+
<div class="reveal" style="display: true;">
1919

2020
<div class="slides">
2121

test/test-markdown-element-attributes.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div id="qunit"></div>
1616
<div id="qunit-fixture"></div>
1717

18-
<div class="reveal" style="display: none;">
18+
<div class="reveal" style="display: true;">
1919

2020
<div class="slides">
2121

@@ -44,7 +44,7 @@
4444
## Slide 2
4545

4646

47-
Paragraph 1.2
47+
Paragraph 1.2
4848
multi-line {_class="fragment highlight-red"}
4949

5050
Paragraph 2.2 {_class="fragment highlight-red"}

0 commit comments

Comments
 (0)