diff options
author | Deniz Bahadir <dbahadir@benocs.com> | 2019-10-23 21:18:14 +0200 |
---|---|---|
committer | Deniz Bahadir <dbahadir@benocs.com> | 2019-10-23 21:18:14 +0200 |
commit | f6d96fe45d86b1f79fd544a2814a3d7af60fb213 (patch) | |
tree | 033bf1f9950aa177002663bc265b9550e4095886 /plugin | |
parent | f9affb550ac49424c745eb8116c419f5d1ab3278 (diff) | |
download | fosdem-2021-minimalism-presentation-f6d96fe45d86b1f79fd544a2814a3d7af60fb213.tar fosdem-2021-minimalism-presentation-f6d96fe45d86b1f79fd544a2814a3d7af60fb213.tar.gz |
Markdown: Boolean (data-)attributes will now be added to elements, too.
Diffstat (limited to 'plugin')
-rwxr-xr-x | plugin/markdown/markdown.js | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index c641d81..bd4de55 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; } |