feat: enhance reduceHeadings function to handle indented and closed markdown headings and add tests for new functionality. resolves #51

This commit is contained in:
SethCohen
2026-04-03 12:32:35 -04:00
parent b96a33520f
commit 80aca15d72
3 changed files with 26 additions and 2 deletions
+1
View File
@@ -7,3 +7,4 @@ release.json
repository.json
user.json
tests/sample-test-release-v2.json
tests/sample-test-release-v3.json
+15 -2
View File
@@ -61,8 +61,21 @@ const removeGithubReferenceLinks = (text) => text
* @returns {string} The text with reduced heading sizes.
*/
const reduceHeadings = (text) => text
.replace(/^###\s+(.+)$/gm, '**__$1__**') // Convert H3 to bold + underline
.replace(/^##\s+(.+)$/gm, '**$1**'); // Convert H2 to bold
.split('\n')
.map((line) => {
const h3 = line.match(/^\s*###\s+(.+?)\s*#*\s*$/);
if (h3) {
return `**__${h3[1].trim()}__**`;
}
const h2 = line.match(/^\s*##\s+(.+?)\s*#*\s*$/);
if (h2) {
return `**${h2[1].trim()}**`;
}
return line;
})
.join('\n');
/**
* Converts PR, issue, and changelog links to markdown format, ignoring existing markdown links.
+10
View File
@@ -70,6 +70,16 @@ describe('index.js utility functions', () => {
expect(reduceHeadings('## Heading2')).toBe('**Heading2**');
});
test('reduceHeadings reduces repeated section headings', () => {
const input = '### Bug Fixes\n- fix thing\n\n### Features\n- add thing';
expect(reduceHeadings(input)).toBe('**__Bug Fixes__**\n- fix thing\n\n**__Features__**\n- add thing');
});
test('reduceHeadings handles indented and closed markdown headings', () => {
const input = ' ## Changes ##\n ### Features ###';
expect(reduceHeadings(input)).toBe('**Changes**\n**__Features__**');
});
test('convertLinksToMarkdown converts PR/issue/changelog links', () => {
const pr = 'https://github.com/owner/repo/pull/1';
const issue = 'https://github.com/owner/repo/issues/2';