11import './user-avatar' ;
22import { msg } from '@lit/localize' ;
3- import { css , html , LitElement , unsafeCSS } from 'lit' ;
3+ import { css , html , LitElement } from 'lit' ;
44import { property , state } from 'lit/decorators.js' ;
5- import { unsafeHTML } from 'lit/directives/unsafe-html.js' ;
65import baseStyles from './styles/base' ;
7- import contentStyles from './styles/content.css?inline' ;
86import { formatDate , timeAgo } from './utils/date' ;
97import './commenter-ua-bar' ;
108import { consume } from '@lit/context' ;
11- import sanitizeHtml from 'sanitize-html' ;
129import { configMapDataContext } from './context' ;
1310import type { ConfigMapData } from './types' ;
11+ import './comment-content' ;
1412
1513export class BaseCommentItem extends LitElement {
1614 @property ( { type : String } )
@@ -41,49 +39,6 @@ export class BaseCommentItem extends LitElement {
4139 @state ( )
4240 configMapData : ConfigMapData | undefined ;
4341
44- protected override firstUpdated ( ) {
45- const codeElements = this . shadowRoot ?. querySelectorAll ( 'pre>code' ) ;
46- if ( ! codeElements ?. length ) return ;
47-
48- Promise . all (
49- Array . from ( codeElements ) . map ( async ( codeblock ) => {
50- const lang =
51- this . extractLanguageFromCodeElement ( codeblock ) || 'plaintext' ;
52- const content = codeblock . textContent || '' ;
53-
54- try {
55- const { codeToHtml } = await import ( 'shiki/bundle/full' ) ;
56-
57- const html = await codeToHtml ( content , {
58- lang,
59- theme : 'github-dark' ,
60- } ) ;
61-
62- if ( codeblock . parentElement ) {
63- codeblock . parentElement . outerHTML = html ;
64- }
65- } catch ( error ) {
66- console . error ( 'Failed to highlight code:' , error ) ;
67- }
68- } )
69- ) ;
70- }
71-
72- private extractLanguageFromCodeElement ( codeElement : Element ) : string | null {
73- const supportedPrefixes = [ 'language-' , 'lang-' ] ;
74-
75- const langClass = Array . from ( codeElement . classList ) . find ( ( className ) =>
76- supportedPrefixes . some ( ( prefix ) => className . startsWith ( prefix ) )
77- ) ;
78-
79- if ( langClass ) {
80- const prefix = supportedPrefixes . find ( ( p ) => langClass . startsWith ( p ) ) ;
81- return prefix ? langClass . substring ( prefix . length ) : null ;
82- }
83-
84- return null ;
85- }
86-
8742 override render ( ) {
8843 return html `<div class= "item flex gap-3 py-4 ${ this . breath ? 'animate-breath' : '' } " >
8944 <div class= "item-avatar flex-none" >
@@ -121,14 +76,7 @@ export class BaseCommentItem extends LitElement {
12176 }
12277 </ div>
12378
124- <div class= "item-content mt-2.5 space-y-2.5 content" > <slot name= "pre-content" > </ slot> ${ unsafeHTML (
125- sanitizeHtml ( this . content , {
126- allowedAttributes : {
127- ...sanitizeHtml . defaults . allowedAttributes ,
128- code : [ 'class' ] ,
129- } ,
130- } )
131- ) } </ div>
79+ <div class= "item-content mt-2.5 space-y-2.5" > <slot name= "pre-content" > </ slot> <comment- content .content = ${ this . content } > </ comment- content> </ div>
13280
13381 <div class= "item-actions mt-2 flex items-center gap-3" >
13482 <slot name= "action" > </ slot>
@@ -141,7 +89,6 @@ export class BaseCommentItem extends LitElement {
14189
14290 static override styles = [
14391 ...baseStyles ,
144- unsafeCSS ( contentStyles ) ,
14592 css `
14693 .animate-breath {
14794 animation : breath 1s ease-in-out infinite;
0 commit comments