@ndla/article-converter 6.5.2 → 6.5.4
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/plugins/copyParagraphPlugin.js +2 -1
- package/es/plugins/divPlugin.js +6 -5
- package/es/plugins/embed/audioEmbedPlugin.js +2 -1
- package/es/plugins/embed/blogPostEmbedPlugin.js +3 -2
- package/es/plugins/embed/brightcoveEmbedPlugin.js +2 -1
- package/es/plugins/embed/codeEmbedPlugin.js +1 -1
- package/es/plugins/embed/conceptEmbedPlugin.js +2 -1
- package/es/plugins/embed/contactBlockEmbedPlugin.js +2 -1
- package/es/plugins/embed/contentLinkEmbedPlugin.js +4 -3
- package/es/plugins/embed/imageEmbedPlugin.js +4 -3
- package/es/plugins/olPlugin.js +3 -2
- package/es/plugins/paragraphPlugin.js +2 -1
- package/es/plugins/spanPlugin.js +2 -1
- package/es/plugins/ulPlugin.js +2 -1
- package/es/transform.js +1 -1
- package/lib/index.js +1 -1
- package/lib/plugins/copyParagraphPlugin.js +2 -1
- package/lib/plugins/divPlugin.js +5 -3
- package/lib/plugins/embed/audioEmbedPlugin.js +2 -1
- package/lib/plugins/embed/blogPostEmbedPlugin.js +3 -2
- package/lib/plugins/embed/brightcoveEmbedPlugin.js +2 -1
- package/lib/plugins/embed/codeEmbedPlugin.js +2 -2
- package/lib/plugins/embed/conceptEmbedPlugin.js +2 -1
- package/lib/plugins/embed/contactBlockEmbedPlugin.js +2 -1
- package/lib/plugins/embed/contentLinkEmbedPlugin.js +3 -2
- package/lib/plugins/embed/imageEmbedPlugin.js +4 -3
- package/lib/plugins/olPlugin.js +3 -2
- package/lib/plugins/paragraphPlugin.js +2 -1
- package/lib/plugins/spanPlugin.js +2 -1
- package/lib/plugins/ulPlugin.js +2 -1
- package/lib/transform.js +1 -1
- package/package.json +6 -7
- package/src/plugins/divPlugin.tsx +7 -4
- package/src/plugins/embed/codeEmbedPlugin.tsx +1 -1
- package/src/plugins/embed/contentLinkEmbedPlugin.tsx +7 -3
|
@@ -10,8 +10,9 @@ import { domToReact } from "html-react-parser";
|
|
|
10
10
|
import { CopyParagraphButton } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const copyParagraphPlugin = (node, converterOpts, opts) => {
|
|
13
|
+
var _parent$attribs;
|
|
13
14
|
const parent = node.parent;
|
|
14
|
-
if (parent
|
|
15
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.name) === "section" || (parent === null || parent === void 0 ? void 0 : parent.name) === "div" && Object.keys((_parent$attribs = parent.attribs) !== null && _parent$attribs !== void 0 ? _parent$attribs : {}).length === 0) {
|
|
15
16
|
return _jsx(CopyParagraphButton, {
|
|
16
17
|
copyText: node.attribs["data-text"],
|
|
17
18
|
lang: opts.articleLanguage,
|
package/es/plugins/divPlugin.js
CHANGED
|
@@ -7,11 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { domToReact, attributesToProps } from "html-react-parser";
|
|
10
|
-
import partition from "lodash/partition";
|
|
11
10
|
import { FileList, RelatedArticleList, Grid, GridParallaxItem, FramedContent } from "@ndla/ui";
|
|
12
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
13
|
-
import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
14
|
-
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
11
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
15
12
|
export const divPlugin = (node, opts) => {
|
|
16
13
|
if (node.attribs["data-type"] === "framed-content" || node.attribs.class === "c-bodybox") {
|
|
17
14
|
return _jsx(FramedContent, {
|
|
@@ -26,7 +23,11 @@ export const divPlugin = (node, opts) => {
|
|
|
26
23
|
});
|
|
27
24
|
} else if (node.attribs["data-type"] === "file" && node.childNodes.length) {
|
|
28
25
|
const elements = node.childNodes.filter(c => c.type === "tag" && c.name === "ndlaembed" && c.attribs["data-resource"] === "file");
|
|
29
|
-
const [pdfs, files] =
|
|
26
|
+
const [pdfs, files] = elements.reduce((acc, el) => {
|
|
27
|
+
const arr = el.attribs["data-type"] === "pdf" && el.attribs["data-display"] === "block" ? acc[0] : acc[1];
|
|
28
|
+
arr.push(el);
|
|
29
|
+
return acc;
|
|
30
|
+
}, [[], []]);
|
|
30
31
|
return _jsxs(_Fragment, {
|
|
31
32
|
children: [files.length ? _jsx(FileList, {
|
|
32
33
|
children: domToReact(files, opts)
|
|
@@ -10,11 +10,12 @@ import { attributesToProps } from "html-react-parser";
|
|
|
10
10
|
import { AudioEmbed } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const audioEmbedPlugin = (element, _, opts) => {
|
|
13
|
+
var _opts$components;
|
|
13
14
|
const props = attributesToProps(element.attribs);
|
|
14
15
|
const data = JSON.parse(props["data-json"]);
|
|
15
16
|
return _jsx(AudioEmbed, {
|
|
16
17
|
embed: data,
|
|
17
|
-
heartButton: opts.components
|
|
18
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
18
19
|
lang: opts.articleLanguage
|
|
19
20
|
});
|
|
20
21
|
};
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
import { attributesToProps } from "html-react-parser";
|
|
10
10
|
import { BlogPostV2 } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
-
export const errorSvgSrc =
|
|
12
|
+
export 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";
|
|
13
13
|
export const blogPostEmbedPlugin = (element, _, opts) => {
|
|
14
|
+
var _data$data$metaImage$, _data$data$metaImage;
|
|
14
15
|
const props = attributesToProps(element.attribs);
|
|
15
16
|
const data = JSON.parse(props["data-json"]);
|
|
16
17
|
const {
|
|
@@ -28,7 +29,7 @@ export const blogPostEmbedPlugin = (element, _, opts) => {
|
|
|
28
29
|
path: opts.path,
|
|
29
30
|
metaImage: {
|
|
30
31
|
alt: alt ? alt : "",
|
|
31
|
-
url: data.status === "success" ? data.data.metaImage
|
|
32
|
+
url: data.status === "success" ? (_data$data$metaImage$ = (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.image.imageUrl) !== null && _data$data$metaImage$ !== void 0 ? _data$data$metaImage$ : errorSvgSrc : errorSvgSrc
|
|
32
33
|
}
|
|
33
34
|
});
|
|
34
35
|
};
|
|
@@ -10,11 +10,12 @@ import { attributesToProps } from "html-react-parser";
|
|
|
10
10
|
import { BrightcoveEmbed } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const brightcoveEmbedPlugin = (element, _, opts) => {
|
|
13
|
+
var _opts$components;
|
|
13
14
|
const props = attributesToProps(element.attribs);
|
|
14
15
|
const data = JSON.parse(props["data-json"]);
|
|
15
16
|
return _jsx(BrightcoveEmbed, {
|
|
16
17
|
embed: data,
|
|
17
|
-
heartButton: opts.components
|
|
18
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
18
19
|
renderContext: opts.renderContext
|
|
19
20
|
});
|
|
20
21
|
};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps } from "html-react-parser";
|
|
10
|
-
import { CodeEmbed } from "@ndla/
|
|
10
|
+
import { CodeEmbed } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const codeEmbedPlugin = element => {
|
|
13
13
|
const props = attributesToProps(element.attribs);
|
|
@@ -10,12 +10,13 @@ import { attributesToProps } from "html-react-parser";
|
|
|
10
10
|
import { ConceptEmbed } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const conceptEmbedPlugin = (element, _, opts) => {
|
|
13
|
+
var _opts$components;
|
|
13
14
|
const props = attributesToProps(element.attribs);
|
|
14
15
|
const data = JSON.parse(props["data-json"]);
|
|
15
16
|
return _jsx(ConceptEmbed, {
|
|
16
17
|
embed: data,
|
|
17
18
|
fullWidth: true,
|
|
18
|
-
heartButton: opts.components
|
|
19
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
19
20
|
lang: opts.articleLanguage,
|
|
20
21
|
renderContext: opts.renderContext
|
|
21
22
|
});
|
|
@@ -10,6 +10,7 @@ import { attributesToProps } from "html-react-parser";
|
|
|
10
10
|
import { ContactBlock } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
13
|
+
var _opts$canonicalUrls;
|
|
13
14
|
const props = attributesToProps(element.attribs);
|
|
14
15
|
const embedData = JSON.parse(props["data-json"]);
|
|
15
16
|
const {
|
|
@@ -31,6 +32,6 @@ export const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
|
31
32
|
name: name,
|
|
32
33
|
blob: blob,
|
|
33
34
|
lang: opts.articleLanguage,
|
|
34
|
-
imageCanonicalUrl: opts.canonicalUrls
|
|
35
|
+
imageCanonicalUrl: (_opts$canonicalUrls = opts.canonicalUrls) === null || _opts$canonicalUrls === void 0 ? void 0 : _opts$canonicalUrls.image
|
|
35
36
|
});
|
|
36
37
|
};
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps } from "html-react-parser";
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
10
|
import { ContentLinkEmbed } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
-
export const contentLinkEmbedPlugin = (element,
|
|
12
|
+
export const contentLinkEmbedPlugin = (element, opts, _ref) => {
|
|
13
13
|
let {
|
|
14
14
|
isOembed
|
|
15
15
|
} = _ref;
|
|
@@ -17,6 +17,7 @@ export const contentLinkEmbedPlugin = (element, _, _ref) => {
|
|
|
17
17
|
const data = JSON.parse(props["data-json"]);
|
|
18
18
|
return _jsx(ContentLinkEmbed, {
|
|
19
19
|
embed: data,
|
|
20
|
-
isOembed: isOembed
|
|
20
|
+
isOembed: isOembed,
|
|
21
|
+
children: domToReact(element.children, opts)
|
|
21
22
|
});
|
|
22
23
|
};
|
|
@@ -10,16 +10,17 @@ import { attributesToProps } from "html-react-parser";
|
|
|
10
10
|
import { ImageEmbed } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const imageEmbedPlugin = (element, _, opts) => {
|
|
13
|
+
var _element$parentNode, _opts$components, _opts$canonicalUrls;
|
|
13
14
|
const props = attributesToProps(element.attribs);
|
|
14
15
|
const data = JSON.parse(props["data-json"]);
|
|
15
|
-
const inGrid = element.parentNode
|
|
16
|
+
const inGrid = ((_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.attribs) === null || _element$parentNode === void 0 ? void 0 : _element$parentNode["data-type"]) === "grid";
|
|
16
17
|
return _jsx(ImageEmbed, {
|
|
17
18
|
inGrid: inGrid,
|
|
18
19
|
embed: data,
|
|
19
20
|
path: opts.path,
|
|
20
21
|
previewAlt: opts.previewAlt,
|
|
21
|
-
heartButton: opts.components
|
|
22
|
-
canonicalUrl: opts.canonicalUrls
|
|
22
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
23
|
+
canonicalUrl: (_opts$canonicalUrls = opts.canonicalUrls) === null || _opts$canonicalUrls === void 0 ? void 0 : _opts$canonicalUrls.image,
|
|
23
24
|
lang: opts.articleLanguage,
|
|
24
25
|
renderContext: opts.renderContext
|
|
25
26
|
});
|
package/es/plugins/olPlugin.js
CHANGED
|
@@ -10,11 +10,12 @@ import { attributesToProps, domToReact } from "html-react-parser";
|
|
|
10
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
|
+
var _node$attribs$class;
|
|
13
14
|
const props = attributesToProps(node.attribs);
|
|
14
15
|
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
15
16
|
const num = node.attribs["start"];
|
|
16
|
-
const numClass = num ?
|
|
17
|
-
const classes = [node.attribs.class
|
|
17
|
+
const numClass = num ? "ol-reset-".concat(num) : false;
|
|
18
|
+
const classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : false, letterClass, numClass].filter(c => !!c).join(" ");
|
|
18
19
|
return _jsx(OrderedList, {
|
|
19
20
|
...props,
|
|
20
21
|
className: classes.length ? classes : undefined,
|
|
@@ -11,7 +11,8 @@ 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
13
|
if (node.attribs["data-align"] === "center") {
|
|
14
|
-
|
|
14
|
+
var _node$attribs$class;
|
|
15
|
+
const classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : "", "u-text-center"].filter(c => !!c).join(" ");
|
|
15
16
|
return _jsx("p", {
|
|
16
17
|
...props,
|
|
17
18
|
lang: opts.articleLanguage,
|
package/es/plugins/spanPlugin.js
CHANGED
|
@@ -10,11 +10,12 @@ 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
12
|
if (node.attribs["data-size"] === "large") {
|
|
13
|
+
var _node$attribs$class;
|
|
13
14
|
const props = attributesToProps(node.attribs);
|
|
14
15
|
return _jsx("span", {
|
|
15
16
|
...props,
|
|
16
17
|
"data-size": undefined,
|
|
17
|
-
className:
|
|
18
|
+
className: "".concat((_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : "", " u-large-body-text"),
|
|
18
19
|
children: domToReact(node.children, opts)
|
|
19
20
|
});
|
|
20
21
|
}
|
package/es/plugins/ulPlugin.js
CHANGED
|
@@ -10,8 +10,9 @@ import { attributesToProps, domToReact } from "html-react-parser";
|
|
|
10
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
|
+
var _node$attribs$class;
|
|
13
14
|
const props = attributesToProps(node.attribs);
|
|
14
|
-
const classes = [node.attribs.class
|
|
15
|
+
const classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : "", node.attribs["data-type"] === "two-column" ? "o-list--two-columns" : ""].filter(c => !!c).join(" ");
|
|
15
16
|
return _jsx(UnOrderedList, {
|
|
16
17
|
...props,
|
|
17
18
|
className: classes,
|
package/es/transform.js
CHANGED
|
@@ -12,7 +12,7 @@ import { basePlugins, oembedPlugins } from "./plugins";
|
|
|
12
12
|
import { embedPlugins } from "./plugins/embed";
|
|
13
13
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
14
14
|
const transform = (content, opts) => {
|
|
15
|
-
const plugins = opts
|
|
15
|
+
const plugins = opts !== null && opts !== void 0 && opts.isOembed ? oembedPlugins : basePlugins;
|
|
16
16
|
const options = {
|
|
17
17
|
replace: node => {
|
|
18
18
|
if (!("attribs" in node)) {
|
package/lib/index.js
CHANGED
|
@@ -24,5 +24,5 @@ Object.defineProperty(exports, "transform", {
|
|
|
24
24
|
var _transform = _interopRequireDefault(require("./transform"));
|
|
25
25
|
var _extractEmbedMeta = _interopRequireWildcard(require("./extractEmbedMeta"));
|
|
26
26
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
27
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
27
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
28
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -16,8 +16,9 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const copyParagraphPlugin = (node, converterOpts, opts) => {
|
|
19
|
+
var _parent$attribs;
|
|
19
20
|
const parent = node.parent;
|
|
20
|
-
if (parent
|
|
21
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.name) === "section" || (parent === null || parent === void 0 ? void 0 : parent.name) === "div" && Object.keys((_parent$attribs = parent.attribs) !== null && _parent$attribs !== void 0 ? _parent$attribs : {}).length === 0) {
|
|
21
22
|
return (0, _jsxRuntime.jsx)(_ui.CopyParagraphButton, {
|
|
22
23
|
copyText: node.attribs["data-text"],
|
|
23
24
|
lang: opts.articleLanguage,
|
package/lib/plugins/divPlugin.js
CHANGED
|
@@ -5,10 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.divPlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
-
var _partition = _interopRequireDefault(require("lodash/partition"));
|
|
9
8
|
var _ui = require("@ndla/ui");
|
|
10
9
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
10
|
/**
|
|
13
11
|
* Copyright (c) 2023-present, NDLA.
|
|
14
12
|
*
|
|
@@ -31,7 +29,11 @@ const divPlugin = (node, opts) => {
|
|
|
31
29
|
});
|
|
32
30
|
} else if (node.attribs["data-type"] === "file" && node.childNodes.length) {
|
|
33
31
|
const elements = node.childNodes.filter(c => c.type === "tag" && c.name === "ndlaembed" && c.attribs["data-resource"] === "file");
|
|
34
|
-
const [pdfs, files] =
|
|
32
|
+
const [pdfs, files] = elements.reduce((acc, el) => {
|
|
33
|
+
const arr = el.attribs["data-type"] === "pdf" && el.attribs["data-display"] === "block" ? acc[0] : acc[1];
|
|
34
|
+
arr.push(el);
|
|
35
|
+
return acc;
|
|
36
|
+
}, [[], []]);
|
|
35
37
|
return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
36
38
|
children: [files.length ? (0, _jsxRuntime.jsx)(_ui.FileList, {
|
|
37
39
|
children: (0, _htmlReactParser.domToReact)(files, opts)
|
|
@@ -16,11 +16,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const audioEmbedPlugin = (element, _, opts) => {
|
|
19
|
+
var _opts$components;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
21
|
const data = JSON.parse(props["data-json"]);
|
|
21
22
|
return (0, _jsxRuntime.jsx)(_ui.AudioEmbed, {
|
|
22
23
|
embed: data,
|
|
23
|
-
heartButton: opts.components
|
|
24
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
24
25
|
lang: opts.articleLanguage
|
|
25
26
|
});
|
|
26
27
|
};
|
|
@@ -15,8 +15,9 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const errorSvgSrc = exports.errorSvgSrc =
|
|
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
|
+
var _data$data$metaImage$, _data$data$metaImage;
|
|
20
21
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
21
22
|
const data = JSON.parse(props["data-json"]);
|
|
22
23
|
const {
|
|
@@ -34,7 +35,7 @@ const blogPostEmbedPlugin = (element, _, opts) => {
|
|
|
34
35
|
path: opts.path,
|
|
35
36
|
metaImage: {
|
|
36
37
|
alt: alt ? alt : "",
|
|
37
|
-
url: data.status === "success" ? data.data.metaImage
|
|
38
|
+
url: data.status === "success" ? (_data$data$metaImage$ = (_data$data$metaImage = data.data.metaImage) === null || _data$data$metaImage === void 0 ? void 0 : _data$data$metaImage.image.imageUrl) !== null && _data$data$metaImage$ !== void 0 ? _data$data$metaImage$ : errorSvgSrc : errorSvgSrc
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
41
|
};
|
|
@@ -16,11 +16,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const brightcoveEmbedPlugin = (element, _, opts) => {
|
|
19
|
+
var _opts$components;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
21
|
const data = JSON.parse(props["data-json"]);
|
|
21
22
|
return (0, _jsxRuntime.jsx)(_ui.BrightcoveEmbed, {
|
|
22
23
|
embed: data,
|
|
23
|
-
heartButton: opts.components
|
|
24
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
24
25
|
renderContext: opts.renderContext
|
|
25
26
|
});
|
|
26
27
|
};
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.codeEmbedPlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
-
var
|
|
8
|
+
var _ui = require("@ndla/ui");
|
|
9
9
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
10
|
/**
|
|
11
11
|
* Copyright (c) 2023-present, NDLA.
|
|
@@ -18,7 +18,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
18
18
|
const codeEmbedPlugin = element => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
20
|
const data = JSON.parse(props["data-json"]);
|
|
21
|
-
return (0, _jsxRuntime.jsx)(
|
|
21
|
+
return (0, _jsxRuntime.jsx)(_ui.CodeEmbed, {
|
|
22
22
|
embed: data
|
|
23
23
|
});
|
|
24
24
|
};
|
|
@@ -16,12 +16,13 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const conceptEmbedPlugin = (element, _, opts) => {
|
|
19
|
+
var _opts$components;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
21
|
const data = JSON.parse(props["data-json"]);
|
|
21
22
|
return (0, _jsxRuntime.jsx)(_ui.ConceptEmbed, {
|
|
22
23
|
embed: data,
|
|
23
24
|
fullWidth: true,
|
|
24
|
-
heartButton: opts.components
|
|
25
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
25
26
|
lang: opts.articleLanguage,
|
|
26
27
|
renderContext: opts.renderContext
|
|
27
28
|
});
|
|
@@ -16,6 +16,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
19
|
+
var _opts$canonicalUrls;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
21
|
const embedData = JSON.parse(props["data-json"]);
|
|
21
22
|
const {
|
|
@@ -37,7 +38,7 @@ const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
|
37
38
|
name: name,
|
|
38
39
|
blob: blob,
|
|
39
40
|
lang: opts.articleLanguage,
|
|
40
|
-
imageCanonicalUrl: opts.canonicalUrls
|
|
41
|
+
imageCanonicalUrl: (_opts$canonicalUrls = opts.canonicalUrls) === null || _opts$canonicalUrls === void 0 ? void 0 : _opts$canonicalUrls.image
|
|
41
42
|
});
|
|
42
43
|
};
|
|
43
44
|
exports.contactBlockEmbedPlugin = contactBlockEmbedPlugin;
|
|
@@ -15,7 +15,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const contentLinkEmbedPlugin = (element,
|
|
18
|
+
const contentLinkEmbedPlugin = (element, opts, _ref) => {
|
|
19
19
|
let {
|
|
20
20
|
isOembed
|
|
21
21
|
} = _ref;
|
|
@@ -23,7 +23,8 @@ const contentLinkEmbedPlugin = (element, _, _ref) => {
|
|
|
23
23
|
const data = JSON.parse(props["data-json"]);
|
|
24
24
|
return (0, _jsxRuntime.jsx)(_ui.ContentLinkEmbed, {
|
|
25
25
|
embed: data,
|
|
26
|
-
isOembed: isOembed
|
|
26
|
+
isOembed: isOembed,
|
|
27
|
+
children: (0, _htmlReactParser.domToReact)(element.children, opts)
|
|
27
28
|
});
|
|
28
29
|
};
|
|
29
30
|
exports.contentLinkEmbedPlugin = contentLinkEmbedPlugin;
|
|
@@ -16,16 +16,17 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const imageEmbedPlugin = (element, _, opts) => {
|
|
19
|
+
var _element$parentNode, _opts$components, _opts$canonicalUrls;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
21
|
const data = JSON.parse(props["data-json"]);
|
|
21
|
-
const inGrid = element.parentNode
|
|
22
|
+
const inGrid = ((_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.attribs) === null || _element$parentNode === void 0 ? void 0 : _element$parentNode["data-type"]) === "grid";
|
|
22
23
|
return (0, _jsxRuntime.jsx)(_ui.ImageEmbed, {
|
|
23
24
|
inGrid: inGrid,
|
|
24
25
|
embed: data,
|
|
25
26
|
path: opts.path,
|
|
26
27
|
previewAlt: opts.previewAlt,
|
|
27
|
-
heartButton: opts.components
|
|
28
|
-
canonicalUrl: opts.canonicalUrls
|
|
28
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
29
|
+
canonicalUrl: (_opts$canonicalUrls = opts.canonicalUrls) === null || _opts$canonicalUrls === void 0 ? void 0 : _opts$canonicalUrls.image,
|
|
29
30
|
lang: opts.articleLanguage,
|
|
30
31
|
renderContext: opts.renderContext
|
|
31
32
|
});
|
package/lib/plugins/olPlugin.js
CHANGED
|
@@ -16,11 +16,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const olPlugin = (node, converterOpts, opts) => {
|
|
19
|
+
var _node$attribs$class;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
21
|
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
21
22
|
const num = node.attribs["start"];
|
|
22
|
-
const numClass = num ?
|
|
23
|
-
const classes = [node.attribs.class
|
|
23
|
+
const numClass = num ? "ol-reset-".concat(num) : false;
|
|
24
|
+
const classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : false, letterClass, numClass].filter(c => !!c).join(" ");
|
|
24
25
|
return (0, _jsxRuntime.jsx)(_ui.OrderedList, {
|
|
25
26
|
...props,
|
|
26
27
|
className: classes.length ? classes : undefined,
|
|
@@ -17,7 +17,8 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
const paragraphPlugin = (node, converterOpts, opts) => {
|
|
18
18
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
19
19
|
if (node.attribs["data-align"] === "center") {
|
|
20
|
-
|
|
20
|
+
var _node$attribs$class;
|
|
21
|
+
const classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : "", "u-text-center"].filter(c => !!c).join(" ");
|
|
21
22
|
return (0, _jsxRuntime.jsx)("p", {
|
|
22
23
|
...props,
|
|
23
24
|
lang: opts.articleLanguage,
|
|
@@ -16,11 +16,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
|
|
17
17
|
const spanPlugin = (node, opts) => {
|
|
18
18
|
if (node.attribs["data-size"] === "large") {
|
|
19
|
+
var _node$attribs$class;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
21
|
return (0, _jsxRuntime.jsx)("span", {
|
|
21
22
|
...props,
|
|
22
23
|
"data-size": undefined,
|
|
23
|
-
className:
|
|
24
|
+
className: "".concat((_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : "", " u-large-body-text"),
|
|
24
25
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
25
26
|
});
|
|
26
27
|
}
|
package/lib/plugins/ulPlugin.js
CHANGED
|
@@ -16,8 +16,9 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const ulPlugin = (node, converterOpts, opts) => {
|
|
19
|
+
var _node$attribs$class;
|
|
19
20
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
-
const classes = [node.attribs.class
|
|
21
|
+
const classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : "", node.attribs["data-type"] === "two-column" ? "o-list--two-columns" : ""].filter(c => !!c).join(" ");
|
|
21
22
|
return (0, _jsxRuntime.jsx)(_ui.UnOrderedList, {
|
|
22
23
|
...props,
|
|
23
24
|
className: classes,
|
package/lib/transform.js
CHANGED
|
@@ -19,7 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
const transform = (content, opts) => {
|
|
22
|
-
const plugins = opts
|
|
22
|
+
const plugins = opts !== null && opts !== void 0 && opts.isOembed ? _plugins.oembedPlugins : _plugins.basePlugins;
|
|
23
23
|
const options = {
|
|
24
24
|
replace: node => {
|
|
25
25
|
if (!("attribs" in node)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.4",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -28,13 +28,12 @@
|
|
|
28
28
|
],
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@ndla/types-backend": "^0.2.64",
|
|
31
|
-
"@ndla/types-embed": "^4.1.
|
|
31
|
+
"@ndla/types-embed": "^4.1.5"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ndla/code": "^5.0.
|
|
35
|
-
"@ndla/ui": "^50.
|
|
36
|
-
"html-react-parser": "^5.1.8"
|
|
37
|
-
"lodash": "^4.17.20"
|
|
34
|
+
"@ndla/code": "^5.0.56",
|
|
35
|
+
"@ndla/ui": "^50.15.0",
|
|
36
|
+
"html-react-parser": "^5.1.8"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|
|
40
39
|
"@emotion/react": "^11.10.4",
|
|
@@ -48,5 +47,5 @@
|
|
|
48
47
|
"publishConfig": {
|
|
49
48
|
"access": "public"
|
|
50
49
|
},
|
|
51
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "f6949c46c9b1b0876c2d5e5d5ec4f1b31db1c28b"
|
|
52
51
|
}
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { domToReact, attributesToProps, Element, DOMNode } from "html-react-parser";
|
|
10
|
-
import partition from "lodash/partition";
|
|
11
10
|
import { FileList, RelatedArticleList, Grid, GridType, GridParallaxItem, FramedContent } from "@ndla/ui";
|
|
12
11
|
import { PluginType } from "./types";
|
|
13
12
|
|
|
@@ -28,9 +27,13 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
28
27
|
const elements = node.childNodes.filter(
|
|
29
28
|
(c): c is Element => c.type === "tag" && c.name === "ndlaembed" && c.attribs["data-resource"] === "file",
|
|
30
29
|
);
|
|
31
|
-
const [pdfs, files] =
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const [pdfs, files] = elements.reduce<[Element[], Element[]]>(
|
|
31
|
+
(acc, el) => {
|
|
32
|
+
const arr = el.attribs["data-type"] === "pdf" && el.attribs["data-display"] === "block" ? acc[0] : acc[1];
|
|
33
|
+
arr.push(el);
|
|
34
|
+
return acc;
|
|
35
|
+
},
|
|
36
|
+
[[], []],
|
|
34
37
|
);
|
|
35
38
|
|
|
36
39
|
return (
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps } from "html-react-parser";
|
|
10
|
-
import { CodeEmbed } from "@ndla/code";
|
|
11
10
|
import { CodeMetaData } from "@ndla/types-embed";
|
|
11
|
+
import { CodeEmbed } from "@ndla/ui";
|
|
12
12
|
import { PluginType } from "../types";
|
|
13
13
|
|
|
14
14
|
export const codeEmbedPlugin: PluginType = (element) => {
|
|
@@ -6,13 +6,17 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps } from "html-react-parser";
|
|
9
|
+
import { DOMNode, attributesToProps, domToReact } from "html-react-parser";
|
|
10
10
|
import { ContentLinkMetaData } from "@ndla/types-embed";
|
|
11
11
|
import { ContentLinkEmbed } from "@ndla/ui";
|
|
12
12
|
import { PluginType } from "../types";
|
|
13
13
|
|
|
14
|
-
export const contentLinkEmbedPlugin: PluginType = (element,
|
|
14
|
+
export const contentLinkEmbedPlugin: PluginType = (element, opts, { isOembed }) => {
|
|
15
15
|
const props = attributesToProps(element.attribs);
|
|
16
16
|
const data = JSON.parse(props["data-json"] as string) as ContentLinkMetaData;
|
|
17
|
-
return
|
|
17
|
+
return (
|
|
18
|
+
<ContentLinkEmbed embed={data} isOembed={isOembed}>
|
|
19
|
+
{domToReact(element.children as DOMNode[], opts)}
|
|
20
|
+
</ContentLinkEmbed>
|
|
21
|
+
);
|
|
18
22
|
};
|