Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 1578e58

Browse files
committed
fix(plugins/plugin-client-common): Markdown handling of consecutive img tags only shows first
Fixes #6602
1 parent fd46054 commit 1578e58

File tree

1 file changed

+22
-13
lines changed
  • plugins/plugin-client-common/src/components/Content

1 file changed

+22
-13
lines changed

plugins/plugin-client-common/src/components/Content/Markdown.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export default class Markdown extends React.PureComponent<Props> {
6868
}
6969
}
7070

71-
private handleImage(src: string, props: { width?: number; align?: React.CSSProperties['float'] }) {
71+
private handleImage(src: string, props: { width?: number; align?: React.CSSProperties['float'] }, key?: string) {
7272
const isLocal = !/^http/i.test(src)
7373
if (isLocal && this.props.fullpath) {
7474
const style = props ? { float: props.align } : undefined
7575
const absoluteSrc = isAbsolute(src) ? src : join(dirname(this.props.fullpath), src)
7676

77-
return <img src={absoluteSrc} width={props.width} style={style} data-float={props.align} />
77+
return <img key={key} src={absoluteSrc} width={props.width} style={style} data-float={props.align} />
7878
}
7979
}
8080

@@ -91,17 +91,26 @@ export default class Markdown extends React.PureComponent<Props> {
9191
renderers={{
9292
html: props => {
9393
if (/<img/.test(props.value)) {
94-
const srcMatch = props.value.match(/src="?([^"\s]+)"?/)
95-
const widthMatch = props.value.match(/width="?(\d+)"?/)
96-
const alignMatch = props.value.match(/align="?([^"\s]+)"?/)
97-
if (srcMatch) {
98-
return (
99-
this.handleImage(srcMatch[1], {
100-
width: widthMatch && widthMatch[1],
101-
align: alignMatch && alignMatch[1]
102-
}) || <span />
103-
)
104-
}
94+
const images = props.value.split(/<img/).filter(_ => _)
95+
const imageTags = images
96+
.map((value, idx) => {
97+
const srcMatch = value.match(/src="?([^"\s]+)"?/)
98+
const widthMatch = value.match(/width="?(\d+)"?/)
99+
const alignMatch = value.match(/align="?([^"\s]+)"?/)
100+
if (srcMatch) {
101+
return this.handleImage(
102+
srcMatch[1],
103+
{
104+
width: widthMatch && widthMatch[1],
105+
align: alignMatch && alignMatch[1]
106+
},
107+
idx
108+
)
109+
}
110+
})
111+
.filter(_ => _)
112+
113+
return <React.Fragment>{imageTags}</React.Fragment>
105114
}
106115

107116
// Render the raw string for all other raw html tags

0 commit comments

Comments
 (0)