1
1
import './user-avatar' ;
2
2
import { msg } from '@lit/localize' ;
3
- import { css , html , LitElement , unsafeCSS } from 'lit' ;
3
+ import { css , html , LitElement } from 'lit' ;
4
4
import { property , state } from 'lit/decorators.js' ;
5
- import { unsafeHTML } from 'lit/directives/unsafe-html.js' ;
6
5
import baseStyles from './styles/base' ;
7
- import contentStyles from './styles/content.css?inline' ;
8
6
import { formatDate , timeAgo } from './utils/date' ;
9
7
import './commenter-ua-bar' ;
10
8
import { consume } from '@lit/context' ;
11
- import sanitizeHtml from 'sanitize-html' ;
12
9
import { configMapDataContext } from './context' ;
13
10
import type { ConfigMapData } from './types' ;
11
+ import './comment-content' ;
14
12
15
13
export class BaseCommentItem extends LitElement {
16
14
@property ( { type : String } )
@@ -41,49 +39,6 @@ export class BaseCommentItem extends LitElement {
41
39
@state ( )
42
40
configMapData : ConfigMapData | undefined ;
43
41
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
-
87
42
override render ( ) {
88
43
return html `<div class= "item flex gap-3 py-4 ${ this . breath ? 'animate-breath' : '' } " >
89
44
<div class= "item-avatar flex-none" >
@@ -121,14 +76,7 @@ export class BaseCommentItem extends LitElement {
121
76
}
122
77
</ div>
123
78
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>
132
80
133
81
<div class= "item-actions mt-2 flex items-center gap-3" >
134
82
<slot name= "action" > </ slot>
@@ -141,7 +89,6 @@ export class BaseCommentItem extends LitElement {
141
89
142
90
static override styles = [
143
91
...baseStyles ,
144
- unsafeCSS ( contentStyles ) ,
145
92
css `
146
93
.animate-breath {
147
94
animation : breath 1s ease-in-out infinite;
0 commit comments