@ndla/article-converter 6.5.7 → 7.0.0
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/asidePlugin.js +1 -7
- package/es/plugins/copyParagraphPlugin.js +1 -1
- package/es/plugins/divPlugin.js +6 -3
- package/es/plugins/embed/fileEmbedPlugin.js +6 -7
- package/es/plugins/h3Plugin.js +0 -1
- package/es/plugins/olPlugin.js +1 -1
- package/es/plugins/paragraphPlugin.js +2 -12
- package/es/plugins/ulPlugin.js +1 -3
- package/es/transform.js +4 -5
- package/lib/plugins/asidePlugin.js +0 -6
- package/lib/plugins/copyParagraphPlugin.js +1 -1
- package/lib/plugins/divPlugin.js +6 -3
- package/lib/plugins/embed/fileEmbedPlugin.js +6 -7
- package/lib/plugins/h3Plugin.js +0 -1
- package/lib/plugins/olPlugin.js +1 -1
- package/lib/plugins/paragraphPlugin.js +2 -12
- package/lib/plugins/ulPlugin.js +1 -3
- package/lib/transform.js +4 -5
- package/package.json +5 -6
- package/src/plugins/asidePlugin.tsx +1 -8
- package/src/plugins/copyParagraphPlugin.tsx +5 -1
- package/src/plugins/divPlugin.tsx +6 -3
- package/src/plugins/embed/fileEmbedPlugin.tsx +3 -9
- package/src/plugins/h3Plugin.tsx +1 -1
- package/src/plugins/olPlugin.tsx +1 -1
- package/src/plugins/paragraphPlugin.tsx +4 -10
- package/src/plugins/ulPlugin.tsx +1 -4
- package/src/transform.tsx +2 -3
|
@@ -7,19 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { domToReact } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { FactBox } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const asidePlugin = (node, opts) => {
|
|
13
13
|
if (node.attribs["data-type"] === "factAside") {
|
|
14
14
|
return _jsx(FactBox, {
|
|
15
15
|
children: domToReact(node.children, opts)
|
|
16
16
|
});
|
|
17
|
-
} else if (node.attribs["data-type"] === "rightAside") {
|
|
18
|
-
return _jsx(Aside, {
|
|
19
|
-
wideScreen: true,
|
|
20
|
-
alwaysShow: true,
|
|
21
|
-
children: domToReact(node.children, opts)
|
|
22
|
-
});
|
|
23
17
|
}
|
|
24
18
|
return null;
|
|
25
19
|
};
|
|
@@ -12,7 +12,7 @@ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
|
12
12
|
export const copyParagraphPlugin = (node, converterOpts, opts) => {
|
|
13
13
|
var _parent$attribs;
|
|
14
14
|
const parent = node.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
|
+
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 || (parent === null || parent === void 0 ? void 0 : parent.name) === "ndlaembed" && parent.attribs["data-resource"] === "uu-disclaimer") {
|
|
16
16
|
return _jsx(CopyParagraphButton, {
|
|
17
17
|
copyText: node.attribs["data-text"],
|
|
18
18
|
lang: opts.articleLanguage,
|
package/es/plugins/divPlugin.js
CHANGED
|
@@ -21,7 +21,8 @@ export const divPlugin = (node, opts) => {
|
|
|
21
21
|
...props,
|
|
22
22
|
children: domToReact(node.children, opts)
|
|
23
23
|
});
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
if (node.attribs["data-type"] === "file" && node.childNodes.length) {
|
|
25
26
|
const elements = node.childNodes.filter(c => c.type === "tag" && c.name === "ndlaembed" && c.attribs["data-resource"] === "file");
|
|
26
27
|
const [pdfs, files] = elements.reduce((acc, el) => {
|
|
27
28
|
const arr = el.attribs["data-type"] === "pdf" && el.attribs["data-display"] === "block" ? acc[0] : acc[1];
|
|
@@ -33,7 +34,8 @@ export const divPlugin = (node, opts) => {
|
|
|
33
34
|
children: domToReact(files, opts)
|
|
34
35
|
}) : undefined, domToReact(pdfs, opts)]
|
|
35
36
|
});
|
|
36
|
-
}
|
|
37
|
+
}
|
|
38
|
+
if (node.attribs["data-type"] === "grid" && node.children.length > 0) {
|
|
37
39
|
const props = attributesToProps(node.attribs);
|
|
38
40
|
const columns = props["data-columns"];
|
|
39
41
|
const border = props["data-border"];
|
|
@@ -47,7 +49,8 @@ export const divPlugin = (node, opts) => {
|
|
|
47
49
|
...props,
|
|
48
50
|
children: domToReact(node.children, opts)
|
|
49
51
|
});
|
|
50
|
-
}
|
|
52
|
+
}
|
|
53
|
+
if (node.attribs["data-parallax-cell"] === "true" && node.children.length) {
|
|
51
54
|
return _jsx(GridParallaxItem, {
|
|
52
55
|
children: domToReact(node.children, opts)
|
|
53
56
|
});
|
|
@@ -23,12 +23,11 @@ export const fileEmbedPlugin = element => {
|
|
|
23
23
|
title: title,
|
|
24
24
|
url: url
|
|
25
25
|
});
|
|
26
|
-
} else {
|
|
27
|
-
return _jsx(File, {
|
|
28
|
-
url: url,
|
|
29
|
-
title: title,
|
|
30
|
-
fileExists: data.status === "success" ? !!data.data.exists : false,
|
|
31
|
-
fileType: type
|
|
32
|
-
});
|
|
33
26
|
}
|
|
27
|
+
return _jsx(File, {
|
|
28
|
+
url: url,
|
|
29
|
+
title: title,
|
|
30
|
+
fileExists: data.status === "success" ? !!data.data.exists : false,
|
|
31
|
+
fileType: type
|
|
32
|
+
});
|
|
34
33
|
};
|
package/es/plugins/h3Plugin.js
CHANGED
package/es/plugins/olPlugin.js
CHANGED
|
@@ -13,7 +13,7 @@ export const olPlugin = (node, converterOpts, opts) => {
|
|
|
13
13
|
var _node$attribs$class;
|
|
14
14
|
const props = attributesToProps(node.attribs);
|
|
15
15
|
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
16
|
-
const num = node.attribs
|
|
16
|
+
const num = node.attribs.start;
|
|
17
17
|
const numClass = num ? "ol-reset-".concat(num) : false;
|
|
18
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(" ");
|
|
19
19
|
return _jsx(OrderedList, {
|
|
@@ -7,21 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { ArticleParagraph } from "@ndla/ui";
|
|
10
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
11
12
|
export const paragraphPlugin = (node, converterOpts, opts) => {
|
|
12
13
|
const props = attributesToProps(node.attribs);
|
|
13
|
-
|
|
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(" ");
|
|
16
|
-
return _jsx("p", {
|
|
17
|
-
...props,
|
|
18
|
-
lang: opts.articleLanguage,
|
|
19
|
-
"data-align": undefined,
|
|
20
|
-
className: classes,
|
|
21
|
-
children: domToReact(node.children, converterOpts)
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
return _jsx("p", {
|
|
14
|
+
return _jsx(ArticleParagraph, {
|
|
25
15
|
...props,
|
|
26
16
|
lang: opts.articleLanguage,
|
|
27
17
|
children: domToReact(node.children, converterOpts)
|
package/es/plugins/ulPlugin.js
CHANGED
|
@@ -10,12 +10,10 @@ 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;
|
|
14
13
|
const props = attributesToProps(node.attribs);
|
|
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(" ");
|
|
16
14
|
return _jsx(UnOrderedList, {
|
|
17
15
|
...props,
|
|
18
|
-
className:
|
|
16
|
+
className: node.attribs.class,
|
|
19
17
|
lang: opts.articleLanguage,
|
|
20
18
|
children: domToReact(node.children, converterOpts)
|
|
21
19
|
});
|
package/es/transform.js
CHANGED
|
@@ -24,12 +24,11 @@ const transform = (content, opts) => {
|
|
|
24
24
|
if (node.name === "ndlaembed") {
|
|
25
25
|
if (embedPlugins[node.attribs["data-resource"]]) {
|
|
26
26
|
return embedPlugins[node.attribs["data-resource"]](node, options, opts);
|
|
27
|
-
} else {
|
|
28
|
-
const embed = JSON.parse(node.attribs["data-json"]);
|
|
29
|
-
return _jsx(UnknownEmbed, {
|
|
30
|
-
embed: embed
|
|
31
|
-
});
|
|
32
27
|
}
|
|
28
|
+
const embed = JSON.parse(node.attribs["data-json"]);
|
|
29
|
+
return _jsx(UnknownEmbed, {
|
|
30
|
+
embed: embed
|
|
31
|
+
});
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
};
|
|
@@ -20,12 +20,6 @@ const asidePlugin = (node, opts) => {
|
|
|
20
20
|
return (0, _jsxRuntime.jsx)(_ui.FactBox, {
|
|
21
21
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
22
22
|
});
|
|
23
|
-
} else if (node.attribs["data-type"] === "rightAside") {
|
|
24
|
-
return (0, _jsxRuntime.jsx)(_ui.Aside, {
|
|
25
|
-
wideScreen: true,
|
|
26
|
-
alwaysShow: true,
|
|
27
|
-
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
28
|
-
});
|
|
29
23
|
}
|
|
30
24
|
return null;
|
|
31
25
|
};
|
|
@@ -18,7 +18,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
18
18
|
const copyParagraphPlugin = (node, converterOpts, opts) => {
|
|
19
19
|
var _parent$attribs;
|
|
20
20
|
const parent = node.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
|
+
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 || (parent === null || parent === void 0 ? void 0 : parent.name) === "ndlaembed" && parent.attribs["data-resource"] === "uu-disclaimer") {
|
|
22
22
|
return (0, _jsxRuntime.jsx)(_ui.CopyParagraphButton, {
|
|
23
23
|
copyText: node.attribs["data-text"],
|
|
24
24
|
lang: opts.articleLanguage,
|
package/lib/plugins/divPlugin.js
CHANGED
|
@@ -27,7 +27,8 @@ const divPlugin = (node, opts) => {
|
|
|
27
27
|
...props,
|
|
28
28
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
29
29
|
});
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
|
+
if (node.attribs["data-type"] === "file" && node.childNodes.length) {
|
|
31
32
|
const elements = node.childNodes.filter(c => c.type === "tag" && c.name === "ndlaembed" && c.attribs["data-resource"] === "file");
|
|
32
33
|
const [pdfs, files] = elements.reduce((acc, el) => {
|
|
33
34
|
const arr = el.attribs["data-type"] === "pdf" && el.attribs["data-display"] === "block" ? acc[0] : acc[1];
|
|
@@ -39,7 +40,8 @@ const divPlugin = (node, opts) => {
|
|
|
39
40
|
children: (0, _htmlReactParser.domToReact)(files, opts)
|
|
40
41
|
}) : undefined, (0, _htmlReactParser.domToReact)(pdfs, opts)]
|
|
41
42
|
});
|
|
42
|
-
}
|
|
43
|
+
}
|
|
44
|
+
if (node.attribs["data-type"] === "grid" && node.children.length > 0) {
|
|
43
45
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
44
46
|
const columns = props["data-columns"];
|
|
45
47
|
const border = props["data-border"];
|
|
@@ -53,7 +55,8 @@ const divPlugin = (node, opts) => {
|
|
|
53
55
|
...props,
|
|
54
56
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
55
57
|
});
|
|
56
|
-
}
|
|
58
|
+
}
|
|
59
|
+
if (node.attribs["data-parallax-cell"] === "true" && node.children.length) {
|
|
57
60
|
return (0, _jsxRuntime.jsx)(_ui.GridParallaxItem, {
|
|
58
61
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
59
62
|
});
|
|
@@ -29,13 +29,12 @@ const fileEmbedPlugin = element => {
|
|
|
29
29
|
title: title,
|
|
30
30
|
url: url
|
|
31
31
|
});
|
|
32
|
-
} else {
|
|
33
|
-
return (0, _jsxRuntime.jsx)(_ui.File, {
|
|
34
|
-
url: url,
|
|
35
|
-
title: title,
|
|
36
|
-
fileExists: data.status === "success" ? !!data.data.exists : false,
|
|
37
|
-
fileType: type
|
|
38
|
-
});
|
|
39
32
|
}
|
|
33
|
+
return (0, _jsxRuntime.jsx)(_ui.File, {
|
|
34
|
+
url: url,
|
|
35
|
+
title: title,
|
|
36
|
+
fileExists: data.status === "success" ? !!data.data.exists : false,
|
|
37
|
+
fileType: type
|
|
38
|
+
});
|
|
40
39
|
};
|
|
41
40
|
exports.fileEmbedPlugin = fileEmbedPlugin;
|
package/lib/plugins/h3Plugin.js
CHANGED
|
@@ -20,7 +20,6 @@ const h3Plugin = (node, converterOpts, opts) => {
|
|
|
20
20
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
21
21
|
(0, _jsxRuntime.jsx)("h3", {
|
|
22
22
|
...props,
|
|
23
|
-
tabIndex: 0,
|
|
24
23
|
lang: opts.articleLanguage,
|
|
25
24
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
|
26
25
|
})
|
package/lib/plugins/olPlugin.js
CHANGED
|
@@ -19,7 +19,7 @@ const olPlugin = (node, converterOpts, opts) => {
|
|
|
19
19
|
var _node$attribs$class;
|
|
20
20
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
21
21
|
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
22
|
-
const num = node.attribs
|
|
22
|
+
const num = node.attribs.start;
|
|
23
23
|
const numClass = num ? "ol-reset-".concat(num) : false;
|
|
24
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(" ");
|
|
25
25
|
return (0, _jsxRuntime.jsx)(_ui.OrderedList, {
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.paragraphPlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
+
var _ui = require("@ndla/ui");
|
|
8
9
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
9
10
|
/**
|
|
10
11
|
* Copyright (c) 2023-present, NDLA.
|
|
@@ -16,18 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
17
|
|
|
17
18
|
const paragraphPlugin = (node, converterOpts, opts) => {
|
|
18
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
19
|
-
|
|
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(" ");
|
|
22
|
-
return (0, _jsxRuntime.jsx)("p", {
|
|
23
|
-
...props,
|
|
24
|
-
lang: opts.articleLanguage,
|
|
25
|
-
"data-align": undefined,
|
|
26
|
-
className: classes,
|
|
27
|
-
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return (0, _jsxRuntime.jsx)("p", {
|
|
20
|
+
return (0, _jsxRuntime.jsx)(_ui.ArticleParagraph, {
|
|
31
21
|
...props,
|
|
32
22
|
lang: opts.articleLanguage,
|
|
33
23
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
package/lib/plugins/ulPlugin.js
CHANGED
|
@@ -16,12 +16,10 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const ulPlugin = (node, converterOpts, opts) => {
|
|
19
|
-
var _node$attribs$class;
|
|
20
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
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(" ");
|
|
22
20
|
return (0, _jsxRuntime.jsx)(_ui.UnOrderedList, {
|
|
23
21
|
...props,
|
|
24
|
-
className:
|
|
22
|
+
className: node.attribs.class,
|
|
25
23
|
lang: opts.articleLanguage,
|
|
26
24
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
|
27
25
|
});
|
package/lib/transform.js
CHANGED
|
@@ -31,12 +31,11 @@ const transform = (content, opts) => {
|
|
|
31
31
|
if (node.name === "ndlaembed") {
|
|
32
32
|
if (_embed.embedPlugins[node.attribs["data-resource"]]) {
|
|
33
33
|
return _embed.embedPlugins[node.attribs["data-resource"]](node, options, opts);
|
|
34
|
-
} else {
|
|
35
|
-
const embed = JSON.parse(node.attribs["data-json"]);
|
|
36
|
-
return (0, _jsxRuntime.jsx)(_ui.UnknownEmbed, {
|
|
37
|
-
embed: embed
|
|
38
|
-
});
|
|
39
34
|
}
|
|
35
|
+
const embed = JSON.parse(node.attribs["data-json"]);
|
|
36
|
+
return (0, _jsxRuntime.jsx)(_ui.UnknownEmbed, {
|
|
37
|
+
embed: embed
|
|
38
|
+
});
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -31,21 +31,20 @@
|
|
|
31
31
|
"@ndla/types-embed": "^4.1.6"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ndla/
|
|
35
|
-
"@ndla/ui": "^50.15.3",
|
|
34
|
+
"@ndla/ui": "^52.0.0",
|
|
36
35
|
"html-react-parser": "^5.1.8"
|
|
37
36
|
},
|
|
38
37
|
"peerDependencies": {
|
|
39
38
|
"@emotion/react": "^11.10.4",
|
|
40
39
|
"@emotion/styled": "^11.10.4",
|
|
41
|
-
"i18next": ">= 23.
|
|
40
|
+
"i18next": ">= 23.11.5",
|
|
42
41
|
"react": ">= 16.8.0",
|
|
43
42
|
"react-dom": ">= 16.8.0",
|
|
44
|
-
"react-i18next": "^
|
|
43
|
+
"react-i18next": "^14.1.1",
|
|
45
44
|
"react-router-dom": ">= 6.0.0"
|
|
46
45
|
},
|
|
47
46
|
"publishConfig": {
|
|
48
47
|
"access": "public"
|
|
49
48
|
},
|
|
50
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "dab99b8c9bf77c2ee7690d348b2ae811af81bd3d"
|
|
51
50
|
}
|
|
@@ -7,18 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { DOMNode, domToReact } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { FactBox } from "@ndla/ui";
|
|
11
11
|
import { PluginType } from "./types";
|
|
12
12
|
export const asidePlugin: PluginType = (node, opts) => {
|
|
13
13
|
if (node.attribs["data-type"] === "factAside") {
|
|
14
14
|
return <FactBox>{domToReact(node.children as DOMNode[], opts)}</FactBox>;
|
|
15
|
-
} else if (node.attribs["data-type"] === "rightAside") {
|
|
16
|
-
return (
|
|
17
|
-
<Aside wideScreen alwaysShow>
|
|
18
|
-
{domToReact(node.children as DOMNode[], opts)}
|
|
19
|
-
</Aside>
|
|
20
|
-
);
|
|
21
15
|
}
|
|
22
|
-
|
|
23
16
|
return null;
|
|
24
17
|
};
|
|
@@ -11,7 +11,11 @@ import { CopyParagraphButton } from "@ndla/ui";
|
|
|
11
11
|
import { PluginType } from "./types";
|
|
12
12
|
export const copyParagraphPlugin: PluginType = (node, converterOpts, opts) => {
|
|
13
13
|
const parent = node.parent as Element | undefined;
|
|
14
|
-
if (
|
|
14
|
+
if (
|
|
15
|
+
parent?.name === "section" ||
|
|
16
|
+
(parent?.name === "div" && Object.keys(parent.attribs ?? {}).length === 0) ||
|
|
17
|
+
(parent?.name === "ndlaembed" && parent.attribs["data-resource"] === "uu-disclaimer")
|
|
18
|
+
) {
|
|
15
19
|
return (
|
|
16
20
|
<CopyParagraphButton copyText={node.attribs["data-text"]} lang={opts.articleLanguage}>
|
|
17
21
|
{domToReact(node.children as DOMNode[], converterOpts)}
|
|
@@ -23,7 +23,8 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
23
23
|
{domToReact(node.children, opts)}
|
|
24
24
|
</RelatedArticleList>
|
|
25
25
|
);
|
|
26
|
-
}
|
|
26
|
+
}
|
|
27
|
+
if (node.attribs["data-type"] === "file" && node.childNodes.length) {
|
|
27
28
|
const elements = node.childNodes.filter(
|
|
28
29
|
(c): c is Element => c.type === "tag" && c.name === "ndlaembed" && c.attribs["data-resource"] === "file",
|
|
29
30
|
);
|
|
@@ -42,7 +43,8 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
42
43
|
{domToReact(pdfs, opts)}
|
|
43
44
|
</>
|
|
44
45
|
);
|
|
45
|
-
}
|
|
46
|
+
}
|
|
47
|
+
if (node.attribs["data-type"] === "grid" && node.children.length > 0) {
|
|
46
48
|
const props = attributesToProps(node.attribs);
|
|
47
49
|
const columns = props["data-columns"] as GridType["columns"];
|
|
48
50
|
const border = props["data-border"] as GridType["border"];
|
|
@@ -54,7 +56,8 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
54
56
|
{domToReact(node.children, opts)}
|
|
55
57
|
</Grid>
|
|
56
58
|
);
|
|
57
|
-
}
|
|
59
|
+
}
|
|
60
|
+
if (node.attribs["data-parallax-cell"] === "true" && node.children.length) {
|
|
58
61
|
return <GridParallaxItem>{domToReact(node.children as DOMNode[], opts)}</GridParallaxItem>;
|
|
59
62
|
}
|
|
60
63
|
return null;
|
|
@@ -17,14 +17,8 @@ export const fileEmbedPlugin: PluginType = (element) => {
|
|
|
17
17
|
const { type, title, url, display } = data.embedData;
|
|
18
18
|
if (type === "pdf" && display === "block") {
|
|
19
19
|
return <PdfFile title={title} url={url} />;
|
|
20
|
-
} else {
|
|
21
|
-
return (
|
|
22
|
-
<File
|
|
23
|
-
url={url}
|
|
24
|
-
title={title}
|
|
25
|
-
fileExists={data.status === "success" ? !!data.data.exists : false}
|
|
26
|
-
fileType={type}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
20
|
}
|
|
21
|
+
return (
|
|
22
|
+
<File url={url} title={title} fileExists={data.status === "success" ? !!data.data.exists : false} fileType={type} />
|
|
23
|
+
);
|
|
30
24
|
};
|
package/src/plugins/h3Plugin.tsx
CHANGED
|
@@ -12,7 +12,7 @@ export const h3Plugin: PluginType = (node, converterOpts, opts) => {
|
|
|
12
12
|
const props = attributesToProps(node.attribs);
|
|
13
13
|
return (
|
|
14
14
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
15
|
-
<h3 {...props}
|
|
15
|
+
<h3 {...props} lang={opts.articleLanguage}>
|
|
16
16
|
{domToReact(node.children as DOMNode[], converterOpts)}
|
|
17
17
|
</h3>
|
|
18
18
|
);
|
package/src/plugins/olPlugin.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { PluginType } from "./types";
|
|
|
12
12
|
export const olPlugin: PluginType = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
|
14
14
|
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
15
|
-
const num = node.attribs
|
|
15
|
+
const num = node.attribs.start;
|
|
16
16
|
const numClass = num ? `ol-reset-${num}` : false;
|
|
17
17
|
const classes = [node.attribs.class ?? false, letterClass, numClass].filter((c): c is string => !!c).join(" ");
|
|
18
18
|
|
|
@@ -7,20 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { DOMNode, attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { ArticleParagraph } from "@ndla/ui";
|
|
10
11
|
import { PluginType } from "./types";
|
|
12
|
+
|
|
11
13
|
export const paragraphPlugin: PluginType = (node, converterOpts, opts) => {
|
|
12
14
|
const props = attributesToProps(node.attribs);
|
|
13
|
-
if (node.attribs["data-align"] === "center") {
|
|
14
|
-
const classes = [node.attribs.class ?? "", "u-text-center"].filter((c) => !!c).join(" ");
|
|
15
|
-
return (
|
|
16
|
-
<p {...props} lang={opts.articleLanguage} data-align={undefined} className={classes}>
|
|
17
|
-
{domToReact(node.children as DOMNode[], converterOpts)}
|
|
18
|
-
</p>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
15
|
return (
|
|
22
|
-
<
|
|
16
|
+
<ArticleParagraph {...props} lang={opts.articleLanguage}>
|
|
23
17
|
{domToReact(node.children as DOMNode[], converterOpts)}
|
|
24
|
-
</
|
|
18
|
+
</ArticleParagraph>
|
|
25
19
|
);
|
|
26
20
|
};
|
package/src/plugins/ulPlugin.tsx
CHANGED
|
@@ -11,11 +11,8 @@ import { UnOrderedList } from "@ndla/ui";
|
|
|
11
11
|
import { PluginType } from "./types";
|
|
12
12
|
export const ulPlugin: PluginType = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
|
14
|
-
const classes = [node.attribs.class ?? "", node.attribs["data-type"] === "two-column" ? "o-list--two-columns" : ""]
|
|
15
|
-
.filter((c) => !!c)
|
|
16
|
-
.join(" ");
|
|
17
14
|
return (
|
|
18
|
-
<UnOrderedList {...props} className={
|
|
15
|
+
<UnOrderedList {...props} className={node.attribs.class} lang={opts.articleLanguage}>
|
|
19
16
|
{domToReact(node.children as DOMNode[], converterOpts)}
|
|
20
17
|
</UnOrderedList>
|
|
21
18
|
);
|
package/src/transform.tsx
CHANGED
|
@@ -26,10 +26,9 @@ const transform = (content: string, opts: TransformOptions) => {
|
|
|
26
26
|
if (node.name === "ndlaembed") {
|
|
27
27
|
if (embedPlugins[node.attribs["data-resource"]]) {
|
|
28
28
|
return embedPlugins[node.attribs["data-resource"]](node, options, opts);
|
|
29
|
-
} else {
|
|
30
|
-
const embed = JSON.parse(node.attribs["data-json"]) as MetaData<any, any>;
|
|
31
|
-
return <UnknownEmbed embed={embed} />;
|
|
32
29
|
}
|
|
30
|
+
const embed = JSON.parse(node.attribs["data-json"]) as MetaData<any, any>;
|
|
31
|
+
return <UnknownEmbed embed={embed} />;
|
|
33
32
|
}
|
|
34
33
|
},
|
|
35
34
|
};
|