88const videoEmbedKeywords = [ 'youtube.com' , 'youtu.be' , 'vimeo.com' ] ;
99const mediaExtensions = / \. ( 3 g p | a s f | a s x | a v i | f l v | m 4 a | m 4 p | m o v | m p 3 | m p 4 | m p e g | m p e g 2 | m p g | m p v | o g g | o g a | o g v | q t l | s m i | s m i l | w a v | w a x | w e b m | w m v | w m p | w m x ) ( \? .* ) ? $ / i;
1010
11+ const MAX_SIBLINGS_TO_CHECK = 5 ;
12+ const PARENT_SIBLING_LIMIT = 3 ;
13+
1114export default {
1215 id : 'has_transcript' ,
1316 evaluate : ( node ) => {
@@ -49,14 +52,37 @@ export default {
4952 } ,
5053} ;
5154
55+ /**
56+ * Helper function to collect text content from a series of sibling elements
57+ * @param {Element } startSibling - The first sibling element to start from
58+ * @param {number } maxCount - Maximum number of siblings to check
59+ * @return {string } - Concatenated text content from siblings
60+ */
61+ function collectSiblingText ( startSibling , maxCount ) {
62+ let text = '' ;
63+ let currentSibling = startSibling ;
64+ let siblingCount = 0 ;
65+
66+ while ( currentSibling && siblingCount < maxCount ) {
67+ const siblingText = currentSibling . textContent ?. trim ( ) ;
68+ if ( siblingText ) {
69+ text += siblingText + ' ' ;
70+ }
71+ currentSibling = currentSibling . nextElementSibling ;
72+ siblingCount ++ ;
73+ }
74+
75+ return text ;
76+ }
77+
5278function getSurroundingText ( node , radius = 250 ) {
5379 let text = '' ;
5480
55- // Include immediate next and previous siblings
56- if ( node . previousElementSibling ) {
81+ // Include immediate next and previous siblings (but skip noscript elements)
82+ if ( node . previousElementSibling && node . previousElementSibling . nodeName . toLowerCase ( ) !== 'noscript' ) {
5783 text += node . previousElementSibling . textContent . trim ( ) + ' ' ;
5884 }
59- if ( node . nextElementSibling ) {
85+ if ( node . nextElementSibling && node . nextElementSibling . nodeName . toLowerCase ( ) !== 'noscript' ) {
6086 text += node . nextElementSibling . textContent . trim ( ) + ' ' ;
6187 }
6288
@@ -67,11 +93,17 @@ function getSurroundingText( node, radius = 250 ) {
6793 if ( figcaption ) {
6894 text += figcaption . textContent . trim ( ) + ' ' ;
6995 }
96+
97+ // Check siblings of the figure element for transcript links
98+ text += collectSiblingText ( figure . nextElementSibling , MAX_SIBLINGS_TO_CHECK ) ;
7099 }
71100
72101 // Walk limited DOM subtree (media-wrapper, section, article, etc.)
73102 const parent = node . closest ( '.media-wrapper, figure, section, article' ) ;
74103 if ( parent ) {
104+ // Also check parent's siblings for transcript text
105+ text += collectSiblingText ( parent . nextElementSibling , PARENT_SIBLING_LIMIT ) ;
106+
75107 const nodeFilter = {
76108 acceptNode ( textNode ) {
77109 const style = window . getComputedStyle ( textNode . parentElement ) ;
0 commit comments