@ndla/article-converter 2.4.11 → 2.5.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/extractEmbedMeta.js +22 -0
- package/es/index.js +1 -1
- package/es/plugins/divPlugin.js +5 -1
- package/es/plugins/embed/linkBlockEmbedPlugin.js +22 -0
- package/es/plugins/index.js +3 -1
- package/es/plugins/navPlugin.js +26 -0
- package/lib/extractEmbedMeta.d.ts +1 -0
- package/lib/extractEmbedMeta.js +24 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +10 -1
- package/lib/plugins/divPlugin.js +4 -0
- package/lib/plugins/embed/linkBlockEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/linkBlockEmbedPlugin.js +27 -0
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/navPlugin.d.ts +9 -0
- package/lib/plugins/navPlugin.js +31 -0
- package/package.json +5 -5
- package/src/extractEmbedMeta.ts +23 -0
- package/src/index.ts +1 -1
- package/src/plugins/divPlugin.tsx +3 -1
- package/src/plugins/embed/linkBlockEmbedPlugin.tsx +19 -0
- package/src/plugins/index.ts +2 -0
- package/src/plugins/navPlugin.tsx +19 -0
package/es/extractEmbedMeta.js
CHANGED
|
@@ -14,4 +14,26 @@ var extractEmbedMeta = function extractEmbedMeta(embed) {
|
|
|
14
14
|
}
|
|
15
15
|
return JSON.parse(node.props['data-json']);
|
|
16
16
|
};
|
|
17
|
+
export var extractEmbedMetas = function extractEmbedMetas(embed) {
|
|
18
|
+
var nodes = parse(embed);
|
|
19
|
+
|
|
20
|
+
// There are no embeds in the string
|
|
21
|
+
if (typeof nodes === 'string') {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
// There is only one embed in the string
|
|
25
|
+
else if (!Array.isArray(nodes) && nodes.type === 'ndlaembed' && !!nodes.props['data-json']) {
|
|
26
|
+
return [JSON.parse(nodes.props['data-json'])];
|
|
27
|
+
}
|
|
28
|
+
// There are multiple embeds in the string
|
|
29
|
+
else if (Array.isArray(nodes) && nodes.length && nodes.every(function (n) {
|
|
30
|
+
return n.type === 'ndlaembed' && !!n.props['data-json'];
|
|
31
|
+
})) {
|
|
32
|
+
return nodes.map(function (n) {
|
|
33
|
+
return JSON.parse(n.props['data-json']);
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
};
|
|
17
39
|
export default extractEmbedMeta;
|
package/es/index.js
CHANGED
package/es/plugins/divPlugin.js
CHANGED
|
@@ -20,7 +20,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
20
20
|
|
|
21
21
|
import partition from 'lodash/partition';
|
|
22
22
|
import { domToReact, attributesToProps } from 'html-react-parser';
|
|
23
|
-
import { FileListV2, RelatedArticleListV2, Grid } from '@ndla/ui';
|
|
23
|
+
import { FileListV2, RelatedArticleListV2, Grid, GridParallaxItem } from '@ndla/ui';
|
|
24
24
|
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";
|
|
@@ -60,6 +60,10 @@ export var divPlugin = function divPlugin(node, opts) {
|
|
|
60
60
|
}, _props), {}, {
|
|
61
61
|
children: domToReact(node.children, opts)
|
|
62
62
|
}));
|
|
63
|
+
} else if (node.attribs['data-parallax-cell'] === 'true' && node.children.length) {
|
|
64
|
+
return _jsx(GridParallaxItem, {
|
|
65
|
+
children: domToReact(node.children, opts)
|
|
66
|
+
});
|
|
63
67
|
}
|
|
64
68
|
return null;
|
|
65
69
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) 2023-present, NDLA.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { LinkBlock } from '@ndla/ui';
|
|
16
|
+
import { attributesToProps } from 'html-react-parser';
|
|
17
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
18
|
+
export var imageEmbedPlugin = function imageEmbedPlugin(element) {
|
|
19
|
+
var props = attributesToProps(element.attribs);
|
|
20
|
+
var data = JSON.parse(props['data-json']);
|
|
21
|
+
return _jsx(LinkBlock, _objectSpread({}, data.embedData));
|
|
22
|
+
};
|
package/es/plugins/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import { asidePlugin } from './asidePlugin';
|
|
|
25
25
|
import { ulPlugin } from './ulPlugin';
|
|
26
26
|
import { ddPlugin } from './ddPlugin';
|
|
27
27
|
import { dtPlugin } from './dtPlugin';
|
|
28
|
+
import { navPlugin } from './navPlugin';
|
|
28
29
|
export var basePlugins = {
|
|
29
30
|
h2: copyParagraphPlugin,
|
|
30
31
|
h3: h3Plugin,
|
|
@@ -37,7 +38,8 @@ export var basePlugins = {
|
|
|
37
38
|
aside: asidePlugin,
|
|
38
39
|
ul: ulPlugin,
|
|
39
40
|
dd: ddPlugin,
|
|
40
|
-
dt: dtPlugin
|
|
41
|
+
dt: dtPlugin,
|
|
42
|
+
nav: navPlugin
|
|
41
43
|
};
|
|
42
44
|
export var oembedPlugins = _objectSpread(_objectSpread({}, basePlugins), {}, {
|
|
43
45
|
a: anchorPlugin
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) 2023-present, NDLA.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
16
|
+
import { LinkBlockSection } from '@ndla/ui';
|
|
17
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
18
|
+
export var navPlugin = function navPlugin(node, opts) {
|
|
19
|
+
if (node.attribs['data-type'] === 'link-block') {
|
|
20
|
+
var props = attributesToProps(node.attribs);
|
|
21
|
+
return _jsx(LinkBlockSection, _objectSpread(_objectSpread({}, props), {}, {
|
|
22
|
+
children: domToReact(node.children, opts)
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
};
|
package/lib/extractEmbedMeta.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.extractEmbedMetas = exports.default = void 0;
|
|
7
7
|
var _htmlReactParser = _interopRequireDefault(require("html-react-parser"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
9
|
/**
|
|
@@ -21,5 +21,28 @@ var extractEmbedMeta = function extractEmbedMeta(embed) {
|
|
|
21
21
|
}
|
|
22
22
|
return JSON.parse(node.props['data-json']);
|
|
23
23
|
};
|
|
24
|
+
var extractEmbedMetas = function extractEmbedMetas(embed) {
|
|
25
|
+
var nodes = (0, _htmlReactParser.default)(embed);
|
|
26
|
+
|
|
27
|
+
// There are no embeds in the string
|
|
28
|
+
if (typeof nodes === 'string') {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
// There is only one embed in the string
|
|
32
|
+
else if (!Array.isArray(nodes) && nodes.type === 'ndlaembed' && !!nodes.props['data-json']) {
|
|
33
|
+
return [JSON.parse(nodes.props['data-json'])];
|
|
34
|
+
}
|
|
35
|
+
// There are multiple embeds in the string
|
|
36
|
+
else if (Array.isArray(nodes) && nodes.length && nodes.every(function (n) {
|
|
37
|
+
return n.type === 'ndlaembed' && !!n.props['data-json'];
|
|
38
|
+
})) {
|
|
39
|
+
return nodes.map(function (n) {
|
|
40
|
+
return JSON.parse(n.props['data-json']);
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.extractEmbedMetas = extractEmbedMetas;
|
|
24
47
|
var _default = extractEmbedMeta;
|
|
25
48
|
exports.default = _default;
|
package/lib/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
export { default as transform } from './transform';
|
|
9
|
-
export { default as extractEmbedMeta } from './extractEmbedMeta';
|
|
9
|
+
export { default as extractEmbedMeta, extractEmbedMetas } from './extractEmbedMeta';
|
|
10
10
|
export type { TransformOptions, DynamicComponents } from './plugins/types';
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -9,6 +10,12 @@ Object.defineProperty(exports, "extractEmbedMeta", {
|
|
|
9
10
|
return _extractEmbedMeta.default;
|
|
10
11
|
}
|
|
11
12
|
});
|
|
13
|
+
Object.defineProperty(exports, "extractEmbedMetas", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _extractEmbedMeta.extractEmbedMetas;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
12
19
|
Object.defineProperty(exports, "transform", {
|
|
13
20
|
enumerable: true,
|
|
14
21
|
get: function get() {
|
|
@@ -16,5 +23,7 @@ Object.defineProperty(exports, "transform", {
|
|
|
16
23
|
}
|
|
17
24
|
});
|
|
18
25
|
var _transform = _interopRequireDefault(require("./transform"));
|
|
19
|
-
var _extractEmbedMeta =
|
|
26
|
+
var _extractEmbedMeta = _interopRequireWildcard(require("./extractEmbedMeta"));
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/plugins/divPlugin.js
CHANGED
|
@@ -63,6 +63,10 @@ var divPlugin = function divPlugin(node, opts) {
|
|
|
63
63
|
}, _props), {}, {
|
|
64
64
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
65
65
|
}));
|
|
66
|
+
} else if (node.attribs['data-parallax-cell'] === 'true' && node.children.length) {
|
|
67
|
+
return (0, _jsxRuntime.jsx)(_ui.GridParallaxItem, {
|
|
68
|
+
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
69
|
+
});
|
|
66
70
|
}
|
|
67
71
|
return null;
|
|
68
72
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { PluginType } from '../types';
|
|
9
|
+
export declare const imageEmbedPlugin: PluginType;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.imageEmbedPlugin = void 0;
|
|
7
|
+
var _ui = require("@ndla/ui");
|
|
8
|
+
var _htmlReactParser = require("html-react-parser");
|
|
9
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**
|
|
16
|
+
* Copyright (c) 2023-present, NDLA.
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
19
|
+
* LICENSE file in the root directory of this source tree.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
var imageEmbedPlugin = function imageEmbedPlugin(element) {
|
|
23
|
+
var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
24
|
+
var data = JSON.parse(props['data-json']);
|
|
25
|
+
return (0, _jsxRuntime.jsx)(_ui.LinkBlock, _objectSpread({}, data.embedData));
|
|
26
|
+
};
|
|
27
|
+
exports.imageEmbedPlugin = imageEmbedPlugin;
|
package/lib/plugins/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var _asidePlugin = require("./asidePlugin");
|
|
|
17
17
|
var _ulPlugin = require("./ulPlugin");
|
|
18
18
|
var _ddPlugin = require("./ddPlugin");
|
|
19
19
|
var _dtPlugin = require("./dtPlugin");
|
|
20
|
+
var _navPlugin = require("./navPlugin");
|
|
20
21
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
21
22
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
22
23
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -41,7 +42,8 @@ var basePlugins = {
|
|
|
41
42
|
aside: _asidePlugin.asidePlugin,
|
|
42
43
|
ul: _ulPlugin.ulPlugin,
|
|
43
44
|
dd: _ddPlugin.ddPlugin,
|
|
44
|
-
dt: _dtPlugin.dtPlugin
|
|
45
|
+
dt: _dtPlugin.dtPlugin,
|
|
46
|
+
nav: _navPlugin.navPlugin
|
|
45
47
|
};
|
|
46
48
|
exports.basePlugins = basePlugins;
|
|
47
49
|
var oembedPlugins = _objectSpread(_objectSpread({}, basePlugins), {}, {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { PluginType } from './types';
|
|
9
|
+
export declare const navPlugin: PluginType;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.navPlugin = void 0;
|
|
7
|
+
var _htmlReactParser = require("html-react-parser");
|
|
8
|
+
var _ui = require("@ndla/ui");
|
|
9
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**
|
|
16
|
+
* Copyright (c) 2023-present, NDLA.
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
19
|
+
* LICENSE file in the root directory of this source tree.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
var navPlugin = function navPlugin(node, opts) {
|
|
23
|
+
if (node.attribs['data-type'] === 'link-block') {
|
|
24
|
+
var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
25
|
+
return (0, _jsxRuntime.jsx)(_ui.LinkBlockSection, _objectSpread(_objectSpread({}, props), {}, {
|
|
26
|
+
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
exports.navPlugin = navPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"src"
|
|
28
28
|
],
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@ndla/types-embed": "^2.0.
|
|
30
|
+
"@ndla/types-embed": "^2.0.7"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ndla/code": "^2.2.
|
|
34
|
-
"@ndla/ui": "^
|
|
33
|
+
"@ndla/code": "^2.2.22",
|
|
34
|
+
"@ndla/ui": "^44.0.0",
|
|
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": "dfd245ca3261ca1209556b43c6185220e2fd7639"
|
|
48
48
|
}
|
package/src/extractEmbedMeta.ts
CHANGED
|
@@ -18,4 +18,27 @@ const extractEmbedMeta = (embed: string): EmbedMetaData | undefined => {
|
|
|
18
18
|
return JSON.parse(node.props['data-json']) as EmbedMetaData;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
export const extractEmbedMetas = (embed: string): EmbedMetaData[] => {
|
|
22
|
+
const nodes = parse(embed);
|
|
23
|
+
|
|
24
|
+
// There are no embeds in the string
|
|
25
|
+
if (typeof nodes === 'string') {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
// There is only one embed in the string
|
|
29
|
+
else if (!Array.isArray(nodes) && nodes.type === 'ndlaembed' && !!nodes.props['data-json']) {
|
|
30
|
+
return [JSON.parse(nodes.props['data-json']) as EmbedMetaData];
|
|
31
|
+
}
|
|
32
|
+
// There are multiple embeds in the string
|
|
33
|
+
else if (
|
|
34
|
+
Array.isArray(nodes) &&
|
|
35
|
+
nodes.length &&
|
|
36
|
+
nodes.every((n) => n.type === 'ndlaembed' && !!n.props['data-json'])
|
|
37
|
+
) {
|
|
38
|
+
return nodes.map((n) => JSON.parse(n.props['data-json']) as EmbedMetaData);
|
|
39
|
+
} else {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
21
44
|
export default extractEmbedMeta;
|
package/src/index.ts
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
export { default as transform } from './transform';
|
|
10
|
-
export { default as extractEmbedMeta } from './extractEmbedMeta';
|
|
10
|
+
export { default as extractEmbedMeta, extractEmbedMetas } from './extractEmbedMeta';
|
|
11
11
|
export type { TransformOptions, DynamicComponents } from './plugins/types';
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import partition from 'lodash/partition';
|
|
10
10
|
import { domToReact, attributesToProps, Element } from 'html-react-parser';
|
|
11
|
-
import { FileListV2, RelatedArticleListV2, Grid, GridType } from '@ndla/ui';
|
|
11
|
+
import { FileListV2, RelatedArticleListV2, Grid, GridType, GridParallaxItem } from '@ndla/ui';
|
|
12
12
|
import { PluginType } from './types';
|
|
13
13
|
|
|
14
14
|
export const divPlugin: PluginType = (node, opts) => {
|
|
@@ -48,6 +48,8 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
48
48
|
{domToReact(node.children, opts)}
|
|
49
49
|
</Grid>
|
|
50
50
|
);
|
|
51
|
+
} else if (node.attribs['data-parallax-cell'] === 'true' && node.children.length) {
|
|
52
|
+
return <GridParallaxItem>{domToReact(node.children, opts)}</GridParallaxItem>;
|
|
51
53
|
}
|
|
52
54
|
return null;
|
|
53
55
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { LinkBlock } from '@ndla/ui';
|
|
10
|
+
import { attributesToProps } from 'html-react-parser';
|
|
11
|
+
import { LinkBlockMetaData } from '@ndla/types-embed';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const imageEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as LinkBlockMetaData;
|
|
17
|
+
|
|
18
|
+
return <LinkBlock {...data.embedData} />;
|
|
19
|
+
};
|
package/src/plugins/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { asidePlugin } from './asidePlugin';
|
|
|
20
20
|
import { ulPlugin } from './ulPlugin';
|
|
21
21
|
import { ddPlugin } from './ddPlugin';
|
|
22
22
|
import { dtPlugin } from './dtPlugin';
|
|
23
|
+
import { navPlugin } from './navPlugin';
|
|
23
24
|
|
|
24
25
|
export const basePlugins: Record<string, PluginType> = {
|
|
25
26
|
h2: copyParagraphPlugin,
|
|
@@ -34,6 +35,7 @@ export const basePlugins: Record<string, PluginType> = {
|
|
|
34
35
|
ul: ulPlugin,
|
|
35
36
|
dd: ddPlugin,
|
|
36
37
|
dt: dtPlugin,
|
|
38
|
+
nav: navPlugin,
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
export const oembedPlugins: Record<string, PluginType> = {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
10
|
+
import { LinkBlockSection } from '@ndla/ui';
|
|
11
|
+
import { PluginType } from './types';
|
|
12
|
+
|
|
13
|
+
export const navPlugin: PluginType = (node, opts) => {
|
|
14
|
+
if (node.attribs['data-type'] === 'link-block') {
|
|
15
|
+
const props = attributesToProps(node.attribs);
|
|
16
|
+
return <LinkBlockSection {...props}>{domToReact(node.children, opts)}</LinkBlockSection>;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|