From d844195be137d6e67fd7eace5ad4d5f1310e7401 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 28 Oct 2013 09:06:43 -0400 Subject: [PATCH] format tweaks markdown.js, remove extra image asset --- plugin/markdown/markdown.js | 30 ++++++++++++--------- test/red-curtain-50x50.jpg | Bin 1995 -> 0 bytes test/test-element-attributes-markdown.html | 12 ++++----- 3 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 test/red-curtain-50x50.jpg diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index fccc442..d6c6c45 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -28,7 +28,7 @@ var DEFAULT_SLIDE_SEPARATOR = '^\n---\n$', DEFAULT_NOTES_SEPARATOR = 'note:'; - DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '{\\\.\s*?([^}]+?)}'; + DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '{_\s*?([^}]+?)}'; /** @@ -277,46 +277,50 @@ * directly on refresh (F5) * http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development/7000899#answer-11786277 */ - function addAttributeInElement( node, elementTarget, separator ){ + function addAttributeInElement( node, elementTarget, separator ) { + var mardownClassesInElementsRegex = new RegExp( separator, 'mg' ); var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"=]+?)\"", 'mg' ); var nodeValue = node.nodeValue; - if ( matches = mardownClassesInElementsRegex.exec( nodeValue ) ) { + if( matches = mardownClassesInElementsRegex.exec( nodeValue ) ) { 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]); + elementTarget.setAttribute( matchesClass[1], matchesClass[2] ); } } + } /** * Add attributes to the parent element of a text node, * or the element of an attribute node. */ - function addAttributes( element, separator ) - { - if ( element.childNodes.length > 0 ) { + function addAttributes( element, separator ) { - for ( var i = 0; i < element.childNodes.length; i++ ) { + if( element.childNodes.length > 0 ) { + for( var i = 0; i < element.childNodes.length; i++ ) { addAttributes( element.childNodes[i], separator ); } } + var nodeValue; var elementTarget; + // From http://stackoverflow.com/questions/9178174/find-all-text-nodes - if ( element.nodeType == Node.TEXT_NODE && /\S/.test(element.nodeValue) ) { + 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 ( iattr=0; iattr 0 ) { + for( var j = 0; j < element.attributes.length; j++ ){ + var attr = element.attributes[j]; + addAttributeInElement( attr, element, separator ); } } + } /** diff --git a/test/red-curtain-50x50.jpg b/test/red-curtain-50x50.jpg deleted file mode 100644 index ddfe7a637d747dedc7c7c71a01431e7e76e0eb6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1995 zcmbW!XH=6}8UWxg`O-)TNgx4q1`|LjA}9z$Q$sOS1%paeihwjh2}KZu6~qE4V1$fV zkY+5$QCSgD9EgD6Vr)nY76?KFLw0KiNqk02m}&~Mx!w5Sao$A7Kg)YXcF-n zBn=#ns7)kkktr04IzdNQo2;uzrjVB|fq|+s2&5VksYb@*@Z|qFpf-Sn0jvNk5M}_t zNidKEgE|1J3W%IClKR$-*=2v*i_>U(Z$6)YjEs;a9T<&ZqQkmkXuujJ-Tk z53?fMyitJCRX(s*xYZOJ>kzumNz-d1NMbMSy>BA?=?v%KLN0Gpk7f6$FK%^Qe9dd= z`QqI9v(JsD+l6Bxz1D4)*Can_AUL5!%Eqo~?Zm7bJ^H$pDFcgNJR#tB55;t!Atp`F zN4|GXusN3b@LFkU$6+FUtR%R3cKgWU_bz%-rTg)_g95`F?=x`*#YI`+Db}qFr)1?P zy=g(af5k-z@Xv|36ul#uE!e&k8imN?bnWoxbhWgRat^(-?)x zErE=_7r)js&+(^_WWC0Q6M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