@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,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 CodeEmbedPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CodeEmbedPlugin = void 0;
7
+ var _htmlReactParser = require("html-react-parser");
8
+ var _code = require("@ndla/code");
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 CodeEmbedPlugin = function CodeEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_code.CodeEmbed, {
22
+ embed: data
23
+ });
24
+ };
25
+ exports.CodeEmbedPlugin = CodeEmbedPlugin;
@@ -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 ConceptEmbedPlugin: PluginType;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ConceptEmbedPlugin = 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 ConceptEmbedPlugin = function ConceptEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.ConceptEmbed, {
22
+ embed: data,
23
+ fullWidth: true
24
+ });
25
+ };
26
+ exports.ConceptEmbedPlugin = ConceptEmbedPlugin;
@@ -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 ConceptListEmbedPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ConceptListEmbedPlugin = 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 ConceptListEmbedPlugin = function ConceptListEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.ConceptListEmbed, {
22
+ embed: data
23
+ });
24
+ };
25
+ exports.ConceptListEmbedPlugin = ConceptListEmbedPlugin;
@@ -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 ContentLinkEmbedPlugin: PluginType;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ContentLinkEmbedPlugin = 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 ContentLinkEmbedPlugin = function ContentLinkEmbedPlugin(element, _, _ref) {
19
+ var isOembed = _ref.isOembed;
20
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
21
+ var data = JSON.parse(props['data-json']);
22
+ return (0, _jsxRuntime.jsx)(_ui.ContentLinkEmbed, {
23
+ embed: data,
24
+ isOembed: isOembed
25
+ });
26
+ };
27
+ exports.ContentLinkEmbedPlugin = ContentLinkEmbedPlugin;
@@ -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 ExternalEmbedPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ExternalEmbedPlugin = 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 ExternalEmbedPlugin = function ExternalEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.ExternalEmbed, {
22
+ embed: data
23
+ });
24
+ };
25
+ exports.ExternalEmbedPlugin = ExternalEmbedPlugin;
@@ -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 FileEmbedPlugin: PluginType;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FileEmbedPlugin = 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 FileEmbedPlugin = function FileEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ var _data$embedData = data.embedData,
22
+ type = _data$embedData.type,
23
+ title = _data$embedData.title,
24
+ url = _data$embedData.url;
25
+ if (type === 'pdf') {
26
+ return (0, _jsxRuntime.jsx)(_ui.PdfFile, {
27
+ title: title,
28
+ url: url
29
+ });
30
+ } else {
31
+ return (0, _jsxRuntime.jsx)(_ui.FileV2, {
32
+ id: "file-".concat(data.seq),
33
+ url: url,
34
+ title: title,
35
+ fileExists: data.status === 'success' ? !!data.data.exists : false,
36
+ fileType: type
37
+ });
38
+ }
39
+ };
40
+ exports.FileEmbedPlugin = FileEmbedPlugin;
@@ -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 FootnoteEmbedPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FootnoteEmbedPlugin = 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 FootnoteEmbedPlugin = function FootnoteEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.FootnoteEmbed, {
22
+ embed: data
23
+ });
24
+ };
25
+ exports.FootnoteEmbedPlugin = FootnoteEmbedPlugin;
@@ -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 H5pEmbedPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.H5pEmbedPlugin = 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 H5pEmbedPlugin = function H5pEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.H5pEmbed, {
22
+ embed: data
23
+ });
24
+ };
25
+ exports.H5pEmbedPlugin = H5pEmbedPlugin;
@@ -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 IframeEmbedPlugin: PluginType;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.IframeEmbedPlugin = 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 IframeEmbedPlugin = function IframeEmbedPlugin(element) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.IframeEmbed, {
22
+ embed: data
23
+ });
24
+ };
25
+ exports.IframeEmbedPlugin = IframeEmbedPlugin;
@@ -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
+ /**
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 ImageEmbedPlugin = function ImageEmbedPlugin(element, _, opts) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.ImageEmbed, {
22
+ embed: data,
23
+ articlePath: opts.path,
24
+ previewAlt: opts.previewAlt
25
+ });
26
+ };
27
+ exports.ImageEmbedPlugin = ImageEmbedPlugin;
@@ -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 RelatedContentEmbedPlugin: PluginType;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RelatedContentEmbedPlugin = 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 RelatedContentEmbedPlugin = function RelatedContentEmbedPlugin(element, _, opts) {
19
+ var props = (0, _htmlReactParser.attributesToProps)(element.attribs);
20
+ var data = JSON.parse(props['data-json']);
21
+ return (0, _jsxRuntime.jsx)(_ui.RelatedContentEmbed, {
22
+ embed: data,
23
+ subject: opts.subject,
24
+ ndlaFrontendDomain: opts.frontendDomain
25
+ });
26
+ };
27
+ exports.RelatedContentEmbedPlugin = RelatedContentEmbedPlugin;
@@ -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 embedPlugins: Record<string, PluginType>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.embedPlugins = void 0;
7
+ var _AudioEmbedPlugin = require("./AudioEmbedPlugin");
8
+ var _ExternalEmbedPlugin = require("./ExternalEmbedPlugin");
9
+ var _H5pEmbedPlugin = require("./H5pEmbedPlugin");
10
+ var _IframeEmbedPlugin = require("./IframeEmbedPlugin");
11
+ var _ImageEmbedPlugin = require("./ImageEmbedPlugin");
12
+ var _FootnoteEmbedPlugin = require("./FootnoteEmbedPlugin");
13
+ var _BrightcoveEmbedPlugin = require("./BrightcoveEmbedPlugin");
14
+ var _RelatedContentEmbedPlugin = require("./RelatedContentEmbedPlugin");
15
+ var _ContentLinkEmbedPlugin = require("./ContentLinkEmbedPlugin");
16
+ var _ConceptEmbedPlugin = require("./ConceptEmbedPlugin");
17
+ var _ConceptListEmbedPlugin = require("./ConceptListEmbedPlugin");
18
+ var _FileEmbedPlugin = require("./FileEmbedPlugin");
19
+ var _CodeEmbedPlugin = require("./CodeEmbedPlugin");
20
+ /**
21
+ * Copyright (c) 2023-present, NDLA.
22
+ *
23
+ * This source code is licensed under the GPLv3 license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ *
26
+ */
27
+
28
+ var embedPlugins = {
29
+ image: _ImageEmbedPlugin.ImageEmbedPlugin,
30
+ audio: _AudioEmbedPlugin.AudioEmbedPlugin,
31
+ h5p: _H5pEmbedPlugin.H5pEmbedPlugin,
32
+ 'code-block': _CodeEmbedPlugin.CodeEmbedPlugin,
33
+ external: _ExternalEmbedPlugin.ExternalEmbedPlugin,
34
+ iframe: _IframeEmbedPlugin.IframeEmbedPlugin,
35
+ footnote: _FootnoteEmbedPlugin.FootnoteEmbedPlugin,
36
+ brightcove: _BrightcoveEmbedPlugin.BrightcoveEmbedPlugin,
37
+ 'related-content': _RelatedContentEmbedPlugin.RelatedContentEmbedPlugin,
38
+ 'content-link': _ContentLinkEmbedPlugin.ContentLinkEmbedPlugin,
39
+ concept: _ConceptEmbedPlugin.ConceptEmbedPlugin,
40
+ 'concept-list': _ConceptListEmbedPlugin.ConceptListEmbedPlugin,
41
+ file: _FileEmbedPlugin.FileEmbedPlugin
42
+ };
43
+ exports.embedPlugins = embedPlugins;
@@ -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 { PluginType } from './types';
9
+ export declare const basePlugins: Record<string, PluginType>;
10
+ export declare const oembedPlugins: Record<string, PluginType>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.oembedPlugins = exports.basePlugins = void 0;
7
+ var _CopyParagraphPlugin = require("./CopyParagraphPlugin");
8
+ var _OLPlugin = require("./OLPlugin");
9
+ var _ParagraphPlugin = require("./ParagraphPlugin");
10
+ var _SpanPlugin = require("./SpanPlugin");
11
+ var _H3Plugin = require("./H3Plugin");
12
+ var _MathPlugin = require("./MathPlugin");
13
+ var _AnchorPlugin = require("./oembed/AnchorPlugin");
14
+ var _DivPlugin = require("./DivPlugin");
15
+ var _TablePlugin = require("./TablePlugin");
16
+ var _AsidePlugin = require("./AsidePlugin");
17
+ 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; }
18
+ 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; }
19
+ 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; }
20
+ var basePlugins = {
21
+ h2: _CopyParagraphPlugin.CopyParagraphPlugin,
22
+ h3: _H3Plugin.H3Plugin,
23
+ ol: _OLPlugin.OLPlugin,
24
+ p: _ParagraphPlugin.ParagraphPlugin,
25
+ span: _SpanPlugin.SpanPlugin,
26
+ math: _MathPlugin.MathPlugin,
27
+ div: _DivPlugin.DivPlugin,
28
+ table: _TablePlugin.TablePlugin,
29
+ aside: _AsidePlugin.AsidePlugin
30
+ };
31
+ exports.basePlugins = basePlugins;
32
+ var oembedPlugins = _objectSpread(_objectSpread({}, basePlugins), {}, {
33
+ a: _AnchorPlugin.AnchorPlugin
34
+ });
35
+ exports.oembedPlugins = oembedPlugins;
@@ -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 AnchorPlugin: PluginType;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AnchorPlugin = 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 AnchorPlugin = function AnchorPlugin(node, options) {
13
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
14
+ return (0, _jsxRuntime.jsx)("a", _objectSpread(_objectSpread({}, props), {}, {
15
+ target: "_blank",
16
+ children: (0, _htmlReactParser.domToReact)(node.children, options)
17
+ }));
18
+ };
19
+ exports.AnchorPlugin = AnchorPlugin;
@@ -0,0 +1,17 @@
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
+ /// <reference types="react" />
9
+ import { Element, HTMLReactParserOptions } from 'html-react-parser';
10
+ export interface TransformOptions {
11
+ isOembed?: boolean;
12
+ subject?: string;
13
+ path?: string;
14
+ previewAlt?: boolean;
15
+ frontendDomain?: string;
16
+ }
17
+ export type PluginType = (element: Element, options: HTMLReactParserOptions, metaData: TransformOptions) => JSX.Element | undefined | null;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,11 @@
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
+ /// <reference types="react" />
9
+ import { TransformOptions } from './plugins/types';
10
+ declare const transform: (content: string, opts: TransformOptions) => string | JSX.Element | JSX.Element[];
11
+ export default transform;
@@ -0,0 +1,47 @@
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
+ var _ui = require("@ndla/ui");
9
+ var _plugins = require("./plugins");
10
+ var _embed = require("./plugins/embed");
11
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+ /**
14
+ * Copyright (c) 2023-present, NDLA.
15
+ *
16
+ * This source code is licensed under the GPLv3 license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+
21
+ var transform = function transform(content, opts) {
22
+ var plugins = opts !== null && opts !== void 0 && opts.isOembed ? _plugins.oembedPlugins : _plugins.basePlugins;
23
+ var options = {
24
+ replace: function replace(node) {
25
+ if (!('attribs' in node)) {
26
+ return;
27
+ }
28
+ if (plugins[node.name]) {
29
+ return plugins[node.name](node, options, opts);
30
+ }
31
+ if (node.name === 'ndlaembed') {
32
+ if (_embed.embedPlugins[node.attribs['data-resource']]) {
33
+ return _embed.embedPlugins[node.attribs['data-resource']](node, options, opts);
34
+ } else {
35
+ var embed = JSON.parse(node.attribs['data-json']);
36
+ return (0, _jsxRuntime.jsx)(_ui.UnknownEmbed, {
37
+ embed: embed
38
+ });
39
+ }
40
+ }
41
+ }
42
+ };
43
+ var replaced = (0, _htmlReactParser["default"])(content, options);
44
+ return replaced;
45
+ };
46
+ var _default = transform;
47
+ exports["default"] = _default;