Skip to content

Commit 8ad633e

Browse files
committed
Fix element attributes, except for multi-line.
1 parent 3330c2a commit 8ad633e

File tree

3 files changed

+60
-39
lines changed

3 files changed

+60
-39
lines changed

plugin/markdown/markdown.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
var DEFAULT_SLIDE_SEPARATOR = '^\n---\n$',
3030
DEFAULT_NOTES_SEPARATOR = 'note:',
3131
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '{\\\.\s*?([^}]+?)}',
32-
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '^.*?<!--\\\sslide-attributes:\\\s(.*?)-->';
32+
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = 'slide-attributes:\\\s(.*?)$';
3333

3434

3535
/**
@@ -73,7 +73,7 @@
7373
value = attributes[i].value;
7474

7575
// disregard attributes that are used for markdown loading/parsing
76-
if( /data\-(markdown|separator|vertical|notes|attributes)/gi.test( name ) ) continue;
76+
if( /data\-(markdown|separator|vertical|notes)/gi.test( name ) ) continue;
7777

7878
if( value ) {
7979
result.push( name + '=' + value );
@@ -282,12 +282,13 @@
282282
var mardownClassesInElementsRegex = new RegExp( separator, 'mg' );
283283
var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"=]+?)\"", 'mg' );
284284
var nodeValue = node.nodeValue;
285+
console.log("=== node.nodeValue='" + nodeValue + "' vs. separator '" + separator + "'");
285286
if( matches = mardownClassesInElementsRegex.exec( nodeValue ) ) {
286287

287288
var classes = matches[1];
288289
nodeValue = nodeValue.substring( 0, matches.index ) + nodeValue.substring( mardownClassesInElementsRegex.lastIndex );
289290
node.nodeValue = nodeValue;
290-
291+
console.log("=========== classes='" + classes + "'");
291292
while( matchesClass = mardownClassRegex.exec( classes ) ) {
292293
elementTarget.setAttribute( matchesClass[1], matchesClass[2] );
293294
}
@@ -302,23 +303,26 @@
302303
*/
303304
function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) {
304305

305-
console.log("element='" + element.innerHTML + "', nodeType='" + element.nodeType + "'");
306+
console.log("*** element='" + element.innerHTML + "', nodeType='" + element.nodeType + "'");
306307
console.log("previousElement="+previousElement)
307308
console.log("section=****"+section.outerHTML+"****");
308-
if( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) {
309+
if ( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) {
309310
previousParentElement = element;
310311
for( var i = 0; i < element.childNodes.length; i++ ) {
311312
childElement = element.childNodes[i];
312-
console.log(" Child element='" + childElement.innerHTML + "'");
313-
if ( i > 0 ) {
313+
console.log(" Child element='" + childElement.innerHTML + "', type " + childElement.nodeType);
314+
if ( i > 0 && typeof element.childNodes[i-1].setAttribute == 'function' ) {
314315
previousParentElement = element.childNodes[i-1];
315316
}
316317
parentSection = section;
317318
if( childElement.nodeName == "section" ) {
318319
parentSection = childElement ;
319320
previousParentElement = childElement ;
320321
}
321-
addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes );
322+
if ( typeof childElement.setAttribute == 'function' || childElement.nodeType == Node.COMMENT_NODE ) {
323+
console.log(" CALL addAttributes")
324+
addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes );
325+
}
322326
}
323327
}
324328

@@ -328,15 +332,15 @@
328332
}
329333
}
330334
// From http://stackoverflow.com/questions/9178174/find-all-text-nodes
331-
if( element.nodeType == Node.TEXT_NODE && /\S/.test(element.nodeValue) ) {
332-
addAttributeInElement( element, element.parentNode, separatorElementAttributes );
333-
}
334-
if( element.nodeType == Node.ELEMENT_NODE && element.attributes.length > 0 ) {
335-
for( var j = 0; j < element.attributes.length; j++ ){
336-
var attr = element.attributes[j];
337-
addAttributeInElement( attr, element, separatorElementAttributes );
338-
}
339-
}
335+
//if( element.nodeType == Node.TEXT_NODE && /\S/.test(element.nodeValue) ) {
336+
// addAttributeInElement( element, element.parentNode, separatorElementAttributes );
337+
//}
338+
//if( element.nodeType == Node.ELEMENT_NODE && element.attributes.length > 0 ) {
339+
// for( var j = 0; j < element.attributes.length; j++ ){
340+
// var attr = element.attributes[j];
341+
// addAttributeInElement( attr, element, separatorElementAttributes );
342+
// }
343+
//}
340344

341345
}
342346

test/test-markdown-attributes.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<section data-markdown data-separator="^\n\n\n"
2626
data-vertical="^\n\n"
2727
data-notes="^Note:"
28-
data-attributes="^\s*?--\s(.*?)$"
28+
data-attributes="--\s(.*?)$"
2929
data-charset="utf-8">
3030
<script type="text/template">
3131
# Test attributes in Markdown
@@ -34,11 +34,11 @@
3434

3535

3636
## Slide 2
37-
-- id="slide2" data-transition="zoom" data-background="#A0C66B"
37+
<!-- -- id="slide2" data-transition="zoom" data-background="#A0C66B" -->
3838

3939

4040
## Slide 2.1
41-
-- data-background="#ff0000" data-transition="fade"
41+
<!-- -- data-background="#ff0000" data-transition="fade" -->
4242

4343

4444
## Slide 2.2
@@ -47,7 +47,7 @@
4747

4848

4949
## Slide 3
50-
-- data-transition="zoom" data-background="#C6916B"
50+
<!-- -- data-transition="zoom" data-background="#C6916B" -->
5151

5252

5353

test/test-markdown-element-attributes.html

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,61 @@
2424
<!-- Slides are separated by newline + three dashes + newline, vertical slides identical but two dashes -->
2525
<section data-markdown data-separator="^\n---\n$" data-vertical="^\n--\n$" data-element-attributes="{_\s*?([^}]+?)}">>
2626
<script type="text/template">
27-
## Slide 1.1 {_class="fragment fade-out" data-fragment-index="1"}
27+
## Slide 1.1
28+
<!-- {_class="fragment fade-out" data-fragment-index="1"} -->
2829

2930
--
3031

31-
## Slide 1.2 {_class="fragment shrink"}
32+
## Slide 1.2
33+
<!-- {_class="fragment shrink"} -->
3234

33-
Paragraph 1 {_class="fragment grow"}
35+
Paragraph 1
36+
<!-- {_class="fragment grow"} -->
3437

35-
Paragraph 2 {_class="fragment grow"}
38+
Paragraph 2
39+
<!-- {_class="fragment grow"} -->
3640

37-
- list item 1 {_class="fragment roll-in"}
38-
- list item 2 {_class="fragment roll-in"}
39-
- list item 3 {_class="fragment roll-in"}
41+
- list item 1
42+
<!-- {_class="fragment roll-in"} -->
43+
- list item 2
44+
<!-- {_class="fragment roll-in"} -->
45+
- list item 3
46+
<!-- {_class="fragment roll-in"} -->
4047

4148

4249
---
4350

4451
## Slide 2
4552

4653

47-
Paragraph 1.2
48-
multi-line {_class="fragment highlight-red"}
54+
Paragraph 1.2
55+
multi-line
56+
<!-- {_class="fragment highlight-red"} -->
4957

50-
Paragraph 2.2 {_class="fragment highlight-red"}
58+
Paragraph 2.2
59+
<!-- {_class="fragment highlight-red"} -->
5160

52-
Paragraph 2.3 {_class="fragment highlight-red"}
61+
Paragraph 2.3
62+
<!-- {_class="fragment highlight-red"} -->
5363

54-
Paragraph 2.4 {_class="fragment highlight-red"}
64+
Paragraph 2.4
65+
<!-- {_class="fragment highlight-red"} -->
5566

56-
- list item 1 {_class="fragment highlight-green"}
57-
- list item 2 {_class="fragment highlight-green"}
58-
- list item 3 {_class="fragment highlight-green"}
59-
- list item 4 {_class="fragment highlight-green"}
60-
- list item 5 {_class="fragment highlight-green"}
67+
- list item 1
68+
<!-- {_class="fragment highlight-green"} -->
69+
- list item 2
70+
<!-- {_class="fragment highlight-green"} -->
71+
- list item 3
72+
<!-- {_class="fragment highlight-green"} -->
73+
- list item 4
74+
<!-- {_class="fragment highlight-green"} -->
75+
- list item 5
76+
<!-- {_class="fragment highlight-green"} -->
6177

6278
Test
6379

64-
![Example Picture{_class="reveal stretch"}](assets/image2.png)
80+
![Example Picture](examples/assets/image2.png)
81+
<!-- {_class="reveal stretch"} -->
6582

6683
</script>
6784
</section>

0 commit comments

Comments
 (0)