Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from Hugolify/17-shortcode-figure-ajout-dimage…
Browse files Browse the repository at this point in the history
…-via-le-cms

[Shortcode figure] fix regex and null values
  • Loading branch information
sebousan authored Nov 13, 2023
2 parents 7fbd8f9 + bd1c438 commit 775fdac
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions admin/app/editor/shortcodes/figure.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global CMS */
import { image_src } from '../../fields/image-src.js'
import { image_alt } from '../../fields/image-alt.js'
import { legend } from '../../fields/legend.js'
import { credit } from '../../fields/credit.js'
import {t} from "../../i18n/translater.js";
import { credit } from '../../fields/credit.js';
import { image_alt } from '../../fields/image-alt.js';
import { image_src } from '../../fields/image-src.js';
import { legend } from '../../fields/legend.js';
import { t } from "../../i18n/translater.js";

CMS.registerEditorComponent({
id: 'figure',
Expand All @@ -14,19 +14,19 @@ CMS.registerEditorComponent({
legend,
credit
],
pattern: /{{< figure (.*?) >}}/,
pattern: /{{< figure src="(.*?)" alt="(.*?)" legend="(.*?)" credit="(.*?)" >}}/,
fromBlock: function (match) {
return {
src: match[1],
alt: match[2],
legend: match[3],
credit: match[4]
src: match[1] ?? '',
alt: match[2] ?? '',
legend: match[3] ?? '',
credit: match[4] ?? ''
};
},
toBlock: function (obj) {
return `{{< figure src="${obj.src}" alt="${obj.alt}" legend="${obj.legend}" credit="${obj.credit}" >}}`;
return `{{< figure src="${obj.src ?? ''}" alt="${obj.alt ?? ''}" legend="${obj.legend ?? ''}" credit="${obj.credit ?? ''}" >}}`;
},
toPreview: function (obj) {
return `{{< figure src="${obj.src}" alt="${obj.alt}" legend="${obj.legend}" credit="${obj.credit}" >}}`;
return `{{< figure src="${obj.src ?? ''}" alt="${obj.alt ?? ''}" legend="${obj.legend ?? ''}" credit="${obj.credit ?? ''}" >}}`;
}
});

0 comments on commit 775fdac

Please sign in to comment.