diff --git a/tasks/wp_readme_to_markdown.js b/tasks/wp_readme_to_markdown.js index a9ef30a..1467fe2 100644 --- a/tasks/wp_readme_to_markdown.js +++ b/tasks/wp_readme_to_markdown.js @@ -18,7 +18,7 @@ module.exports = function(grunt) { var options = this.options({ screenshot_url: 'http://ps.w.org/{plugin}/assets/{screenshot}.png', }); - + grunt.verbose.writeflags( options ); this.files.forEach(function(f) { @@ -29,7 +29,7 @@ module.exports = function(grunt) { grunt.log.warn('Source file "' + filepath + '" not found.'); return false; } else { - return true; + return true; } }).map(function(filepath) { // Read file source. @@ -38,9 +38,9 @@ module.exports = function(grunt) { /* The following is a ported version of {@see https://github.com/benbalter/WP-Readme-to-Github-Markdown}*/ - //Convert Headings + //Convert Headings grunt.log.debug("Converting headings"); - readme = readme.replace( new RegExp("^=([^=]+)=*?[\\s ]*?$","gim"),"###$1###"); + readme = readme.replace( new RegExp("^=([^=]+)=*?[\\s ]*?$","gim"),"###$1###"); readme = readme.replace( new RegExp("^==([^=]+)==*?[\\s ]*?$","mig"),"##$1##"); readme = readme.replace( new RegExp("^===([^=]+)===*?[\\s ]*?$","gim"),"#$1#"); @@ -53,19 +53,41 @@ module.exports = function(grunt) { readme = readme.replace( header_search, header_replace ); } + // Include w.org profiles for contributors. + grunt.log.debug("Including contributors profiles"); + var contributors_match = readme.match( new RegExp("(\\*\\*Contributors:\\*\\* )(.+)", "m") ); + if ( header_match && header_match.length >= 1 ) { + var contributors_search = contributors_match[0]; + var contributors_replace = contributors_match[1]; + var profiles = []; + + // Fill profiles. + contributors_match[2].split(",").forEach(function(value) { + value = value.trim(); + profiles.push("[" + value + "](https://profiles.wordpress.org/" + value + ")"); + }); + + contributors_replace += profiles.join(", "); + + // Add line break. + contributors_replace += ' '; + + readme = readme.replace( contributors_search, contributors_replace ); + } + //guess plugin slug from plugin name //@todo Get this from config instead? grunt.log.debug("Get plugin name"); - var _match = readme.match( new RegExp("^#([^#]+)#[\\s ]*?$","im") ); + var _match = readme.match( new RegExp("^#([^#]+)#[\\s ]*?$","im") ); //process screenshots, if any grunt.log.debug("Get screenshots"); var screenshot_match = readme.match( new RegExp("## Screenshots ##([^#]*)","im") ); if ( _match && screenshot_match && screenshot_match.length > 1 ) { - + var plugin = _match[1].trim().toLowerCase().replace(/ /g, '-'); - - //Collect screenshots content + + //Collect screenshots content var screenshots = screenshot_match[1]; //parse screenshot list into array @@ -76,7 +98,7 @@ module.exports = function(grunt) { nonGlobalMatch = globalMatch[i].match( new RegExp( "^[0-9]+\\. (.*)", 'im' ) ); matchArray.push( nonGlobalMatch[1] ); } - + //replace list item with markdown image syntax, hotlinking to plugin repo //@todo assumes .png, perhaps should check that file exists first? for( i=1; i <= matchArray.length; i++ ) { @@ -86,7 +108,7 @@ module.exports = function(grunt) { readme = readme.replace( globalMatch[i-1], "### "+i+". "+ matchArray[i-1] +" ###\n!["+matchArray[i-1]+"](" + url + ")\n" ); } } - + //Code blocks readme = readme.replace( new RegExp("^`$[\n\r]+([^`]*)[\n\r]+^`$","gm"),function( codeblock, codeblockContents ){ var lines = codeblockContents.split("\n"); @@ -96,7 +118,7 @@ module.exports = function(grunt) { // Write the destination file. grunt.file.write( f.dest, readme ); - + // Print a success message. grunt.log.writeln('File "' + f.dest + '" created.'); });