mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 02:46:04 +01:00 
			
		
		
		
	Fix suggestions for issues (#32380)
This commit is contained in:
		| @@ -298,22 +298,24 @@ export function replaceTextareaSelection(textarea: HTMLTextAreaElement, text: st | ||||
| } | ||||
|  | ||||
| // Warning: Do not enter any unsanitized variables here | ||||
| export function createElementFromHTML(htmlString: string) { | ||||
| export function createElementFromHTML(htmlString: string): HTMLElement { | ||||
|   const div = document.createElement('div'); | ||||
|   div.innerHTML = htmlString.trim(); | ||||
|   return div.firstChild as Element; | ||||
|   return div.firstChild as HTMLElement; | ||||
| } | ||||
|  | ||||
| export function createElementFromAttrs(tagName: string, attrs: Record<string, any>) { | ||||
| export function createElementFromAttrs(tagName: string, attrs: Record<string, any>, ...children: (Node|string)[]): HTMLElement { | ||||
|   const el = document.createElement(tagName); | ||||
|   for (const [key, value] of Object.entries(attrs)) { | ||||
|   for (const [key, value] of Object.entries(attrs || {})) { | ||||
|     if (value === undefined || value === null) continue; | ||||
|     if (typeof value === 'boolean') { | ||||
|       el.toggleAttribute(key, value); | ||||
|     } else { | ||||
|       el.setAttribute(key, String(value)); | ||||
|     } | ||||
|     // TODO: in the future we could make it also support "textContent" and "innerHTML" properties if needed | ||||
|   } | ||||
|   for (const child of children) { | ||||
|     el.append(child instanceof Node ? child : document.createTextNode(child)); | ||||
|   } | ||||
|   return el; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user