File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -371,9 +371,16 @@ Iterable<html.Node> _groupChangelogNodes(List<html.Node> nodes) sync* {
371
371
final version = mayBeVersion ? _extractVersion (versionText) : null ;
372
372
if (version != null ) {
373
373
firstHeaderTag ?? = nodeTag;
374
+ var id = node.attributes['id' ];
375
+ if (id == null || id.isEmpty) {
376
+ // `package:markdown` generates ids without dots (`.`), using similar
377
+ // normalization here.
378
+ // TODO: consider replacing all uses with `<a>.<b>.<c>` id attributes
379
+ id = version.toString ().replaceAll ('.' , '' );
380
+ }
374
381
final titleElem = html.Element .tag ('h2' )
375
382
..attributes['class' ] = 'changelog-version'
376
- ..attributes['id' ] = node.attributes[ 'id' ] !
383
+ ..attributes['id' ] = id
377
384
..append (html.Text (versionText! ));
378
385
379
386
lastContentDiv = html.Element .tag ('div' )
Original file line number Diff line number Diff line change @@ -405,6 +405,21 @@ void main() {
405
405
'</h2>' ,
406
406
);
407
407
});
408
+
409
+ test ('custom html' , () {
410
+ final input = '''<h1>1.0.0</h1><hr><ul><li>a</li></ul>
411
+ <h1>0.2.9</h1><hr><ul><li>b</li></ul>
412
+ ''' ;
413
+ final output = markdownToHtml (input, isChangelog: true );
414
+ expect (
415
+ output,
416
+ allOf ([
417
+ contains ('<h2 class="changelog-version hash-header" id="100">'
418
+ '1.0.0 <a href="#100" class="hash-link">#</a></h2>' ),
419
+ contains ('<div class="changelog-content"><hr><ul><li>a</li></ul>' ),
420
+ ]),
421
+ );
422
+ });
408
423
});
409
424
410
425
group ('alert blocks' , () {
You can’t perform that action at this time.
0 commit comments