@@ -38,6 +38,8 @@ interface Subroot {
3838 branch ?: SBranch | BBranch
3939}
4040
41+ type GetNoteFunction = ( id : string ) => SNote | BNote | null ;
42+
4143function getSharedSubTreeRoot ( note : SNote | BNote | undefined ) : Subroot {
4244 if ( ! note || note . noteId === shareRoot . SHARE_ROOT_NOTE_ID ) {
4345 // share root itself is not shared
@@ -301,7 +303,7 @@ function renderText(result: Result, note: SNote | BNote) {
301303
302304 result . isEmpty = document . textContent ?. trim ( ) . length === 0 && document . querySelectorAll ( "img" ) . length === 0 ;
303305
304- const getNote = note instanceof BNote
306+ const getNote : GetNoteFunction = note instanceof BNote
305307 ? ( noteId : string ) => becca . getNote ( noteId )
306308 : ( noteId : string ) => shaca . getNote ( noteId ) ;
307309 const getAttachment = note instanceof BNote
@@ -319,7 +321,7 @@ function renderText(result: Result, note: SNote | BNote) {
319321 }
320322
321323 if ( linkEl . classList . contains ( "reference-link" ) ) {
322- cleanUpReferenceLinks ( linkEl ) ;
324+ cleanUpReferenceLinks ( linkEl , getNote ) ;
323325 }
324326
325327 if ( href ?. startsWith ( "#" ) ) {
@@ -347,7 +349,7 @@ function renderText(result: Result, note: SNote | BNote) {
347349 }
348350}
349351
350- function handleAttachmentLink ( linkEl : HTMLElement , href : string , getNote : ( id : string ) => SNote | BNote | null , getAttachment : ( id : string ) => BAttachment | SAttachment | null ) {
352+ function handleAttachmentLink ( linkEl : HTMLElement , href : string , getNote : GetNoteFunction , getAttachment : ( id : string ) => BAttachment | SAttachment | null ) {
351353 const linkRegExp = / a t t a c h m e n t I d = ( [ a - z A - Z 0 - 9 _ ] + ) / g;
352354 let attachmentMatch ;
353355 if ( ( attachmentMatch = linkRegExp . exec ( href ) ) ) {
@@ -392,13 +394,13 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: (id: s
392394 *
393395 * @param linkEl the <a> element to process.
394396 */
395- function cleanUpReferenceLinks ( linkEl : HTMLElement ) {
397+ function cleanUpReferenceLinks ( linkEl : HTMLElement , getNote : GetNoteFunction ) {
396398 // Note: this method is basically a reimplementation of getReferenceLinkTitleSync from the link service of the client.
397399 const href = linkEl . getAttribute ( "href" ) ?? "" ;
398400 if ( linkEl . classList . contains ( "attachment-link" ) ) return ;
399401
400402 const noteId = href . split ( "/" ) . at ( - 1 ) ;
401- const note = noteId ? shaca . getNote ( noteId ) : undefined ;
403+ const note = noteId ? getNote ( noteId ) : undefined ;
402404 if ( ! note ) {
403405 console . warn ( "Unable to find note " , noteId ) ;
404406 linkEl . innerHTML = "[missing note]" ;
0 commit comments