mirror of
https://github.com/go-gitea/gitea
synced 2024-11-22 05:01:20 +01:00
createElementFromHTML<T extends HTMLElement>
This commit is contained in:
parent
cd01c71926
commit
4eaf28d5cc
1 changed files with 2 additions and 2 deletions
|
@ -301,13 +301,13 @@ export function replaceTextareaSelection(textarea: HTMLTextAreaElement, text: st
|
|||
}
|
||||
|
||||
// Warning: Do not enter any unsanitized variables here
|
||||
export function createElementFromHTML<T = HTMLElement>(htmlString: string): T {
|
||||
export function createElementFromHTML<T extends HTMLElement>(htmlString: string): T {
|
||||
htmlString = htmlString.trim();
|
||||
// some tags like "tr" are special, it must use a correct parent container to create
|
||||
if (htmlString.startsWith('<tr')) {
|
||||
const container = document.createElement('table');
|
||||
container.innerHTML = htmlString;
|
||||
return container.querySelector('tr') as T;
|
||||
return container.querySelector<T>('tr');
|
||||
}
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = htmlString;
|
||||
|
|
Loading…
Reference in a new issue