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

Commit 5c382f8

Browse files
committed
fix(plugins/plugin-client-common): Markdown image does not properly handle align attribute
Fixes #6551
1 parent fc97ab8 commit 5c382f8

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ export default class Markdown extends React.PureComponent<Props> {
7878
}
7979
}
8080

81-
private handleImage(src: string, width?: number) {
81+
private handleImage(src: string, props: { width?: number; align?: React.CSSProperties['float'] }) {
8282
const isLocal = !/^http/i.test(src)
8383
if (isLocal && this.props.fullpath) {
84+
const style = props ? { float: props.align } : undefined
8485
const absoluteSrc = isAbsolute(src) ? src : join(dirname(this.props.fullpath), src)
85-
return <img src={absoluteSrc} width={width} />
86+
87+
return <img src={absoluteSrc} width={props.width} style={style} data-float={props.align} />
8688
}
8789
}
8890

@@ -100,8 +102,14 @@ export default class Markdown extends React.PureComponent<Props> {
100102
if (/<img/.test(props.value)) {
101103
const srcMatch = props.value.match(/src="?([^"\s]+)"?/)
102104
const widthMatch = props.value.match(/width="?(\d+)"?/)
105+
const alignMatch = props.value.match(/align="?([^"\s]+)"?/)
103106
if (srcMatch) {
104-
return this.handleImage(srcMatch[1], widthMatch[1]) || <span />
107+
return (
108+
this.handleImage(srcMatch[1], {
109+
width: widthMatch && widthMatch[1],
110+
align: alignMatch && alignMatch[1]
111+
}) || <span />
112+
)
105113
}
106114
}
107115

@@ -174,7 +182,7 @@ export default class Markdown extends React.PureComponent<Props> {
174182
)
175183
},
176184
image: props => {
177-
return this.handleImage(props.src, props.width) || <img {...props} />
185+
return this.handleImage(props.src, props) || <img {...props} />
178186
},
179187
list: props => {
180188
return React.createElement(

plugins/plugin-client-common/web/css/static/ui.css

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -772,23 +772,12 @@ $kui--page-content-paragraph-padding: 0.375em;
772772
}
773773
.page-content h2,
774774
.page-h2 {
775-
font-size: 2em;
776-
font-weight: 300;
777-
margin: 1em 0;
778-
position: relative;
775+
font-size: 1.875em;
776+
font-weight: 500;
777+
margin: 0.875em 0 0.5em;
779778
line-height: 1.25;
780-
}
781-
.page-content h2::before,
782-
.page-h2::before {
783-
background-color: var(--color-content-divider);
784-
content: "";
785-
display: block;
786-
height: 1px;
787-
left: 0;
788-
position: absolute;
789-
bottom: -5px;
790-
width: 100%;
791-
z-index: 100;
779+
border-bottom: 1px solid var(--color-content-divider);
780+
padding-bottom: 5px;
792781
}
793782
.page-content > h3:first-child,
794783
.page-content > h2:first-child,
@@ -821,6 +810,18 @@ $kui--page-content-paragraph-padding: 0.375em;
821810
font-size: 1.25em;
822811
line-height: 2em;
823812
}
813+
.page-content img {
814+
&[data-float] {
815+
background-color: var(--color-sidecar-background-01);
816+
padding-bottom: 0.5em;
817+
}
818+
&[data-float="left"] {
819+
padding-right: 1em;
820+
}
821+
&[data-float="right"] {
822+
padding-left: 1em;
823+
}
824+
}
824825
.page-content ol,
825826
.page-content ul {
826827
font-size: inherit;

0 commit comments

Comments
 (0)