@@ -28,6 +28,9 @@ const SECTION_PREFIX = {
2828 Reverts : 'Revert'
2929}
3030
31+ // Render the scope (when present) as a parenthesised qualifier on the prefix:
32+ // "Fix (documentation): add ngram-index..." rather than the awkward double-colon
33+ // "Fix: documentation: add ngram-index...".
3134const XML_MAIN_TEMPLATE =
3235 '{{#each noteGroups}}' +
3336 '{{#each notes}}' +
@@ -36,10 +39,28 @@ const XML_MAIN_TEMPLATE =
3639 '{{/each}}' +
3740 '{{#each commitGroups}}' +
3841 '{{#each commits}}' +
39- '{{#unless isBreaking}}<li>{{prefix}}: {{#if scope}}{{scope}}: {{/if}}{{subject}}</li>\n{{/unless}}' +
42+ '{{#unless isBreaking}}<li>{{prefix}}{{#if scope}} ( {{scope}}) {{/if}}: {{subject}}</li>\n{{/unless}}' +
4043 '{{/each}}' +
4144 '{{/each}}'
4245
46+ /**
47+ * Tidy up a commit-derived <li> text node for display in the in-app changelog.
48+ *
49+ * - Collapse hard-wrapped newlines from the commit body (which would otherwise
50+ * break the sentence mid-line in the rendered <li>).
51+ * - Strip backslash-escapes that immediately precede backticks. Commit bodies
52+ * written via shell heredocs sometimes end up with literal `\`` sequences
53+ * in the stored message; they're meaningless once the text reaches an HTML
54+ * list item.
55+ * - Collapse consecutive whitespace and trim.
56+ */
57+ function normalizeItem ( text ) {
58+ return text
59+ . replace ( / \\ ` / g, '`' )
60+ . replace ( / \s + / g, ' ' )
61+ . trim ( )
62+ }
63+
4364function parseArgs ( ) {
4465 return Object . fromEntries (
4566 process . argv . slice ( 2 )
@@ -108,7 +129,7 @@ async function buildChangeItems (rawCommits, version) {
108129 const liNodes = doc . getElementsByTagNameNS ( HTML_NS , 'li' )
109130 const items = [ ]
110131 for ( let i = 0 ; i < liNodes . length ; i ++ ) {
111- const text = liNodes . item ( i ) . textContent
132+ const text = normalizeItem ( liNodes . item ( i ) . textContent || '' )
112133 if ( text ) items . push ( text )
113134 }
114135 return items
0 commit comments