11import { appendTemplate , safeUrl , strip } from '../util/attachTemplate.js' ;
2+ import MyTrustedTypes from '../util/MyTrustedTypes.js' ;
23// Was: import MyElement from '../MyElement.js';
34
45const { fetch, HTMLElement, Request, location } = window ;
@@ -15,6 +16,8 @@ const { fetch, HTMLElement, Request, location } = window;
1516 * @since 1.3.0
1617 */
1718export class MyFeedElement extends HTMLElement {
19+ #trustedTypes;
20+
1821 static getTag ( ) { return 'my-feed' ; }
1922
2023 get href ( ) {
@@ -45,6 +48,7 @@ export class MyFeedElement extends HTMLElement {
4548 }
4649
4750 async connectedCallback ( ) {
51+ await this . #loadTrustedTypes( ) ;
4852 const { data, resp, req } = await this . #fetchFeed( ) ;
4953
5054 const FILTERED = this . #filterItems( data . items ) ;
@@ -82,14 +86,17 @@ export class MyFeedElement extends HTMLElement {
8286 return filtered ;
8387 }
8488
89+ get #policyId ( ) { return 'allowAnchorListPlus' ; }
90+
8591 #makeListItem ( item , open ) {
92+ const createHTML = ( s ) => this . #trustedTypes. createHTML ( this . #policyId , s ) ;
8693 const { skip, guid, link, pubDate, title, url, time, tags, content, content_html } = item ; /* eslint-disable-line camelcase */
8794
8895 if ( skip ) return '<template><!-- skip --></template>' ;
8996
9097 // @TODO : security! - _saferHtml()
9198 const CONTENT = content || content_html || null ; /* eslint-disable-line camelcase */
92- const DETAILS = CONTENT ? `<details part="details" ${ open ? 'open' : '' } ><summary part="summary">More</summary>${ CONTENT } </details>` : null ;
99+ const DETAILS = CONTENT ? `<details part="details" ${ open ? 'open' : '' } ><summary part="summary">More</summary>${ createHTML ( CONTENT ) } </details>` : null ;
93100 // Be liberal in what we accept - 'link' or 'url'.
94101 // console.debug('makeListItem:', item);
95102 return `<template>
@@ -119,4 +126,9 @@ export class MyFeedElement extends HTMLElement {
119126 const feedUrl = this . toJson ? this . #rssToJsonService + encodeURIComponent ( PARSED . href ) : PARSED . href ;
120127 return new Request ( feedUrl ) ;
121128 }
129+
130+ async #loadTrustedTypes ( ) {
131+ this . #trustedTypes = new MyTrustedTypes ( ) ;
132+ await this . #trustedTypes. load ( ) ;
133+ }
122134}
0 commit comments