forked from github/cinny
🦉 allow images
This commit is contained in:
@@ -474,14 +474,10 @@ export const getReactCustomHtmlParser = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name === 'img') {
|
if (name === 'img') {
|
||||||
const htmlSrc = mxcUrlToHttp(mx, props.src, params.useAuthentication);
|
const isMxc = typeof props.src === 'string' && props.src.startsWith('mxc://');
|
||||||
if (htmlSrc && props.src.startsWith('mxc://') === false) {
|
const htmlSrc = isMxc
|
||||||
return (
|
? mxcUrlToHttp(mx, props.src, params.useAuthentication)
|
||||||
<a href={htmlSrc} target="_blank" rel="noreferrer noopener">
|
: props.src;
|
||||||
{props.alt || props.title || htmlSrc}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (htmlSrc && 'data-mx-emoticon' in props) {
|
if (htmlSrc && 'data-mx-emoticon' in props) {
|
||||||
return (
|
return (
|
||||||
<span className={css.EmoticonBase}>
|
<span className={css.EmoticonBase}>
|
||||||
|
|||||||
@@ -105,26 +105,12 @@ const transformATag: Transformer = (tagName, attribs) => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const transformImgTag: Transformer = (tagName, attribs) => {
|
const transformImgTag: Transformer = (tagName, attribs) => ({
|
||||||
const { src } = attribs;
|
|
||||||
if (typeof src === 'string' && src.startsWith('mxc://') === false) {
|
|
||||||
return {
|
|
||||||
tagName: 'a',
|
|
||||||
attribs: {
|
|
||||||
href: src,
|
|
||||||
rel: 'noreferrer noopener',
|
|
||||||
target: '_blank',
|
|
||||||
},
|
|
||||||
text: attribs.alt || src,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
tagName,
|
tagName,
|
||||||
attribs: {
|
attribs: {
|
||||||
...attribs,
|
...attribs,
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
};
|
|
||||||
|
|
||||||
export const sanitizeCustomHtml = (customHtml: string): string =>
|
export const sanitizeCustomHtml = (customHtml: string): string =>
|
||||||
sanitizeHtml(customHtml, {
|
sanitizeHtml(customHtml, {
|
||||||
|
|||||||
Reference in New Issue
Block a user