@ndla/article-converter 1.0.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.
Files changed (122) hide show
  1. package/LICENSE +674 -0
  2. package/es/extractEmbedMeta.js +17 -0
  3. package/es/index.js +10 -0
  4. package/es/plugins/AsidePlugin.js +25 -0
  5. package/es/plugins/CopyParagraphPlugin.js +17 -0
  6. package/es/plugins/DivPlugin.js +48 -0
  7. package/es/plugins/H3Plugin.js +23 -0
  8. package/es/plugins/MathPlugin.js +18 -0
  9. package/es/plugins/OLPlugin.js +28 -0
  10. package/es/plugins/ParagraphPlugin.js +28 -0
  11. package/es/plugins/SpanPlugin.js +25 -0
  12. package/es/plugins/TablePlugin.js +20 -0
  13. package/es/plugins/ULPlugin.js +28 -0
  14. package/es/plugins/embed/AudioEmbedPlugin.js +19 -0
  15. package/es/plugins/embed/BrightcoveEmbedPlugin.js +18 -0
  16. package/es/plugins/embed/CodeEmbedPlugin.js +18 -0
  17. package/es/plugins/embed/ConceptEmbedPlugin.js +19 -0
  18. package/es/plugins/embed/ConceptListEmbedPlugin.js +18 -0
  19. package/es/plugins/embed/ContentLinkEmbedPlugin.js +20 -0
  20. package/es/plugins/embed/ExternalEmbedPlugin.js +18 -0
  21. package/es/plugins/embed/FileEmbedPlugin.js +33 -0
  22. package/es/plugins/embed/FootnoteEmbedPlugin.js +18 -0
  23. package/es/plugins/embed/H5pEmbedPlugin.js +18 -0
  24. package/es/plugins/embed/IframeEmbedPlugin.js +18 -0
  25. package/es/plugins/embed/ImageEmbedPlugin.js +20 -0
  26. package/es/plugins/embed/RelatedContentEmbedPlugin.js +20 -0
  27. package/es/plugins/embed/index.js +36 -0
  28. package/es/plugins/index.js +35 -0
  29. package/es/plugins/oembed/AnchorPlugin.js +20 -0
  30. package/es/plugins/types.js +1 -0
  31. package/es/transform.js +39 -0
  32. package/lib/extractEmbedMeta.d.ts +10 -0
  33. package/lib/extractEmbedMeta.js +25 -0
  34. package/lib/index.d.ts +10 -0
  35. package/lib/index.js +20 -0
  36. package/lib/plugins/AsidePlugin.d.ts +9 -0
  37. package/lib/plugins/AsidePlugin.js +32 -0
  38. package/lib/plugins/CopyParagraphPlugin.d.ts +9 -0
  39. package/lib/plugins/CopyParagraphPlugin.js +24 -0
  40. package/lib/plugins/DivPlugin.d.ts +9 -0
  41. package/lib/plugins/DivPlugin.js +46 -0
  42. package/lib/plugins/H3Plugin.d.ts +9 -0
  43. package/lib/plugins/H3Plugin.js +22 -0
  44. package/lib/plugins/MathPlugin.d.ts +9 -0
  45. package/lib/plugins/MathPlugin.js +25 -0
  46. package/lib/plugins/OLPlugin.d.ts +9 -0
  47. package/lib/plugins/OLPlugin.js +27 -0
  48. package/lib/plugins/ParagraphPlugin.d.ts +9 -0
  49. package/lib/plugins/ParagraphPlugin.js +27 -0
  50. package/lib/plugins/SpanPlugin.d.ts +9 -0
  51. package/lib/plugins/SpanPlugin.js +24 -0
  52. package/lib/plugins/TablePlugin.d.ts +9 -0
  53. package/lib/plugins/TablePlugin.js +19 -0
  54. package/lib/plugins/ULPlugin.d.ts +9 -0
  55. package/lib/plugins/ULPlugin.js +27 -0
  56. package/lib/plugins/embed/AudioEmbedPlugin.d.ts +9 -0
  57. package/lib/plugins/embed/AudioEmbedPlugin.js +26 -0
  58. package/lib/plugins/embed/BrightcoveEmbedPlugin.d.ts +9 -0
  59. package/lib/plugins/embed/BrightcoveEmbedPlugin.js +25 -0
  60. package/lib/plugins/embed/CodeEmbedPlugin.d.ts +9 -0
  61. package/lib/plugins/embed/CodeEmbedPlugin.js +25 -0
  62. package/lib/plugins/embed/ConceptEmbedPlugin.d.ts +9 -0
  63. package/lib/plugins/embed/ConceptEmbedPlugin.js +26 -0
  64. package/lib/plugins/embed/ConceptListEmbedPlugin.d.ts +9 -0
  65. package/lib/plugins/embed/ConceptListEmbedPlugin.js +25 -0
  66. package/lib/plugins/embed/ContentLinkEmbedPlugin.d.ts +9 -0
  67. package/lib/plugins/embed/ContentLinkEmbedPlugin.js +27 -0
  68. package/lib/plugins/embed/ExternalEmbedPlugin.d.ts +9 -0
  69. package/lib/plugins/embed/ExternalEmbedPlugin.js +25 -0
  70. package/lib/plugins/embed/FileEmbedPlugin.d.ts +9 -0
  71. package/lib/plugins/embed/FileEmbedPlugin.js +40 -0
  72. package/lib/plugins/embed/FootnoteEmbedPlugin.d.ts +9 -0
  73. package/lib/plugins/embed/FootnoteEmbedPlugin.js +25 -0
  74. package/lib/plugins/embed/H5pEmbedPlugin.d.ts +9 -0
  75. package/lib/plugins/embed/H5pEmbedPlugin.js +25 -0
  76. package/lib/plugins/embed/IframeEmbedPlugin.d.ts +9 -0
  77. package/lib/plugins/embed/IframeEmbedPlugin.js +25 -0
  78. package/lib/plugins/embed/ImageEmbedPlugin.d.ts +9 -0
  79. package/lib/plugins/embed/ImageEmbedPlugin.js +27 -0
  80. package/lib/plugins/embed/RelatedContentEmbedPlugin.d.ts +9 -0
  81. package/lib/plugins/embed/RelatedContentEmbedPlugin.js +27 -0
  82. package/lib/plugins/embed/index.d.ts +9 -0
  83. package/lib/plugins/embed/index.js +43 -0
  84. package/lib/plugins/index.d.ts +10 -0
  85. package/lib/plugins/index.js +35 -0
  86. package/lib/plugins/oembed/AnchorPlugin.d.ts +9 -0
  87. package/lib/plugins/oembed/AnchorPlugin.js +19 -0
  88. package/lib/plugins/types.d.ts +17 -0
  89. package/lib/plugins/types.js +5 -0
  90. package/lib/transform.d.ts +11 -0
  91. package/lib/transform.js +47 -0
  92. package/package.json +48 -0
  93. package/src/extractEmbedMeta.ts +21 -0
  94. package/src/index.ts +11 -0
  95. package/src/plugins/AsidePlugin.tsx +24 -0
  96. package/src/plugins/CopyParagraphPlugin.tsx +18 -0
  97. package/src/plugins/DivPlugin.tsx +40 -0
  98. package/src/plugins/H3Plugin.tsx +19 -0
  99. package/src/plugins/MathPlugin.tsx +14 -0
  100. package/src/plugins/OLPlugin.tsx +23 -0
  101. package/src/plugins/ParagraphPlugin.tsx +23 -0
  102. package/src/plugins/SpanPlugin.tsx +22 -0
  103. package/src/plugins/TablePlugin.tsx +15 -0
  104. package/src/plugins/ULPlugin.tsx +23 -0
  105. package/src/plugins/embed/AudioEmbedPlugin.tsx +18 -0
  106. package/src/plugins/embed/BrightcoveEmbedPlugin.tsx +18 -0
  107. package/src/plugins/embed/CodeEmbedPlugin.tsx +18 -0
  108. package/src/plugins/embed/ConceptEmbedPlugin.tsx +18 -0
  109. package/src/plugins/embed/ConceptListEmbedPlugin.tsx +18 -0
  110. package/src/plugins/embed/ContentLinkEmbedPlugin.tsx +18 -0
  111. package/src/plugins/embed/ExternalEmbedPlugin.tsx +18 -0
  112. package/src/plugins/embed/FileEmbedPlugin.tsx +31 -0
  113. package/src/plugins/embed/FootnoteEmbedPlugin.tsx +18 -0
  114. package/src/plugins/embed/H5pEmbedPlugin.tsx +18 -0
  115. package/src/plugins/embed/IframeEmbedPlugin.tsx +18 -0
  116. package/src/plugins/embed/ImageEmbedPlugin.tsx +18 -0
  117. package/src/plugins/embed/RelatedContentEmbedPlugin.tsx +18 -0
  118. package/src/plugins/embed/index.ts +38 -0
  119. package/src/plugins/index.ts +36 -0
  120. package/src/plugins/oembed/AnchorPlugin.tsx +18 -0
  121. package/src/plugins/types.ts +23 -0
  122. package/src/transform.tsx +41 -0
@@ -0,0 +1,35 @@
1
+ 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; }
2
+ 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; }
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ /**
5
+ * Copyright (c) 2023-present, NDLA.
6
+ *
7
+ * This source code is licensed under the GPLv3 license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ *
10
+ */
11
+
12
+ import { CopyParagraphPlugin } from './CopyParagraphPlugin';
13
+ import { OLPlugin } from './OLPlugin';
14
+ import { ParagraphPlugin } from './ParagraphPlugin';
15
+ import { SpanPlugin } from './SpanPlugin';
16
+ import { H3Plugin } from './H3Plugin';
17
+ import { MathPlugin } from './MathPlugin';
18
+ import { AnchorPlugin } from './oembed/AnchorPlugin';
19
+ import { DivPlugin } from './DivPlugin';
20
+ import { TablePlugin } from './TablePlugin';
21
+ import { AsidePlugin } from './AsidePlugin';
22
+ export var basePlugins = {
23
+ h2: CopyParagraphPlugin,
24
+ h3: H3Plugin,
25
+ ol: OLPlugin,
26
+ p: ParagraphPlugin,
27
+ span: SpanPlugin,
28
+ math: MathPlugin,
29
+ div: DivPlugin,
30
+ table: TablePlugin,
31
+ aside: AsidePlugin
32
+ };
33
+ export var oembedPlugins = _objectSpread(_objectSpread({}, basePlugins), {}, {
34
+ a: AnchorPlugin
35
+ });
@@ -0,0 +1,20 @@
1
+ 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; }
2
+ 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; }
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ /**
5
+ * Copyright (c) 2023-present, NDLA.
6
+ *
7
+ * This source code is licensed under the GPLv3 license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ *
10
+ */
11
+
12
+ import { attributesToProps, domToReact } from 'html-react-parser';
13
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
14
+ export var AnchorPlugin = function AnchorPlugin(node, options) {
15
+ var props = attributesToProps(node.attribs);
16
+ return _jsx("a", _objectSpread(_objectSpread({}, props), {}, {
17
+ target: "_blank",
18
+ children: domToReact(node.children, options)
19
+ }));
20
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
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 parse from 'html-react-parser';
10
+ import { UnknownEmbed } from '@ndla/ui';
11
+ import { basePlugins, oembedPlugins } from './plugins';
12
+ import { embedPlugins } from './plugins/embed';
13
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
14
+ var transform = function transform(content, opts) {
15
+ var plugins = opts !== null && opts !== void 0 && opts.isOembed ? oembedPlugins : basePlugins;
16
+ var options = {
17
+ replace: function replace(node) {
18
+ if (!('attribs' in node)) {
19
+ return;
20
+ }
21
+ if (plugins[node.name]) {
22
+ return plugins[node.name](node, options, opts);
23
+ }
24
+ if (node.name === 'ndlaembed') {
25
+ if (embedPlugins[node.attribs['data-resource']]) {
26
+ return embedPlugins[node.attribs['data-resource']](node, options, opts);
27
+ } else {
28
+ var embed = JSON.parse(node.attribs['data-json']);
29
+ return _jsx(UnknownEmbed, {
30
+ embed: embed
31
+ });
32
+ }
33
+ }
34
+ }
35
+ };
36
+ var replaced = parse(content, options);
37
+ return replaced;
38
+ };
39
+ export default transform;
@@ -0,0 +1,10 @@
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 { EmbedMetaData } from '@ndla/types-embed';
9
+ declare const extractEmbedMeta: (embed: string) => EmbedMetaData | undefined;
10
+ export default extractEmbedMeta;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _htmlReactParser = _interopRequireDefault(require("html-react-parser"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ /**
10
+ * Copyright (c) 2023-present, NDLA.
11
+ *
12
+ * This source code is licensed under the GPLv3 license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
15
+ */
16
+
17
+ var extractEmbedMeta = function extractEmbedMeta(embed) {
18
+ var node = (0, _htmlReactParser["default"])(embed);
19
+ if (typeof node === 'string' || Array.isArray(node) || node.type !== 'ndlaembed' || !node.props['data-json']) {
20
+ return;
21
+ }
22
+ return JSON.parse(node.props['data-json']);
23
+ };
24
+ var _default = extractEmbedMeta;
25
+ exports["default"] = _default;
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
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
+ export { default as transform } from './transform';
9
+ export { default as extractEmbedMeta } from './extractEmbedMeta';
10
+ export type { TransformOptions } from './plugins/types';
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "extractEmbedMeta", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _extractEmbedMeta["default"];
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "transform", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _transform["default"];
16
+ }
17
+ });
18
+ var _transform = _interopRequireDefault(require("./transform"));
19
+ var _extractEmbedMeta = _interopRequireDefault(require("./extractEmbedMeta"));
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -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 AsidePlugin: PluginType;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AsidePlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _ui = require("@ndla/ui");
9
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
+ /**
11
+ * Copyright (c) 2023-present, NDLA.
12
+ *
13
+ * This source code is licensed under the GPLv3 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ */
17
+
18
+ var AsidePlugin = function AsidePlugin(node, opts) {
19
+ if (node.attribs['data-type'] === 'factAside') {
20
+ return (0, _jsxRuntime.jsx)(_ui.FactBoxV2, {
21
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
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
+ }
30
+ return null;
31
+ };
32
+ exports.AsidePlugin = AsidePlugin;
@@ -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 CopyParagraphPlugin: PluginType;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CopyParagraphPlugin = void 0;
7
+ var _ui = require("@ndla/ui");
8
+ var _htmlReactParser = require("html-react-parser");
9
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
+ /**
11
+ * Copyright (c) 2023-present, NDLA.
12
+ *
13
+ * This source code is licensed under the GPLv3 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ */
17
+
18
+ var CopyParagraphPlugin = function CopyParagraphPlugin(node, opts) {
19
+ return (0, _jsxRuntime.jsx)(_ui.CopyParagraphButtonV2, {
20
+ copyText: node.attribs['data-text'],
21
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
22
+ });
23
+ };
24
+ exports.CopyParagraphPlugin = CopyParagraphPlugin;
@@ -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 DivPlugin: PluginType;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DivPlugin = void 0;
7
+ var _partition3 = _interopRequireDefault(require("lodash/partition"));
8
+ var _htmlReactParser = require("html-react-parser");
9
+ var _ui = require("@ndla/ui");
10
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
16
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
+ 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; }
19
+ 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; }
20
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+ var DivPlugin = function DivPlugin(node, opts) {
22
+ if (node.attribs['data-type'] === 'related-content' && node.children.length) {
23
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
24
+ return (0, _jsxRuntime.jsx)(_ui.RelatedArticleListV2, _objectSpread(_objectSpread({}, props), {}, {
25
+ headingLevel: "h3",
26
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
27
+ }));
28
+ } else if (node.attribs['data-type'] === 'file' && node.childNodes.length) {
29
+ var elements = node.childNodes.filter(function (c) {
30
+ return c.type === 'tag' && c.name === 'ndlaembed' && c.attribs['data-resource'] === 'file';
31
+ });
32
+ var _partition = (0, _partition3["default"])(elements, function (el) {
33
+ return el.attribs['data-type'] === 'pdf' && el.attribs['data-display'] === 'block';
34
+ }),
35
+ _partition2 = _slicedToArray(_partition, 2),
36
+ pdfs = _partition2[0],
37
+ files = _partition2[1];
38
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
39
+ children: [files.length ? (0, _jsxRuntime.jsx)(_ui.FileListV2, {
40
+ children: (0, _htmlReactParser.domToReact)(files, opts)
41
+ }) : undefined, (0, _htmlReactParser.domToReact)(pdfs, opts)]
42
+ });
43
+ }
44
+ return null;
45
+ };
46
+ exports.DivPlugin = DivPlugin;
@@ -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 H3Plugin: PluginType;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.H3Plugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
+ 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; }
10
+ 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; }
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ var H3Plugin = function H3Plugin(node, opts) {
13
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
14
+ return (
15
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
16
+ (0, _jsxRuntime.jsx)("h3", _objectSpread(_objectSpread({}, props), {}, {
17
+ tabIndex: 0,
18
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
19
+ }))
20
+ );
21
+ };
22
+ exports.H3Plugin = H3Plugin;
@@ -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 MathPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MathPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
+ /**
10
+ * Copyright (c) 2023-present, NDLA.
11
+ *
12
+ * This source code is licensed under the GPLv3 license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
15
+ */
16
+
17
+ var MathPlugin = function MathPlugin(node) {
18
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
19
+ return (0, _jsxRuntime.jsx)("span", {
20
+ dangerouslySetInnerHTML: {
21
+ __html: "<math display=\"block\">".concat(props['data-math'], "</math>")
22
+ }
23
+ });
24
+ };
25
+ exports.MathPlugin = MathPlugin;
@@ -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 OLPlugin: PluginType;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OLPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
+ 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; }
10
+ 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; }
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ var OLPlugin = function OLPlugin(node, opts) {
13
+ var _node$attribs$class;
14
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
15
+ var letterClass = node.attribs['data-type'] === 'letters' ? 'ol-list--roman' : false;
16
+ var num = node.attribs['start'];
17
+ var numClass = num ? "ol-reset-".concat(num) : false;
18
+ var classes = [(_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : false, letterClass, numClass].filter(function (c) {
19
+ return !!c;
20
+ }).join(' ');
21
+ return (0, _jsxRuntime.jsx)("ol", _objectSpread(_objectSpread({}, props), {}, {
22
+ "data-type": undefined,
23
+ className: classes.length ? classes : undefined,
24
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
25
+ }));
26
+ };
27
+ exports.OLPlugin = OLPlugin;
@@ -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 ParagraphPlugin: PluginType;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ParagraphPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
+ 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; }
10
+ 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; }
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ var ParagraphPlugin = function ParagraphPlugin(node, opts) {
13
+ if (node.attribs['data-align'] === 'center') {
14
+ var _node$attribs$class;
15
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
16
+ var classes = [(_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', 'u-text-center'].filter(function (c) {
17
+ return !!c;
18
+ }).join(' ');
19
+ return (0, _jsxRuntime.jsx)("p", _objectSpread(_objectSpread({}, props), {}, {
20
+ "data-align": undefined,
21
+ className: classes,
22
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
23
+ }));
24
+ }
25
+ return null;
26
+ };
27
+ exports.ParagraphPlugin = ParagraphPlugin;
@@ -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 SpanPlugin: PluginType;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SpanPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
+ 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; }
10
+ 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; }
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ var SpanPlugin = function SpanPlugin(node, opts) {
13
+ if (node.attribs['data-size'] === 'large') {
14
+ var _node$attribs$class;
15
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
16
+ return (0, _jsxRuntime.jsx)("span", _objectSpread(_objectSpread({}, props), {}, {
17
+ "data-size": undefined,
18
+ className: "".concat((_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', " u-large-body-text"),
19
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
20
+ }));
21
+ }
22
+ return null;
23
+ };
24
+ exports.SpanPlugin = SpanPlugin;
@@ -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 TablePlugin: PluginType;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TablePlugin = 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 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; }
11
+ 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; }
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ var TablePlugin = function TablePlugin(node, opts) {
14
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
15
+ return (0, _jsxRuntime.jsx)(_ui.Table, _objectSpread(_objectSpread({}, props), {}, {
16
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
17
+ }));
18
+ };
19
+ exports.TablePlugin = TablePlugin;
@@ -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 OLPlugin: PluginType;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OLPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
+ 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; }
10
+ 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; }
11
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ var OLPlugin = function OLPlugin(node, opts) {
13
+ if (node.attribs['data-type'] === 'two-column') {
14
+ var _node$attribs$class;
15
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
16
+ var classes = [(_node$attribs$class = node.attribs["class"]) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', 'o-list--two-columns'].filter(function (c) {
17
+ return !!c;
18
+ }).join(' ');
19
+ return (0, _jsxRuntime.jsx)("ul", _objectSpread(_objectSpread({}, props), {}, {
20
+ "data-type": undefined,
21
+ className: classes,
22
+ children: (0, _htmlReactParser.domToReact)(node.children, opts)
23
+ }));
24
+ }
25
+ return null;
26
+ };
27
+ exports.OLPlugin = OLPlugin;
@@ -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 AudioEmbedPlugin: PluginType;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AudioEmbedPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _ui = require("@ndla/ui");
9
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
+ /**
11
+ * Copyright (c) 2023-present, NDLA.
12
+ *
13
+ * This source code is licensed under the GPLv3 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ */
17
+
18
+ var AudioEmbedPlugin = function AudioEmbedPlugin(element, _, opts) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.AudioEmbed, {
22
+ embed: data,
23
+ articlePath: opts.path
24
+ });
25
+ };
26
+ exports.AudioEmbedPlugin = AudioEmbedPlugin;
@@ -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 BrightcoveEmbedPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BrightcoveEmbedPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _ui = require("@ndla/ui");
9
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
+ /**
11
+ * Copyright (c) 2023-present, NDLA.
12
+ *
13
+ * This source code is licensed under the GPLv3 license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ *
16
+ */
17
+
18
+ var BrightcoveEmbedPlugin = function BrightcoveEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.BrightcoveEmbed, {
22
+ embed: data
23
+ });
24
+ };
25
+ exports.BrightcoveEmbedPlugin = BrightcoveEmbedPlugin;