2323var filter = require ( '@stdlib/array/base/filter' ) ;
2424var trim = require ( '@stdlib/string/trim' ) ;
2525var map = require ( '@stdlib/utils/map' ) ;
26+ var reEOL = require ( '@stdlib/regexp/eol' ) ;
2627var collectField = require ( './collect_field.js' ) ;
2728var sectionStart = require ( './section_start.js' ) ;
2829var sectionEnd = require ( './section_end.js' ) ;
@@ -38,19 +39,17 @@ var RE_YAML_DELIMITER = /^\s*---\s*$/;
3839// FUNCTIONS //
3940
4041/**
41- * Strips YAML frontmatter blocks from text.
42+ * Strips YAML frontmatter blocks from text lines .
4243*
4344* @private
44- * @param {string } text - text to process
45- * @returns {string } text without YAML blocks
45+ * @param {Array< string> } lines - text lines to process
46+ * @returns {Array< string> } text lines without YAML blocks
4647*/
47- function stripYamlBlocks ( text ) {
48+ function stripYamlBlocks ( lines ) {
4849 var result ;
4950 var inYaml ;
50- var lines ;
5151 var i ;
5252
53- lines = text . split ( '\n' ) ;
5453 result = [ ] ;
5554 inYaml = false ;
5655
@@ -67,7 +66,7 @@ function stripYamlBlocks( text ) {
6766 }
6867 }
6968
70- return trim ( result . join ( '\n' ) ) ;
69+ return result ;
7170}
7271
7372/**
@@ -87,17 +86,39 @@ function stripYamlBlocks( text ) {
8786* // returns '- [`abcdef1`](https://github.com/stdlib-js/stdlib/commit/abcdef1234567890): beep'
8887*/
8988function formatBreakingChange ( note ) {
90- var parts ;
89+ var contentLines ;
90+ var trimmedLine ;
91+ var firstLine ;
92+ var restLines ;
93+ var textLines ;
9194 var hash ;
9295 var out ;
96+ var i ;
9397
94- parts = stripYamlBlocks ( note . text ) . split ( '\n' ) ;
98+ textLines = note . text . split ( reEOL . REGEXP ) ;
99+ contentLines = stripYamlBlocks ( textLines ) ;
100+ firstLine = '' ;
101+ restLines = [ ] ;
95102 hash = trim ( note . hash ) ;
96- out = '- [`' + hash . substring ( 0 , 7 ) + '`](' + STDLIB_GITHUB_URL + '/' + hash + '): ' + parts [ 0 ] ;
97- if ( parts . length > 1 ) {
98- out += '\n\n' ;
99- out += ' - ' ;
100- out += parts . slice ( 1 ) . join ( '\n ' ) ;
103+
104+ for ( i = 0 ; i < contentLines . length ; i ++ ) {
105+ trimmedLine = trim ( contentLines [ i ] ) ;
106+ if ( trimmedLine !== '' ) {
107+ // If this is our first non-empty line, it's the firstLine...
108+ if ( firstLine === '' ) {
109+ firstLine = trimmedLine ;
110+ } else {
111+ restLines . push ( trimmedLine ) ;
112+ }
113+ }
114+ }
115+
116+ // Construct output string - use a single string concatenation when possible
117+ out = '- [`' + hash . substring ( 0 , 7 ) + '`](' + STDLIB_GITHUB_URL + '/' + hash + '): ' + firstLine ;
118+
119+ if ( restLines . length > 0 ) {
120+ out += '\n\n' ;
121+ out += ' - ' + restLines . join ( '\n ' ) ;
101122 out += '\n' ;
102123 }
103124 return out ;
0 commit comments