Skip to content

Commit dbc5d64

Browse files
committed
HTML attributes within render option
1 parent 16b28d5 commit dbc5d64

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/helper/find-embeded-object.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ export function findRenderString(
5151
if ((!renderModel && renderModel === undefined) || (!object && object === undefined)) {
5252
return '';
5353
}
54-
let text = null
55-
if (object["sys-style-type"] !== ASSET.DISPLAYABLE && (object as EmbeddedEntry)["#text"]) {
56-
text = (object as EmbeddedEntry)["#text"]
57-
} else if ((object as EmbeddedEntry).alt) {
58-
text = (object as EmbeddedEntry).alt
59-
}
54+
6055
if (renderOptions && renderOptions[object['sys-style-type']] !== undefined) {
6156
const renderFunction = renderOptions[object['sys-style-type']] as RenderObject;
6257

@@ -65,11 +60,11 @@ export function findRenderString(
6560
typeof renderFunction !== 'function' &&
6661
renderFunction[(object as EmbeddedEntry)['data-sys-content-type-uid']] !== undefined
6762
) {
68-
return (renderFunction as RenderContentType)[(object as EmbeddedEntry)['data-sys-content-type-uid']](renderModel, text);
63+
return (renderFunction as RenderContentType)[(object as EmbeddedEntry)['data-sys-content-type-uid']](renderModel, object);
6964
} else if (typeof renderFunction === 'function') {
70-
return renderFunction(renderModel, text);
65+
return renderFunction(renderModel, object);
7166
}
7267
}
73-
const defaultRenderFunction = defaultOptions[object['sys-style-type']] as RenderObject;
74-
return defaultRenderFunction(renderModel, text);
68+
const defaultRenderFunction = defaultOptions[object['sys-style-type']] as RenderObject;
69+
return defaultRenderFunction(renderModel, object);
7570
}

src/options/default-options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export const defaultOptions: RenderOption = {
66
[ENTRY.BLOCK]: (entry) =>
77
`<div><p>${entry.title || entry.uid}</p><p>Content type: <span>${entry._content_type_uid}</span></p></div>`,
88
[ENTRY.INLINE]: (entry) => `<span>${entry.title || entry.uid}</span>`,
9-
[ENTRY.LINK]: (entry, text) => `<a href="${entry.url}">${text || entry.title || entry.uid}</a>`, // Todo Check for link with Manish
10-
[ASSET.DOWNLOADABLE]: (asset, text) => `<a href="${asset.url}">${text || asset.title || asset.filename || asset.uid}</a>`,
11-
[ASSET.DISPLAYABLE]: (asset, text) => {
12-
const displaycontent = `<img src="${asset.url}" alt="${text || asset.title || asset.filename || asset.uid}" />`
9+
[ENTRY.LINK]: (entry, embedAttributes) => `<a href="${entry.url}">${embedAttributes[`#text`] || entry.title || entry.uid}</a>`, // Todo Check for link with Manish
10+
[ASSET.DOWNLOADABLE]: (asset, embedAttributes) => `<a href="${asset.url}">${embedAttributes[`#text`] || asset.title || asset.filename || asset.uid}</a>`,
11+
[ASSET.DISPLAYABLE]: (asset, embedAttributes) => {
12+
const displaycontent = `<img src="${asset.url}" alt="${embedAttributes.alt || asset.title || asset.filename || asset.uid}" />`
1313
return displaycontent
1414
},
1515
};

src/options/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Entry, ContentTypeEntry } from '../Models/entry-model';
22
import { AssetModel } from '../Models/asset-model';
3+
import { EmbedAttributes } from '../Models/embed-attributes-model';
34

4-
export type RenderObject = (object: ContentTypeEntry | AssetModel, text?: string) => string;
5+
export type RenderObject = (object: ContentTypeEntry | AssetModel, embedAttributes: EmbedAttributes) => string;
56

67
export interface RenderOption {
78
[embedType: string]: RenderObject | RenderContentType;

0 commit comments

Comments
 (0)