@@ -6,7 +6,7 @@ import imsize from '../imsize';
6
6
import { MarkdownItPluginOpts } from '../typings' ;
7
7
8
8
const BLOCK_START = '{% changelog %}' ;
9
- const BLOCK_END = '{% endchangelog %}\n ' ;
9
+ const BLOCK_END = '{% endchangelog %}' ;
10
10
11
11
function parseChangelogs ( str : string , path ?: string ) {
12
12
const { parse, compile, env} = initMarkdownit ( {
@@ -28,33 +28,38 @@ type Options = Pick<MarkdownItPluginOpts, 'path' | 'log'> & {
28
28
const collect = ( input : string , { path : filepath , log, changelogs, extractChangelogs} : Options ) => {
29
29
let result = input ;
30
30
let lastPos = 0 ;
31
- const rawChanges = [ ] ;
31
+ const rawChangelogs = [ ] ;
32
32
33
33
// eslint-disable-next-line no-constant-condition
34
34
while ( true ) {
35
- const pos = result . indexOf ( BLOCK_START , lastPos ) ;
36
- lastPos = pos ;
37
- if ( pos === - 1 ) {
35
+ const startPos = result . indexOf ( BLOCK_START , lastPos ) ;
36
+ lastPos = startPos ;
37
+ if ( startPos === - 1 ) {
38
38
break ;
39
39
}
40
- const endPos = result . indexOf ( BLOCK_END , pos + BLOCK_START . length ) ;
41
- if ( endPos === - 1 ) {
40
+
41
+ const endBlockPos = result . indexOf ( BLOCK_END , startPos + BLOCK_START . length ) ;
42
+ if ( endBlockPos === - 1 ) {
42
43
log . error ( `Changelog block must be closed${ filepath ? ` in ${ bold ( filepath ) } ` : '' } ` ) ;
43
44
break ;
44
45
}
46
+ let endPos = endBlockPos + BLOCK_END . length ;
47
+ if ( result [ endPos + 1 ] === '\n' ) {
48
+ endPos += 1 ;
49
+ }
45
50
46
- const change = result . slice ( pos , endPos + BLOCK_END . length ) ;
51
+ const changelog = result . slice ( startPos , endPos ) ;
47
52
48
- rawChanges . push ( change ) ;
53
+ rawChangelogs . push ( changelog ) ;
49
54
50
- result = result . slice ( 0 , pos ) + result . slice ( endPos + BLOCK_END . length ) ;
55
+ result = result . slice ( 0 , startPos ) + result . slice ( endPos ) ;
51
56
}
52
57
53
- if ( rawChanges . length && changelogs && extractChangelogs ) {
54
- const parsedChangelogs = parseChangelogs ( rawChanges . join ( '\n\n' ) , filepath ) ;
55
- if ( parsedChangelogs . length !== rawChanges . length ) {
58
+ if ( rawChangelogs . length && changelogs && extractChangelogs ) {
59
+ const parsedChangelogs = parseChangelogs ( rawChangelogs . join ( '\n\n' ) , filepath ) ;
60
+ if ( parsedChangelogs . length !== rawChangelogs . length ) {
56
61
log . error (
57
- `Parsed cahngelogs less than expected${ filepath ? ` in ${ bold ( filepath ) } ` : '' } ` ,
62
+ `Parsed changelogs less than expected${ filepath ? ` in ${ bold ( filepath ) } ` : '' } ` ,
58
63
) ;
59
64
}
60
65
changelogs . push ( ...parsedChangelogs ) ;
0 commit comments