@ndla/article-converter 2.3.17 → 2.4.1
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.
|
@@ -10,8 +10,13 @@ import { CopyParagraphButtonV2 } from '@ndla/ui';
|
|
|
10
10
|
import { domToReact } from 'html-react-parser';
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export var copyParagraphPlugin = function copyParagraphPlugin(node, opts) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
var _parent$attribs;
|
|
14
|
+
var 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) {
|
|
16
|
+
return _jsx(CopyParagraphButtonV2, {
|
|
17
|
+
copyText: node.attribs['data-text'],
|
|
18
|
+
children: domToReact(node.children, opts)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
17
22
|
};
|
package/es/plugins/divPlugin.js
CHANGED
|
@@ -25,7 +25,6 @@ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
|
25
25
|
import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
26
26
|
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
27
27
|
export var divPlugin = function divPlugin(node, opts) {
|
|
28
|
-
var _node$attribs$class;
|
|
29
28
|
if (node.attribs['data-type'] === 'related-content' && node.children.length) {
|
|
30
29
|
var props = attributesToProps(node.attribs);
|
|
31
30
|
return _jsx(RelatedArticleListV2, _objectSpread(_objectSpread({}, props), {}, {
|
|
@@ -47,28 +46,18 @@ export var divPlugin = function divPlugin(node, opts) {
|
|
|
47
46
|
children: domToReact(files, opts)
|
|
48
47
|
}) : undefined, domToReact(pdfs, opts)]
|
|
49
48
|
});
|
|
50
|
-
} else if ((_node$attribs$class = node.attribs['class']) !== null && _node$attribs$class !== void 0 && _node$attribs$class.includes('c-bodybox') && node.childNodes.filter(function (c) {
|
|
51
|
-
return 'attribs' in c;
|
|
52
|
-
}).some(function (c) {
|
|
53
|
-
return c.name === 'table';
|
|
54
|
-
})) {
|
|
55
|
-
var _props = attributesToProps(node.attribs);
|
|
56
|
-
return _jsx("div", _objectSpread(_objectSpread({}, _props), {}, {
|
|
57
|
-
className: "".concat(_props.className, " c-bodybox--contains-table"),
|
|
58
|
-
children: domToReact(node.children, opts)
|
|
59
|
-
}));
|
|
60
49
|
} else if (node.attribs['data-type'] === 'grid' && node.children.length > 0) {
|
|
61
|
-
var
|
|
62
|
-
var columns =
|
|
63
|
-
var border =
|
|
64
|
-
var background =
|
|
65
|
-
var frontpage = !!
|
|
50
|
+
var _props = attributesToProps(node.attribs);
|
|
51
|
+
var columns = _props['data-columns'];
|
|
52
|
+
var border = _props['data-border'];
|
|
53
|
+
var background = _props['data-background'];
|
|
54
|
+
var frontpage = !!_props['data-size'];
|
|
66
55
|
return _jsx(Grid, _objectSpread(_objectSpread({
|
|
67
56
|
isFrontpage: frontpage,
|
|
68
57
|
border: border,
|
|
69
58
|
columns: columns,
|
|
70
59
|
background: background
|
|
71
|
-
},
|
|
60
|
+
}, _props), {}, {
|
|
72
61
|
children: domToReact(node.children, opts)
|
|
73
62
|
}));
|
|
74
63
|
}
|
|
@@ -16,9 +16,14 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
var copyParagraphPlugin = function copyParagraphPlugin(node, opts) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
var _parent$attribs;
|
|
20
|
+
var 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) {
|
|
22
|
+
return (0, _jsxRuntime.jsx)(_ui.CopyParagraphButtonV2, {
|
|
23
|
+
copyText: node.attribs['data-text'],
|
|
24
|
+
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
23
28
|
};
|
|
24
29
|
exports.copyParagraphPlugin = copyParagraphPlugin;
|
package/lib/plugins/divPlugin.js
CHANGED
|
@@ -28,7 +28,6 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
28
28
|
*
|
|
29
29
|
*/
|
|
30
30
|
var divPlugin = function divPlugin(node, opts) {
|
|
31
|
-
var _node$attribs$class;
|
|
32
31
|
if (node.attribs['data-type'] === 'related-content' && node.children.length) {
|
|
33
32
|
var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
34
33
|
return (0, _jsxRuntime.jsx)(_ui.RelatedArticleListV2, _objectSpread(_objectSpread({}, props), {}, {
|
|
@@ -50,28 +49,18 @@ var divPlugin = function divPlugin(node, opts) {
|
|
|
50
49
|
children: (0, _htmlReactParser.domToReact)(files, opts)
|
|
51
50
|
}) : undefined, (0, _htmlReactParser.domToReact)(pdfs, opts)]
|
|
52
51
|
});
|
|
53
|
-
} else if ((_node$attribs$class = node.attribs['class']) !== null && _node$attribs$class !== void 0 && _node$attribs$class.includes('c-bodybox') && node.childNodes.filter(function (c) {
|
|
54
|
-
return 'attribs' in c;
|
|
55
|
-
}).some(function (c) {
|
|
56
|
-
return c.name === 'table';
|
|
57
|
-
})) {
|
|
58
|
-
var _props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
59
|
-
return (0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, _props), {}, {
|
|
60
|
-
className: "".concat(_props.className, " c-bodybox--contains-table"),
|
|
61
|
-
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
62
|
-
}));
|
|
63
52
|
} else if (node.attribs['data-type'] === 'grid' && node.children.length > 0) {
|
|
64
|
-
var
|
|
65
|
-
var columns =
|
|
66
|
-
var border =
|
|
67
|
-
var background =
|
|
68
|
-
var frontpage = !!
|
|
53
|
+
var _props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
54
|
+
var columns = _props['data-columns'];
|
|
55
|
+
var border = _props['data-border'];
|
|
56
|
+
var background = _props['data-background'];
|
|
57
|
+
var frontpage = !!_props['data-size'];
|
|
69
58
|
return (0, _jsxRuntime.jsx)(_ui.Grid, _objectSpread(_objectSpread({
|
|
70
59
|
isFrontpage: frontpage,
|
|
71
60
|
border: border,
|
|
72
61
|
columns: columns,
|
|
73
62
|
background: background
|
|
74
|
-
},
|
|
63
|
+
}, _props), {}, {
|
|
75
64
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
76
65
|
}));
|
|
77
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@ndla/types-embed": "^2.0.5"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ndla/code": "^2.2.
|
|
34
|
-
"@ndla/ui": "^
|
|
33
|
+
"@ndla/code": "^2.2.15",
|
|
34
|
+
"@ndla/ui": "^42.0.1",
|
|
35
35
|
"html-react-parser": "^3.0.8",
|
|
36
36
|
"lodash": "^4.17.20"
|
|
37
37
|
},
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "a96d41fdd79d1372f1b8e8a3f50ad52983d26e30"
|
|
48
48
|
}
|
|
@@ -7,12 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { CopyParagraphButtonV2 } from '@ndla/ui';
|
|
10
|
-
import { domToReact } from 'html-react-parser';
|
|
10
|
+
import { Element, domToReact } from 'html-react-parser';
|
|
11
11
|
import { PluginType } from './types';
|
|
12
12
|
export const copyParagraphPlugin: PluginType = (node, opts) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const parent = node.parent as Element | undefined;
|
|
14
|
+
if (parent?.name === 'section' || (parent?.name === 'div' && Object.keys(parent.attribs ?? {}).length === 0)) {
|
|
15
|
+
return (
|
|
16
|
+
<CopyParagraphButtonV2 copyText={node.attribs['data-text']}>
|
|
17
|
+
{domToReact(node.children, opts)}
|
|
18
|
+
</CopyParagraphButtonV2>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
18
22
|
};
|
|
@@ -36,16 +36,6 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
36
36
|
{domToReact(pdfs, opts)}
|
|
37
37
|
</>
|
|
38
38
|
);
|
|
39
|
-
} else if (
|
|
40
|
-
node.attribs['class']?.includes('c-bodybox') &&
|
|
41
|
-
node.childNodes.filter((c): c is Element => 'attribs' in c).some((c) => c.name === 'table')
|
|
42
|
-
) {
|
|
43
|
-
const props = attributesToProps(node.attribs);
|
|
44
|
-
return (
|
|
45
|
-
<div {...props} className={`${props.className} c-bodybox--contains-table`}>
|
|
46
|
-
{domToReact(node.children, opts)}
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
39
|
} else if (node.attribs['data-type'] === 'grid' && node.children.length > 0) {
|
|
50
40
|
const props = attributesToProps(node.attribs);
|
|
51
41
|
const columns = props['data-columns'] as GridType['columns'];
|