@@ -51,27 +51,31 @@ function cloneAttrsString(node) {
51
51
52
52
/**
53
53
* @param {import('cheerio').Cheerio } article
54
- * @returns {void }
54
+ * @param {string } selector
55
+ * @param {($node: import('cheerio').Cheerio<Element>, attrs: string, content: string) => string } cb
55
56
*/
56
- function replaceWRSSemantic ( article ) {
57
- const listStrong = article . find ( 'span.control' ) ;
57
+ function replaceNode ( article , selector , cb ) {
58
+ const listStrong = article . find ( selector ) ;
58
59
59
60
for ( let i = 0 , length = listStrong . length ; i < length ; i ++ ) {
60
- const strong = listStrong . eq ( i ) ;
61
- const node = listStrong [ i ] ;
62
- const newNode = `<b ${ cloneAttrsString ( node ) } >${ strong . html ( ) } </b>` ;
63
- strong . replaceWith ( newNode ) ;
61
+ const $node = listStrong . eq ( i ) ;
62
+ const newNode = cb ( $node , cloneAttrsString ( listStrong [ i ] ) , $node . html ( ) ) ;
63
+ $node . replaceWith ( newNode ) ;
64
64
}
65
+ }
65
66
67
+ /**
68
+ * @param {import('cheerio').Cheerio } article
69
+ * @returns {void }
70
+ */
71
+ function replaceWRSSemantic ( article ) {
72
+ replaceNode ( article , 'span.control' , ( $node , attrs , content ) => (
73
+ `<b ${ attrs } >${ content } </b>`
74
+ ) ) ;
66
75
67
- const listCode = article . find ( 'div.code-block' ) ;
68
-
69
- for ( let i = 0 , length = listCode . length ; i < length ; i ++ ) {
70
- const code = listCode . eq ( i ) ;
71
- const node = listStrong [ i ] ;
72
- const newNode = `<code ${ cloneAttrsString ( node ) } >${ code . html ( ) } </code>` ;
73
- code . replaceWith ( newNode ) . addClass ( 'code' ) ;
74
- }
76
+ replaceNode ( article , 'div.code-block' , ( $node , attrs , content ) => (
77
+ `<code ${ attrs } >${ content } </code>`
78
+ ) ) ;
75
79
}
76
80
77
81
/**
0 commit comments