Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* @license Apache-2.0
*
Expand Down Expand Up @@ -33,10 +32,44 @@ var heading = require( './heading.js' );
// VARIABLES //

var STDLIB_GITHUB_URL = 'https://github.com/stdlib-js/stdlib/commit';
var RE_YAML_DELIMITER = /^\s*---\s*$/;


// FUNCTIONS //

/**
* Strips YAML frontmatter blocks from text.
*
* @private
* @param {string} text - text to process
* @returns {string} text without YAML blocks
*/
function stripYamlBlocks( text ) {
var result;
var inYaml;
var lines;
var i;

lines = text.split( '\n' );
result = [];
inYaml = false;

for ( i = 0; i < lines.length; i++ ) {
// Check for YAML delimiter (---) with optional whitespace:
if ( RE_YAML_DELIMITER.test( lines[i] ) ) {
inYaml = !inYaml; // Toggle YAML block state
continue;
}

// Only include lines that are not part of YAML blocks:
if ( !inYaml ) {
result.push( lines[i] );
}
}

return trim( result.join( '\n' ) );
}

/**
* Formats a breaking change.
*
Expand All @@ -54,9 +87,13 @@ var STDLIB_GITHUB_URL = 'https://github.com/stdlib-js/stdlib/commit';
* // returns '- [`abcdef1`](https://github.com/stdlib-js/stdlib/commit/abcdef1234567890): beep'
*/
function formatBreakingChange( note ) {
var parts = note.text.split( '\n' );
var hash = trim( note.hash );
var out = '- [`'+hash.substring( 0, 7 )+'`]('+STDLIB_GITHUB_URL+'/'+hash+'): '+parts[ 0 ];
var parts;
var hash;
var out;

parts = stripYamlBlocks( note.text ).split( '\n' );
hash = trim( note.hash );
out = '- [`'+hash.substring( 0, 7 )+'`]('+STDLIB_GITHUB_URL+'/'+hash+'): '+parts[ 0 ];
if ( parts.length > 1 ) {
out +='\n\n';
out += ' - ';
Expand Down