From f6d96fe45d86b1f79fd544a2814a3d7af60fb213 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Wed, 23 Oct 2019 21:18:14 +0200 Subject: [PATCH] Markdown: Boolean (data-)attributes will now be added to elements, too. --- plugin/markdown/markdown.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index c641d81f..bd4de552 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -307,7 +307,7 @@ 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 ) ) { @@ -315,7 +315,11 @@ 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; }