11import { LEFT , RIGHT , SIDE } from '../const'
22import vari from '../var'
33import { NodeObj } from '../index'
4-
4+ import { encodeHTML } from '../utils/index'
55export type Top = HTMLElement
66
77export type Group = HTMLElement
@@ -36,7 +36,7 @@ export const createGroup = function(nodeObj: NodeObj) {
3636}
3737
3838export const shapeTpc = function ( tpc : Topic , nodeObj : NodeObj ) {
39- tpc . innerHTML = nodeObj . topic
39+ tpc . innerText = nodeObj . topic
4040
4141 if ( nodeObj . style ) {
4242 tpc . style . color = nodeObj . style . color || 'inherit'
@@ -56,23 +56,23 @@ export const shapeTpc = function(tpc: Topic, nodeObj: NodeObj) {
5656 const linkContainer = $d . createElement ( 'a' )
5757 linkContainer . className = 'hyper-link'
5858 linkContainer . target = '_blank'
59- linkContainer . innerHTML = '🔗'
59+ linkContainer . innerText = '🔗'
6060 linkContainer . href = nodeObj . hyperLink
6161 tpc . appendChild ( linkContainer )
6262 }
6363 if ( nodeObj . icons ) {
6464 const iconsContainer = $d . createElement ( 'span' )
6565 iconsContainer . className = 'icons'
6666 iconsContainer . innerHTML = nodeObj . icons
67- . map ( icon => `<span>${ icon } </span>` )
67+ . map ( icon => `<span>${ encodeHTML ( icon ) } </span>` )
6868 . join ( '' )
6969 tpc . appendChild ( iconsContainer )
7070 }
7171 if ( nodeObj . tags ) {
7272 const tagsContainer = $d . createElement ( 'div' )
7373 tagsContainer . className = 'tags'
7474 tagsContainer . innerHTML = nodeObj . tags
75- . map ( tag => `<span>${ tag } </span>` )
75+ . map ( tag => `<span>${ encodeHTML ( tag ) } </span>` )
7676 . join ( '' )
7777 tpc . appendChild ( tagsContainer )
7878 }
@@ -110,7 +110,7 @@ export function createInputDiv(tpc: Topic) {
110110 let div = $d . createElement ( 'div' )
111111 const origin = tpc . childNodes [ 0 ] . textContent as string
112112 tpc . appendChild ( div )
113- div . innerHTML = origin
113+ div . innerText = origin
114114 div . contentEditable = 'true'
115115 div . spellcheck = false
116116 div . style . cssText = `min-width:${ tpc . offsetWidth - 8 } px;`
@@ -161,7 +161,7 @@ export function createInputDiv(tpc: Topic) {
161161export const createExpander = function ( expanded : boolean | undefined ) : Expander {
162162 const expander : Expander = $d . createElement ( 'epd' )
163163 // 包含未定义 expanded 的情况,未定义视为展开
164- expander . innerHTML = expanded !== false ? '-' : '+'
164+ expander . innerText = expanded !== false ? '-' : '+'
165165 expander . expanded = expanded !== false
166166 expander . className = expanded !== false ? 'minus' : ''
167167 return expander
0 commit comments