Skip to content

Commit

Permalink
Merge pull request hakimel#2515 from Bagira80/boolean-attributes-from…
Browse files Browse the repository at this point in the history
…-markdown

Markdown: Boolean (data-)attributes will now be added to elements, too.
  • Loading branch information
hakimel authored Mar 3, 2020
2 parents ac19f69 + 57332a7 commit a37faa2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plugin/markdown/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,19 @@
function addAttributeInElement( node, elementTarget, separator ) {

var mardownClassesInElementsRegex = new RegExp( separator, 'mg' );
var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"=]+?)\"", 'mg' );
var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"]+?)\"|(data-[^\"= ]+?)(?=[\" ])", 'mg' );
var nodeValue = node.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] );
if( matchesClass[2] ) {
elementTarget.setAttribute( matchesClass[1], matchesClass[2] );
} else {
elementTarget.setAttribute( matchesClass[3], "" );
}
}
return true;
}
Expand Down

0 comments on commit a37faa2

Please sign in to comment.