@@ -6,33 +6,17 @@ import {insertTextIntoField, setFieldText} from 'text-field-edit';
66import features from '../feature-manager.js' ;
77import looseParseInt from '../helpers/loose-parse-int.js' ;
88import observe from '../helpers/selector-observer.js' ;
9-
10- function interpretNode ( node : ChildNode ) : string | void {
11- switch ( node instanceof Element && node . tagName ) {
12- case false :
13- case 'A' : {
14- return node . textContent ;
15- }
16-
17- case 'CODE' : {
18- // Restore backticks that GitHub loses when rendering them
19- return '`' + node . textContent + '`' ;
20- }
21-
22- default :
23- // Ignore other nodes, like `<span>...</span>` that appears when commits have a body
24- }
25- }
9+ import parseRenderedText from '../github-helpers/parse-rendered-text.js' ;
2610
2711function getFirstCommit ( firstCommit : HTMLElement ) : { title : string ; body : string | undefined } {
2812 const body = $optional ( '.Details-content--hidden pre' , firstCommit )
2913 ?. textContent
3014 . trim ( ) ?? undefined ;
3115
32- const title = [ ... firstCommit . childNodes ]
33- . map ( node => interpretNode ( node ) )
34- . join ( '' )
35- . trim ( ) ;
16+ const title = parseRenderedText ( firstCommit . firstElementChild ! , ( { nodeName } ) =>
17+ // Exclude expand body button
18+ nodeName === '#text' || nodeName === 'CODE' ? NodeFilter . FILTER_ACCEPT : NodeFilter . FILTER_REJECT ,
19+ ) ;
3620
3721 return { title, body} ;
3822}
@@ -89,8 +73,14 @@ void features.add(import.meta.url, {
8973} ) ;
9074
9175/*
76+
9277Test URLs
9378
94- Few commit: https://github.com/refined-github/sandbox/compare/rendered-commit-title?expand=1
95- Many commits: https://github.com/refined-github/refined-github/compare/refined-github:refined-github:esbuild-2...pgimalac:refined-github:pgimalac/fit-rendered-markdown?expand=1
79+ Few commits:
80+ - https://github.com/refined-github/sandbox/compare/rendered-commit-title?expand=1
81+ - https://github.com/refined-github/sandbox/compare/9012?expand=1
82+ Many commits:
83+ - https://github.com/refined-github/refined-github/compare/refined-github:refined-github:esbuild-2...pgimalac:refined-github:pgimalac/fit-rendered-markdown?expand=1
84+ - https://github.com/refined-github/sandbox/compare/9012-2?expand=1
85+
9686*/
0 commit comments