mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-07 18:04:56 -04:00
feat: import html-to-react from https://github.com/hedgedoc/html-to-react
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
5dc6526278
commit
84527f065c
37 changed files with 1388 additions and 0 deletions
34
html-to-react/src/utils/generatePropsFromAttributes.ts
Normal file
34
html-to-react/src/utils/generatePropsFromAttributes.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { mapHtmlAttributesToReactElementAttributes } from './mapHtmlAttributesToReactElementAttributes.js'
|
||||
import { convertInlineStyleToMap } from './convertInlineStyleToMap.js'
|
||||
|
||||
/**
|
||||
* Generates props for a React element from an object of HTML attributes
|
||||
*
|
||||
* @param {Object} attributes The HTML attributes
|
||||
* @param {String} key The key to give the react element
|
||||
*/
|
||||
export function generatePropsFromAttributes(
|
||||
attributes: Record<string, string>,
|
||||
key: string | number
|
||||
): Record<string, string | Record<string, string>> {
|
||||
const props = Object.assign(
|
||||
{ key },
|
||||
mapHtmlAttributesToReactElementAttributes(attributes)
|
||||
) as Record<string, string | Record<string, string>>
|
||||
|
||||
if (props.style) {
|
||||
if (typeof props.style === 'string') {
|
||||
props.style = convertInlineStyleToMap(props.style)
|
||||
}
|
||||
} else {
|
||||
delete props.style
|
||||
}
|
||||
|
||||
return props
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue