-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathparser.ts
More file actions
33 lines (25 loc) · 772 Bytes
/
Copy pathparser.ts
File metadata and controls
33 lines (25 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Sections } from 'types';
type Content = {
url: string;
};
type Styles = {
align: 'left' | 'center' | 'right';
height: number;
float: 'none' | 'right' | 'left';
};
type ImageSectionParserArgs = {
content: Content;
styles: Styles;
};
const imageSectionParser = ({ content, styles }: ImageSectionParserArgs) => {
const { url } = content;
const { height, align, float = 'none' } = styles;
const hasFloat = float !== 'none';
const floatStyle = `align="${float}" `;
return `
${!hasFloat ? `<div data-importer="${Sections.IMAGE}" align="${align}">` : ''}
<img data-importer="${Sections.IMAGE}" ${hasFloat ? floatStyle : ''}height="${height}" src="${url}" />
${!hasFloat ? '</div>' : ''}
`;
};
export { imageSectionParser };