Skip to content

Commit b551156

Browse files
authored
Fix changelog processing when id attribute is missing. (#8625)
1 parent b7a63a9 commit b551156

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/lib/shared/markdown.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,16 @@ Iterable<html.Node> _groupChangelogNodes(List<html.Node> nodes) sync* {
371371
final version = mayBeVersion ? _extractVersion(versionText) : null;
372372
if (version != null) {
373373
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+
}
374381
final titleElem = html.Element.tag('h2')
375382
..attributes['class'] = 'changelog-version'
376-
..attributes['id'] = node.attributes['id']!
383+
..attributes['id'] = id
377384
..append(html.Text(versionText!));
378385

379386
lastContentDiv = html.Element.tag('div')

app/test/shared/markdown_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,21 @@ void main() {
405405
'</h2>',
406406
);
407407
});
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+
});
408423
});
409424

410425
group('alert blocks', () {

0 commit comments

Comments
 (0)