@ndla/article-converter 6.0.42 → 6.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/extractEmbedMeta.js +8 -8
- package/es/index.js +2 -2
- package/es/plugins/anchorPlugin.js +3 -3
- package/es/plugins/asidePlugin.js +4 -4
- package/es/plugins/copyParagraphPlugin.js +4 -4
- package/es/plugins/ddPlugin.js +2 -2
- package/es/plugins/divPlugin.js +14 -14
- package/es/plugins/dtPlugin.js +2 -2
- package/es/plugins/embed/KeyFigureEmbedPlugin.js +5 -5
- package/es/plugins/embed/audioEmbedPlugin.js +3 -3
- package/es/plugins/embed/blogPostEmbedPlugin.js +5 -5
- package/es/plugins/embed/brightcoveEmbedPlugin.js +3 -3
- package/es/plugins/embed/campaignBlockPlugin.js +5 -5
- package/es/plugins/embed/codeEmbedPlugin.js +3 -3
- package/es/plugins/embed/conceptEmbedPlugin.js +3 -3
- package/es/plugins/embed/conceptListEmbedPlugin.js +3 -3
- package/es/plugins/embed/contactBlockEmbedPlugin.js +4 -4
- package/es/plugins/embed/contentLinkEmbedPlugin.js +3 -3
- package/es/plugins/embed/externalEmbedPlugin.js +3 -3
- package/es/plugins/embed/fileEmbedPlugin.js +5 -5
- package/es/plugins/embed/footnoteEmbedPlugin.js +3 -3
- package/es/plugins/embed/h5pEmbedPlugin.js +3 -3
- package/es/plugins/embed/iframeEmbedPlugin.js +3 -3
- package/es/plugins/embed/imageEmbedPlugin.js +4 -4
- package/es/plugins/embed/index.js +27 -27
- package/es/plugins/embed/linkBlockEmbedPlugin.js +3 -3
- package/es/plugins/embed/relatedContentEmbedPlugin.js +3 -3
- package/es/plugins/h3Plugin.js +1 -1
- package/es/plugins/index.js +15 -15
- package/es/plugins/mathPlugin.js +2 -2
- package/es/plugins/navPlugin.js +3 -3
- package/es/plugins/oembed/anchorPlugin.js +3 -3
- package/es/plugins/olPlugin.js +5 -5
- package/es/plugins/paragraphPlugin.js +3 -3
- package/es/plugins/spanPlugin.js +3 -3
- package/es/plugins/tablePlugin.js +2 -2
- package/es/plugins/ulPlugin.js +3 -3
- package/es/transform.js +9 -9
- package/lib/extractEmbedMeta.d.ts +1 -1
- package/lib/extractEmbedMeta.js +7 -7
- package/lib/index.d.ts +3 -3
- package/lib/plugins/anchorPlugin.d.ts +1 -1
- package/lib/plugins/asidePlugin.d.ts +1 -1
- package/lib/plugins/asidePlugin.js +2 -2
- package/lib/plugins/copyParagraphPlugin.d.ts +1 -1
- package/lib/plugins/copyParagraphPlugin.js +2 -2
- package/lib/plugins/ddPlugin.d.ts +1 -1
- package/lib/plugins/divPlugin.d.ts +1 -1
- package/lib/plugins/divPlugin.js +11 -11
- package/lib/plugins/dtPlugin.d.ts +1 -1
- package/lib/plugins/embed/KeyFigureEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/KeyFigureEmbedPlugin.js +3 -3
- package/lib/plugins/embed/audioEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/audioEmbedPlugin.js +1 -1
- package/lib/plugins/embed/blogPostEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/blogPostEmbedPlugin.js +3 -3
- package/lib/plugins/embed/brightcoveEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/brightcoveEmbedPlugin.js +1 -1
- package/lib/plugins/embed/campaignBlockPlugin.d.ts +1 -1
- package/lib/plugins/embed/campaignBlockPlugin.js +3 -3
- package/lib/plugins/embed/codeEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/codeEmbedPlugin.js +1 -1
- package/lib/plugins/embed/conceptEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/conceptEmbedPlugin.js +1 -1
- package/lib/plugins/embed/conceptListEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/conceptListEmbedPlugin.js +1 -1
- package/lib/plugins/embed/contactBlockEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/contactBlockEmbedPlugin.js +2 -2
- package/lib/plugins/embed/contentLinkEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/contentLinkEmbedPlugin.js +1 -1
- package/lib/plugins/embed/externalEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/externalEmbedPlugin.js +1 -1
- package/lib/plugins/embed/fileEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/fileEmbedPlugin.js +3 -3
- package/lib/plugins/embed/footnoteEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/footnoteEmbedPlugin.js +1 -1
- package/lib/plugins/embed/h5pEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/h5pEmbedPlugin.js +1 -1
- package/lib/plugins/embed/iframeEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/iframeEmbedPlugin.js +1 -1
- package/lib/plugins/embed/imageEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/imageEmbedPlugin.js +2 -2
- package/lib/plugins/embed/index.d.ts +1 -1
- package/lib/plugins/embed/index.js +9 -9
- package/lib/plugins/embed/linkBlockEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/linkBlockEmbedPlugin.js +1 -1
- package/lib/plugins/embed/relatedContentEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/relatedContentEmbedPlugin.js +1 -1
- package/lib/plugins/h3Plugin.d.ts +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/lib/plugins/mathPlugin.d.ts +1 -1
- package/lib/plugins/mathPlugin.js +1 -1
- package/lib/plugins/navPlugin.d.ts +1 -1
- package/lib/plugins/navPlugin.js +1 -1
- package/lib/plugins/oembed/anchorPlugin.d.ts +1 -1
- package/lib/plugins/olPlugin.d.ts +1 -1
- package/lib/plugins/olPlugin.js +3 -3
- package/lib/plugins/paragraphPlugin.d.ts +1 -1
- package/lib/plugins/paragraphPlugin.js +2 -2
- package/lib/plugins/spanPlugin.d.ts +1 -1
- package/lib/plugins/spanPlugin.js +2 -2
- package/lib/plugins/tablePlugin.d.ts +1 -1
- package/lib/plugins/types.d.ts +2 -2
- package/lib/plugins/ulPlugin.d.ts +1 -1
- package/lib/plugins/ulPlugin.js +1 -1
- package/lib/transform.d.ts +1 -1
- package/lib/transform.js +5 -5
- package/package.json +5 -5
- package/src/extractEmbedMeta.ts +9 -9
- package/src/index.ts +3 -3
- package/src/plugins/anchorPlugin.tsx +4 -4
- package/src/plugins/asidePlugin.tsx +5 -5
- package/src/plugins/copyParagraphPlugin.tsx +5 -5
- package/src/plugins/ddPlugin.tsx +3 -3
- package/src/plugins/divPlugin.tsx +15 -15
- package/src/plugins/dtPlugin.tsx +3 -3
- package/src/plugins/embed/KeyFigureEmbedPlugin.tsx +7 -7
- package/src/plugins/embed/audioEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/blogPostEmbedPlugin.tsx +7 -7
- package/src/plugins/embed/brightcoveEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/campaignBlockPlugin.tsx +11 -8
- package/src/plugins/embed/codeEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/conceptEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/conceptListEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/contactBlockEmbedPlugin.tsx +6 -6
- package/src/plugins/embed/contentLinkEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/externalEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/fileEmbedPlugin.tsx +7 -7
- package/src/plugins/embed/footnoteEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/h5pEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/iframeEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/imageEmbedPlugin.tsx +6 -6
- package/src/plugins/embed/index.ts +28 -28
- package/src/plugins/embed/linkBlockEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/relatedContentEmbedPlugin.tsx +5 -5
- package/src/plugins/h3Plugin.tsx +2 -2
- package/src/plugins/index.ts +16 -16
- package/src/plugins/mathPlugin.tsx +3 -3
- package/src/plugins/navPlugin.tsx +4 -4
- package/src/plugins/oembed/anchorPlugin.tsx +4 -4
- package/src/plugins/olPlugin.tsx +6 -6
- package/src/plugins/paragraphPlugin.tsx +4 -4
- package/src/plugins/spanPlugin.tsx +4 -4
- package/src/plugins/tablePlugin.tsx +3 -3
- package/src/plugins/types.ts +2 -2
- package/src/plugins/ulPlugin.tsx +5 -5
- package/src/transform.tsx +11 -11
package/es/plugins/h3Plugin.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
10
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
11
11
|
export const h3Plugin = (node, converterOpts, opts) => {
|
|
12
12
|
const props = attributesToProps(node.attribs);
|
package/es/plugins/index.js
CHANGED
|
@@ -6,21 +6,21 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { anchorPlugin } from
|
|
10
|
-
import { asidePlugin } from
|
|
11
|
-
import { copyParagraphPlugin } from
|
|
12
|
-
import { ddPlugin } from
|
|
13
|
-
import { divPlugin } from
|
|
14
|
-
import { dtPlugin } from
|
|
15
|
-
import { h3Plugin } from
|
|
16
|
-
import { mathPlugin } from
|
|
17
|
-
import { navPlugin } from
|
|
18
|
-
import { anchorPlugin as oembedAnchorPlugin } from
|
|
19
|
-
import { olPlugin } from
|
|
20
|
-
import { paragraphPlugin } from
|
|
21
|
-
import { spanPlugin } from
|
|
22
|
-
import { tablePlugin } from
|
|
23
|
-
import { ulPlugin } from
|
|
9
|
+
import { anchorPlugin } from "./anchorPlugin";
|
|
10
|
+
import { asidePlugin } from "./asidePlugin";
|
|
11
|
+
import { copyParagraphPlugin } from "./copyParagraphPlugin";
|
|
12
|
+
import { ddPlugin } from "./ddPlugin";
|
|
13
|
+
import { divPlugin } from "./divPlugin";
|
|
14
|
+
import { dtPlugin } from "./dtPlugin";
|
|
15
|
+
import { h3Plugin } from "./h3Plugin";
|
|
16
|
+
import { mathPlugin } from "./mathPlugin";
|
|
17
|
+
import { navPlugin } from "./navPlugin";
|
|
18
|
+
import { anchorPlugin as oembedAnchorPlugin } from "./oembed/anchorPlugin";
|
|
19
|
+
import { olPlugin } from "./olPlugin";
|
|
20
|
+
import { paragraphPlugin } from "./paragraphPlugin";
|
|
21
|
+
import { spanPlugin } from "./spanPlugin";
|
|
22
|
+
import { tablePlugin } from "./tablePlugin";
|
|
23
|
+
import { ulPlugin } from "./ulPlugin";
|
|
24
24
|
export const basePlugins = {
|
|
25
25
|
h2: copyParagraphPlugin,
|
|
26
26
|
h3: h3Plugin,
|
package/es/plugins/mathPlugin.js
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps } from
|
|
9
|
+
import { attributesToProps } from "html-react-parser";
|
|
10
10
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
11
11
|
export const mathPlugin = node => {
|
|
12
12
|
const {
|
|
13
|
-
|
|
13
|
+
"data-math": mathContent,
|
|
14
14
|
...props
|
|
15
15
|
} = attributesToProps(node.attribs);
|
|
16
16
|
// @ts-ignore
|
package/es/plugins/navPlugin.js
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
10
|
-
import { LinkBlockSection } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { LinkBlockSection } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const navPlugin = (node, opts) => {
|
|
13
|
-
if (node.attribs[
|
|
13
|
+
if (node.attribs["data-type"] === "link-block-list") {
|
|
14
14
|
const props = attributesToProps(node.attribs);
|
|
15
15
|
return _jsx(LinkBlockSection, {
|
|
16
16
|
...props,
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
10
|
-
import SafeLink from
|
|
11
|
-
import { getPossiblyRelativeUrl } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import SafeLink from "@ndla/safelink";
|
|
11
|
+
import { getPossiblyRelativeUrl } from "@ndla/ui";
|
|
12
12
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
13
13
|
export const anchorPlugin = (node, options, _ref) => {
|
|
14
14
|
let {
|
package/es/plugins/olPlugin.js
CHANGED
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
10
|
-
import { OrderedList } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { OrderedList } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const olPlugin = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
|
14
|
-
const letterClass = node.attribs[
|
|
15
|
-
const num = node.attribs[
|
|
14
|
+
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
15
|
+
const num = node.attribs["start"];
|
|
16
16
|
const numClass = num ? `ol-reset-${num}` : false;
|
|
17
|
-
const classes = [node.attribs.class ?? false, letterClass, numClass].filter(c => !!c).join(
|
|
17
|
+
const classes = [node.attribs.class ?? false, letterClass, numClass].filter(c => !!c).join(" ");
|
|
18
18
|
return _jsx(OrderedList, {
|
|
19
19
|
...props,
|
|
20
20
|
className: classes.length ? classes : undefined,
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
10
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
11
11
|
export const paragraphPlugin = (node, converterOpts, opts) => {
|
|
12
12
|
const props = attributesToProps(node.attribs);
|
|
13
|
-
if (node.attribs[
|
|
14
|
-
const classes = [node.attribs.class ??
|
|
13
|
+
if (node.attribs["data-align"] === "center") {
|
|
14
|
+
const classes = [node.attribs.class ?? "", "u-text-center"].filter(c => !!c).join(" ");
|
|
15
15
|
return _jsx("p", {
|
|
16
16
|
...props,
|
|
17
17
|
lang: opts.articleLanguage,
|
package/es/plugins/spanPlugin.js
CHANGED
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
10
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
11
11
|
export const spanPlugin = (node, opts) => {
|
|
12
|
-
if (node.attribs[
|
|
12
|
+
if (node.attribs["data-size"] === "large") {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
|
14
14
|
return _jsx("span", {
|
|
15
15
|
...props,
|
|
16
16
|
"data-size": undefined,
|
|
17
|
-
className: `${node.attribs.class ??
|
|
17
|
+
className: `${node.attribs.class ?? ""} u-large-body-text`,
|
|
18
18
|
children: domToReact(node.children, opts)
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
10
|
-
import { Table } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { Table } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const tablePlugin = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
package/es/plugins/ulPlugin.js
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
10
|
-
import { UnOrderedList } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { UnOrderedList } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const ulPlugin = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
|
14
|
-
const classes = [node.attribs.class ??
|
|
14
|
+
const classes = [node.attribs.class ?? "", node.attribs["data-type"] === "two-column" ? "o-list--two-columns" : ""].filter(c => !!c).join(" ");
|
|
15
15
|
return _jsx(UnOrderedList, {
|
|
16
16
|
...props,
|
|
17
17
|
className: classes,
|
package/es/transform.js
CHANGED
|
@@ -6,26 +6,26 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import parse from
|
|
10
|
-
import { UnknownEmbed } from
|
|
11
|
-
import { basePlugins, oembedPlugins } from
|
|
12
|
-
import { embedPlugins } from
|
|
9
|
+
import parse from "html-react-parser";
|
|
10
|
+
import { UnknownEmbed } from "@ndla/ui";
|
|
11
|
+
import { basePlugins, oembedPlugins } from "./plugins";
|
|
12
|
+
import { embedPlugins } from "./plugins/embed";
|
|
13
13
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
14
14
|
const transform = (content, opts) => {
|
|
15
15
|
const plugins = opts?.isOembed ? oembedPlugins : basePlugins;
|
|
16
16
|
const options = {
|
|
17
17
|
replace: node => {
|
|
18
|
-
if (!(
|
|
18
|
+
if (!("attribs" in node)) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
if (plugins[node.name]) {
|
|
22
22
|
return plugins[node.name](node, options, opts);
|
|
23
23
|
}
|
|
24
|
-
if (node.name ===
|
|
25
|
-
if (embedPlugins[node.attribs[
|
|
26
|
-
return embedPlugins[node.attribs[
|
|
24
|
+
if (node.name === "ndlaembed") {
|
|
25
|
+
if (embedPlugins[node.attribs["data-resource"]]) {
|
|
26
|
+
return embedPlugins[node.attribs["data-resource"]](node, options, opts);
|
|
27
27
|
} else {
|
|
28
|
-
const embed = JSON.parse(node.attribs[
|
|
28
|
+
const embed = JSON.parse(node.attribs["data-json"]);
|
|
29
29
|
return _jsx(UnknownEmbed, {
|
|
30
30
|
embed: embed
|
|
31
31
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { EmbedMetaData } from
|
|
8
|
+
import { EmbedMetaData } from "@ndla/types-embed";
|
|
9
9
|
declare const extractEmbedMeta: (embed: string) => EmbedMetaData | undefined;
|
|
10
10
|
export declare const extractEmbedMetas: (embed: string) => EmbedMetaData[];
|
|
11
11
|
export default extractEmbedMeta;
|
package/lib/extractEmbedMeta.js
CHANGED
|
@@ -16,25 +16,25 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
16
|
|
|
17
17
|
const extractEmbedMeta = embed => {
|
|
18
18
|
const node = (0, _htmlReactParser.default)(embed);
|
|
19
|
-
if (typeof node ===
|
|
19
|
+
if (typeof node === "string" || Array.isArray(node) || node.type !== "ndlaembed" || !node.props["data-json"]) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
return JSON.parse(node.props[
|
|
22
|
+
return JSON.parse(node.props["data-json"]);
|
|
23
23
|
};
|
|
24
24
|
const extractEmbedMetas = embed => {
|
|
25
25
|
const nodes = (0, _htmlReactParser.default)(embed);
|
|
26
26
|
|
|
27
27
|
// There are no embeds in the string
|
|
28
|
-
if (typeof nodes ===
|
|
28
|
+
if (typeof nodes === "string") {
|
|
29
29
|
return [];
|
|
30
30
|
}
|
|
31
31
|
// There is only one embed in the string
|
|
32
|
-
else if (!Array.isArray(nodes) && nodes.type ===
|
|
33
|
-
return [JSON.parse(nodes.props[
|
|
32
|
+
else if (!Array.isArray(nodes) && nodes.type === "ndlaembed" && !!nodes.props["data-json"]) {
|
|
33
|
+
return [JSON.parse(nodes.props["data-json"])];
|
|
34
34
|
}
|
|
35
35
|
// There are multiple embeds in the string
|
|
36
|
-
else if (Array.isArray(nodes) && nodes.length && nodes.every(n => n.type ===
|
|
37
|
-
return nodes.map(n => JSON.parse(n.props[
|
|
36
|
+
else if (Array.isArray(nodes) && nodes.length && nodes.every(n => n.type === "ndlaembed" && !!n.props["data-json"])) {
|
|
37
|
+
return nodes.map(n => JSON.parse(n.props["data-json"]));
|
|
38
38
|
} else {
|
|
39
39
|
return [];
|
|
40
40
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export { default as transform } from
|
|
9
|
-
export { default as extractEmbedMeta, extractEmbedMetas } from
|
|
10
|
-
export type { TransformOptions, DynamicComponents } from
|
|
8
|
+
export { default as transform } from "./transform";
|
|
9
|
+
export { default as extractEmbedMeta, extractEmbedMetas } from "./extractEmbedMeta";
|
|
10
|
+
export type { TransformOptions, DynamicComponents } from "./plugins/types";
|
|
@@ -16,11 +16,11 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const asidePlugin = (node, opts) => {
|
|
19
|
-
if (node.attribs[
|
|
19
|
+
if (node.attribs["data-type"] === "factAside") {
|
|
20
20
|
return (0, _jsxRuntime.jsx)(_ui.FactBox, {
|
|
21
21
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
22
22
|
});
|
|
23
|
-
} else if (node.attribs[
|
|
23
|
+
} else if (node.attribs["data-type"] === "rightAside") {
|
|
24
24
|
return (0, _jsxRuntime.jsx)(_ui.Aside, {
|
|
25
25
|
wideScreen: true,
|
|
26
26
|
alwaysShow: true,
|
|
@@ -17,9 +17,9 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const copyParagraphPlugin = (node, converterOpts, opts) => {
|
|
19
19
|
const parent = node.parent;
|
|
20
|
-
if (parent?.name ===
|
|
20
|
+
if (parent?.name === "section" || parent?.name === "div" && Object.keys(parent.attribs ?? {}).length === 0) {
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.CopyParagraphButton, {
|
|
22
|
-
copyText: node.attribs[
|
|
22
|
+
copyText: node.attribs["data-text"],
|
|
23
23
|
lang: opts.articleLanguage,
|
|
24
24
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
|
25
25
|
});
|
package/lib/plugins/divPlugin.js
CHANGED
|
@@ -18,32 +18,32 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
const divPlugin = (node, opts) => {
|
|
21
|
-
if (node.attribs[
|
|
21
|
+
if (node.attribs["data-type"] === "framed-content" || node.attribs.class === "c-bodybox") {
|
|
22
22
|
return (0, _jsxRuntime.jsx)(_ui.FramedContent, {
|
|
23
23
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
if (node.attribs[
|
|
26
|
+
if (node.attribs["data-type"] === "related-content" && node.children.length) {
|
|
27
27
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
28
28
|
return (0, _jsxRuntime.jsx)(_ui.RelatedArticleList, {
|
|
29
29
|
...props,
|
|
30
30
|
headingLevel: "h3",
|
|
31
31
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
32
32
|
});
|
|
33
|
-
} else if (node.attribs[
|
|
34
|
-
const elements = node.childNodes.filter(c => c.type ===
|
|
35
|
-
const [pdfs, files] = (0, _partition.default)(elements, el => el.attribs[
|
|
33
|
+
} else if (node.attribs["data-type"] === "file" && node.childNodes.length) {
|
|
34
|
+
const elements = node.childNodes.filter(c => c.type === "tag" && c.name === "ndlaembed" && c.attribs["data-resource"] === "file");
|
|
35
|
+
const [pdfs, files] = (0, _partition.default)(elements, el => el.attribs["data-type"] === "pdf" && el.attribs["data-display"] === "block");
|
|
36
36
|
return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
37
37
|
children: [files.length ? (0, _jsxRuntime.jsx)(_ui.FileList, {
|
|
38
38
|
children: (0, _htmlReactParser.domToReact)(files, opts)
|
|
39
39
|
}) : undefined, (0, _htmlReactParser.domToReact)(pdfs, opts)]
|
|
40
40
|
});
|
|
41
|
-
} else if (node.attribs[
|
|
41
|
+
} else if (node.attribs["data-type"] === "grid" && node.children.length > 0) {
|
|
42
42
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
43
|
-
const columns = props[
|
|
44
|
-
const border = props[
|
|
45
|
-
const background = props[
|
|
46
|
-
const frontpage = !!props[
|
|
43
|
+
const columns = props["data-columns"];
|
|
44
|
+
const border = props["data-border"];
|
|
45
|
+
const background = props["data-background"];
|
|
46
|
+
const frontpage = !!props["data-size"];
|
|
47
47
|
return (0, _jsxRuntime.jsx)(_ui.Grid, {
|
|
48
48
|
isFrontpage: frontpage,
|
|
49
49
|
border: border,
|
|
@@ -52,7 +52,7 @@ const divPlugin = (node, opts) => {
|
|
|
52
52
|
...props,
|
|
53
53
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
54
54
|
});
|
|
55
|
-
} else if (node.attribs[
|
|
55
|
+
} else if (node.attribs["data-parallax-cell"] === "true" && node.children.length) {
|
|
56
56
|
return (0, _jsxRuntime.jsx)(_ui.GridParallaxItem, {
|
|
57
57
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
58
58
|
});
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const keyFigureEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
const {
|
|
22
22
|
title,
|
|
23
23
|
subtitle,
|
|
@@ -26,9 +26,9 @@ const keyFigureEmbedPlugin = (element, _, opts) => {
|
|
|
26
26
|
return (0, _jsxRuntime.jsx)(_ui.KeyFigure, {
|
|
27
27
|
title: title,
|
|
28
28
|
subtitle: subtitle,
|
|
29
|
-
image: data.status ===
|
|
29
|
+
image: data.status === "success" && data.data.metaImage ? {
|
|
30
30
|
src: data.data.metaImage.image.imageUrl,
|
|
31
|
-
alt: alt === undefined ?
|
|
31
|
+
alt: alt === undefined ? "" : alt
|
|
32
32
|
} : undefined,
|
|
33
33
|
lang: opts.articleLanguage
|
|
34
34
|
});
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const audioEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.AudioEmbed, {
|
|
22
22
|
embed: data,
|
|
23
23
|
heartButton: opts.components?.heartButton,
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { PluginType } from
|
|
8
|
+
import { PluginType } from "../types";
|
|
9
9
|
export declare const errorSvgSrc = "data:image/svg+xml;charset=UTF-8,%3Csvg fill='%238A8888' height='400' viewBox='0 0 24 12' width='100%25' xmlns='http://www.w3.org/2000/svg' style='background-color: %23EFF0F2'%3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath transform='scale(0.3) translate(28, 8.5)' d='M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z'/%3E%3C/svg%3E";
|
|
10
10
|
export declare const blogPostEmbedPlugin: PluginType;
|
|
@@ -18,7 +18,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
18
18
|
const errorSvgSrc = exports.errorSvgSrc = `data:image/svg+xml;charset=UTF-8,%3Csvg fill='%238A8888' height='400' viewBox='0 0 24 12' width='100%25' xmlns='http://www.w3.org/2000/svg' style='background-color: %23EFF0F2'%3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath transform='scale(0.3) translate(28, 8.5)' d='M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z'/%3E%3C/svg%3E`;
|
|
19
19
|
const blogPostEmbedPlugin = (element, _, opts) => {
|
|
20
20
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
21
|
-
const data = JSON.parse(props[
|
|
21
|
+
const data = JSON.parse(props["data-json"]);
|
|
22
22
|
const {
|
|
23
23
|
title,
|
|
24
24
|
author,
|
|
@@ -37,8 +37,8 @@ const blogPostEmbedPlugin = (element, _, opts) => {
|
|
|
37
37
|
size: size,
|
|
38
38
|
path: opts.path,
|
|
39
39
|
metaImage: {
|
|
40
|
-
alt: alt ? alt :
|
|
41
|
-
url: data.status ===
|
|
40
|
+
alt: alt ? alt : "",
|
|
41
|
+
url: data.status === "success" ? data.data.metaImage?.image.imageUrl ?? errorSvgSrc : errorSvgSrc
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
};
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const brightcoveEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.BrightcoveEmbed, {
|
|
22
22
|
embed: data,
|
|
23
23
|
heartButton: opts.components?.heartButton,
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const campaignBlockPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
const embed = data.embedData;
|
|
22
22
|
return (0, _jsxRuntime.jsx)(_ui.CampaignBlock, {
|
|
23
23
|
title: {
|
|
@@ -34,9 +34,9 @@ const campaignBlockPlugin = (element, _, opts) => {
|
|
|
34
34
|
},
|
|
35
35
|
path: opts.path,
|
|
36
36
|
imageSide: embed.imageSide,
|
|
37
|
-
image: data.status ===
|
|
37
|
+
image: data.status === "success" && data.data.image ? {
|
|
38
38
|
src: data.data.image.image.imageUrl,
|
|
39
|
-
alt: embed.alt === undefined ?
|
|
39
|
+
alt: embed.alt === undefined ? "" : embed.alt
|
|
40
40
|
} : undefined
|
|
41
41
|
});
|
|
42
42
|
};
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const codeEmbedPlugin = element => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_code.CodeEmbed, {
|
|
22
22
|
embed: data
|
|
23
23
|
});
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const conceptEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.ConceptEmbed, {
|
|
22
22
|
embed: data,
|
|
23
23
|
fullWidth: true,
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const conceptListEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.ConceptListEmbed, {
|
|
22
22
|
embed: data,
|
|
23
23
|
lang: opts.articleLanguage
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const embedData = JSON.parse(props[
|
|
20
|
+
const embedData = JSON.parse(props["data-json"]);
|
|
21
21
|
const {
|
|
22
22
|
name,
|
|
23
23
|
email,
|
|
@@ -28,7 +28,7 @@ const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
|
28
28
|
alt
|
|
29
29
|
} = embedData.embedData;
|
|
30
30
|
return (0, _jsxRuntime.jsx)(_ui.ContactBlock, {
|
|
31
|
-
image: embedData.status ===
|
|
31
|
+
image: embedData.status === "success" ? embedData.data.image : undefined,
|
|
32
32
|
embedAlt: alt,
|
|
33
33
|
description: description,
|
|
34
34
|
email: email,
|