@ndla/article-converter 6.0.42 → 6.0.44
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 +8 -8
- package/es/index.js +2 -2
- package/es/plugins/anchorPlugin.js +3 -3
- package/es/plugins/asidePlugin.js +4 -4
- package/es/plugins/copyParagraphPlugin.js +4 -4
- package/es/plugins/ddPlugin.js +2 -2
- package/es/plugins/divPlugin.js +14 -14
- package/es/plugins/dtPlugin.js +2 -2
- package/es/plugins/embed/KeyFigureEmbedPlugin.js +5 -5
- package/es/plugins/embed/audioEmbedPlugin.js +3 -3
- package/es/plugins/embed/blogPostEmbedPlugin.js +5 -5
- package/es/plugins/embed/brightcoveEmbedPlugin.js +3 -3
- package/es/plugins/embed/campaignBlockPlugin.js +5 -5
- package/es/plugins/embed/codeEmbedPlugin.js +3 -3
- package/es/plugins/embed/conceptEmbedPlugin.js +3 -3
- package/es/plugins/embed/conceptListEmbedPlugin.js +3 -3
- package/es/plugins/embed/contactBlockEmbedPlugin.js +4 -4
- package/es/plugins/embed/contentLinkEmbedPlugin.js +3 -3
- package/es/plugins/embed/externalEmbedPlugin.js +3 -3
- package/es/plugins/embed/fileEmbedPlugin.js +5 -5
- package/es/plugins/embed/footnoteEmbedPlugin.js +3 -3
- package/es/plugins/embed/h5pEmbedPlugin.js +3 -3
- package/es/plugins/embed/iframeEmbedPlugin.js +3 -3
- package/es/plugins/embed/imageEmbedPlugin.js +4 -4
- package/es/plugins/embed/index.js +27 -27
- package/es/plugins/embed/linkBlockEmbedPlugin.js +3 -3
- package/es/plugins/embed/relatedContentEmbedPlugin.js +3 -3
- package/es/plugins/h3Plugin.js +1 -1
- package/es/plugins/index.js +15 -15
- package/es/plugins/mathPlugin.js +2 -2
- package/es/plugins/navPlugin.js +3 -3
- package/es/plugins/oembed/anchorPlugin.js +3 -3
- package/es/plugins/olPlugin.js +5 -5
- package/es/plugins/paragraphPlugin.js +3 -3
- package/es/plugins/spanPlugin.js +3 -3
- package/es/plugins/tablePlugin.js +2 -2
- package/es/plugins/ulPlugin.js +3 -3
- package/es/transform.js +9 -9
- package/lib/extractEmbedMeta.d.ts +1 -1
- package/lib/extractEmbedMeta.js +7 -7
- package/lib/index.d.ts +3 -3
- package/lib/plugins/anchorPlugin.d.ts +1 -1
- package/lib/plugins/asidePlugin.d.ts +1 -1
- package/lib/plugins/asidePlugin.js +2 -2
- package/lib/plugins/copyParagraphPlugin.d.ts +1 -1
- package/lib/plugins/copyParagraphPlugin.js +2 -2
- package/lib/plugins/ddPlugin.d.ts +1 -1
- package/lib/plugins/divPlugin.d.ts +1 -1
- package/lib/plugins/divPlugin.js +11 -11
- package/lib/plugins/dtPlugin.d.ts +1 -1
- package/lib/plugins/embed/KeyFigureEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/KeyFigureEmbedPlugin.js +3 -3
- package/lib/plugins/embed/audioEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/audioEmbedPlugin.js +1 -1
- package/lib/plugins/embed/blogPostEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/blogPostEmbedPlugin.js +3 -3
- package/lib/plugins/embed/brightcoveEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/brightcoveEmbedPlugin.js +1 -1
- package/lib/plugins/embed/campaignBlockPlugin.d.ts +1 -1
- package/lib/plugins/embed/campaignBlockPlugin.js +3 -3
- package/lib/plugins/embed/codeEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/codeEmbedPlugin.js +1 -1
- package/lib/plugins/embed/conceptEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/conceptEmbedPlugin.js +1 -1
- package/lib/plugins/embed/conceptListEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/conceptListEmbedPlugin.js +1 -1
- package/lib/plugins/embed/contactBlockEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/contactBlockEmbedPlugin.js +2 -2
- package/lib/plugins/embed/contentLinkEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/contentLinkEmbedPlugin.js +1 -1
- package/lib/plugins/embed/externalEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/externalEmbedPlugin.js +1 -1
- package/lib/plugins/embed/fileEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/fileEmbedPlugin.js +3 -3
- package/lib/plugins/embed/footnoteEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/footnoteEmbedPlugin.js +1 -1
- package/lib/plugins/embed/h5pEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/h5pEmbedPlugin.js +1 -1
- package/lib/plugins/embed/iframeEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/iframeEmbedPlugin.js +1 -1
- package/lib/plugins/embed/imageEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/imageEmbedPlugin.js +2 -2
- package/lib/plugins/embed/index.d.ts +1 -1
- package/lib/plugins/embed/index.js +9 -9
- package/lib/plugins/embed/linkBlockEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/linkBlockEmbedPlugin.js +1 -1
- package/lib/plugins/embed/relatedContentEmbedPlugin.d.ts +1 -1
- package/lib/plugins/embed/relatedContentEmbedPlugin.js +1 -1
- package/lib/plugins/h3Plugin.d.ts +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/lib/plugins/mathPlugin.d.ts +1 -1
- package/lib/plugins/mathPlugin.js +1 -1
- package/lib/plugins/navPlugin.d.ts +1 -1
- package/lib/plugins/navPlugin.js +1 -1
- package/lib/plugins/oembed/anchorPlugin.d.ts +1 -1
- package/lib/plugins/olPlugin.d.ts +1 -1
- package/lib/plugins/olPlugin.js +3 -3
- package/lib/plugins/paragraphPlugin.d.ts +1 -1
- package/lib/plugins/paragraphPlugin.js +2 -2
- package/lib/plugins/spanPlugin.d.ts +1 -1
- package/lib/plugins/spanPlugin.js +2 -2
- package/lib/plugins/tablePlugin.d.ts +1 -1
- package/lib/plugins/types.d.ts +2 -2
- package/lib/plugins/ulPlugin.d.ts +1 -1
- package/lib/plugins/ulPlugin.js +1 -1
- package/lib/transform.d.ts +1 -1
- package/lib/transform.js +5 -5
- package/package.json +5 -5
- package/src/extractEmbedMeta.ts +9 -9
- package/src/index.ts +3 -3
- package/src/plugins/anchorPlugin.tsx +4 -4
- package/src/plugins/asidePlugin.tsx +5 -5
- package/src/plugins/copyParagraphPlugin.tsx +5 -5
- package/src/plugins/ddPlugin.tsx +3 -3
- package/src/plugins/divPlugin.tsx +15 -15
- package/src/plugins/dtPlugin.tsx +3 -3
- package/src/plugins/embed/KeyFigureEmbedPlugin.tsx +7 -7
- package/src/plugins/embed/audioEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/blogPostEmbedPlugin.tsx +7 -7
- package/src/plugins/embed/brightcoveEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/campaignBlockPlugin.tsx +11 -8
- package/src/plugins/embed/codeEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/conceptEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/conceptListEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/contactBlockEmbedPlugin.tsx +6 -6
- package/src/plugins/embed/contentLinkEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/externalEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/fileEmbedPlugin.tsx +7 -7
- package/src/plugins/embed/footnoteEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/h5pEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/iframeEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/imageEmbedPlugin.tsx +6 -6
- package/src/plugins/embed/index.ts +28 -28
- package/src/plugins/embed/linkBlockEmbedPlugin.tsx +5 -5
- package/src/plugins/embed/relatedContentEmbedPlugin.tsx +5 -5
- package/src/plugins/h3Plugin.tsx +2 -2
- package/src/plugins/index.ts +16 -16
- package/src/plugins/mathPlugin.tsx +3 -3
- package/src/plugins/navPlugin.tsx +4 -4
- package/src/plugins/oembed/anchorPlugin.tsx +4 -4
- package/src/plugins/olPlugin.tsx +6 -6
- package/src/plugins/paragraphPlugin.tsx +4 -4
- package/src/plugins/spanPlugin.tsx +4 -4
- package/src/plugins/tablePlugin.tsx +3 -3
- package/src/plugins/types.ts +2 -2
- package/src/plugins/ulPlugin.tsx +5 -5
- package/src/transform.tsx +11 -11
|
@@ -20,7 +20,7 @@ const contentLinkEmbedPlugin = (element, _, _ref) => {
|
|
|
20
20
|
isOembed
|
|
21
21
|
} = _ref;
|
|
22
22
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
23
|
-
const data = JSON.parse(props[
|
|
23
|
+
const data = JSON.parse(props["data-json"]);
|
|
24
24
|
return (0, _jsxRuntime.jsx)(_ui.ContentLinkEmbed, {
|
|
25
25
|
embed: data,
|
|
26
26
|
isOembed: isOembed
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const externalEmbedPlugin = element => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.ExternalEmbed, {
|
|
22
22
|
embed: data
|
|
23
23
|
});
|
|
@@ -17,14 +17,14 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const fileEmbedPlugin = element => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
const {
|
|
22
22
|
type,
|
|
23
23
|
title,
|
|
24
24
|
url,
|
|
25
25
|
display
|
|
26
26
|
} = data.embedData;
|
|
27
|
-
if (type ===
|
|
27
|
+
if (type === "pdf" && display === "block") {
|
|
28
28
|
return (0, _jsxRuntime.jsx)(_ui.PdfFile, {
|
|
29
29
|
title: title,
|
|
30
30
|
url: url
|
|
@@ -33,7 +33,7 @@ const fileEmbedPlugin = element => {
|
|
|
33
33
|
return (0, _jsxRuntime.jsx)(_ui.File, {
|
|
34
34
|
url: url,
|
|
35
35
|
title: title,
|
|
36
|
-
fileExists: data.status ===
|
|
36
|
+
fileExists: data.status === "success" ? !!data.data.exists : false,
|
|
37
37
|
fileType: type
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const footnoteEmbedPlugin = element => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.FootnoteEmbed, {
|
|
22
22
|
embed: data
|
|
23
23
|
});
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const h5pEmbedPlugin = element => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.H5pEmbed, {
|
|
22
22
|
embed: data
|
|
23
23
|
});
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const iframeEmbedPlugin = element => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.IframeEmbed, {
|
|
22
22
|
embed: data
|
|
23
23
|
});
|
|
@@ -17,8 +17,8 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const imageEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
21
|
-
const inGrid = element.parentNode?.parentNode?.attribs?.[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
|
+
const inGrid = element.parentNode?.parentNode?.attribs?.["data-type"] === "grid";
|
|
22
22
|
return (0, _jsxRuntime.jsx)(_ui.ImageEmbed, {
|
|
23
23
|
inGrid: inGrid,
|
|
24
24
|
embed: data,
|
|
@@ -34,19 +34,19 @@ const embedPlugins = exports.embedPlugins = {
|
|
|
34
34
|
image: _imageEmbedPlugin.imageEmbedPlugin,
|
|
35
35
|
audio: _audioEmbedPlugin.audioEmbedPlugin,
|
|
36
36
|
h5p: _h5pEmbedPlugin.h5pEmbedPlugin,
|
|
37
|
-
|
|
37
|
+
"code-block": _codeEmbedPlugin.codeEmbedPlugin,
|
|
38
38
|
external: _externalEmbedPlugin.externalEmbedPlugin,
|
|
39
39
|
iframe: _iframeEmbedPlugin.iframeEmbedPlugin,
|
|
40
40
|
footnote: _footnoteEmbedPlugin.footnoteEmbedPlugin,
|
|
41
41
|
brightcove: _brightcoveEmbedPlugin.brightcoveEmbedPlugin,
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
"related-content": _relatedContentEmbedPlugin.relatedContentEmbedPlugin,
|
|
43
|
+
"content-link": _contentLinkEmbedPlugin.contentLinkEmbedPlugin,
|
|
44
44
|
concept: _conceptEmbedPlugin.conceptEmbedPlugin,
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
"concept-list": _conceptListEmbedPlugin.conceptListEmbedPlugin,
|
|
46
|
+
"blog-post": _blogPostEmbedPlugin.blogPostEmbedPlugin,
|
|
47
47
|
file: _fileEmbedPlugin.fileEmbedPlugin,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
"key-figure": _KeyFigureEmbedPlugin.keyFigureEmbedPlugin,
|
|
49
|
+
"contact-block": _contactBlockEmbedPlugin.contactBlockEmbedPlugin,
|
|
50
|
+
"campaign-block": _campaignBlockPlugin.campaignBlockPlugin,
|
|
51
|
+
"link-block": _linkBlockEmbedPlugin.linkBlockPlugin
|
|
52
52
|
};
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const linkBlockPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.LinkBlock, {
|
|
22
22
|
...data.embedData,
|
|
23
23
|
path: opts.path
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const relatedContentEmbedPlugin = (element, _, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
20
|
-
const data = JSON.parse(props[
|
|
20
|
+
const data = JSON.parse(props["data-json"]);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.RelatedContentEmbed, {
|
|
22
22
|
embed: data,
|
|
23
23
|
subject: opts.subject,
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { PluginType } from
|
|
8
|
+
import { PluginType } from "./types";
|
|
9
9
|
export declare const basePlugins: Record<string, PluginType>;
|
|
10
10
|
export declare const oembedPlugins: Record<string, PluginType>;
|
package/lib/plugins/navPlugin.js
CHANGED
|
@@ -16,7 +16,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const navPlugin = (node, opts) => {
|
|
19
|
-
if (node.attribs[
|
|
19
|
+
if (node.attribs["data-type"] === "link-block-list") {
|
|
20
20
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.LinkBlockSection, {
|
|
22
22
|
...props,
|
package/lib/plugins/olPlugin.js
CHANGED
|
@@ -17,10 +17,10 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const olPlugin = (node, converterOpts, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
-
const letterClass = node.attribs[
|
|
21
|
-
const num = node.attribs[
|
|
20
|
+
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
21
|
+
const num = node.attribs["start"];
|
|
22
22
|
const numClass = num ? `ol-reset-${num}` : false;
|
|
23
|
-
const classes = [node.attribs.class ?? false, letterClass, numClass].filter(c => !!c).join(
|
|
23
|
+
const classes = [node.attribs.class ?? false, letterClass, numClass].filter(c => !!c).join(" ");
|
|
24
24
|
return (0, _jsxRuntime.jsx)(_ui.OrderedList, {
|
|
25
25
|
...props,
|
|
26
26
|
className: classes.length ? classes : undefined,
|
|
@@ -16,8 +16,8 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
|
|
17
17
|
const paragraphPlugin = (node, converterOpts, opts) => {
|
|
18
18
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
19
|
-
if (node.attribs[
|
|
20
|
-
const classes = [node.attribs.class ??
|
|
19
|
+
if (node.attribs["data-align"] === "center") {
|
|
20
|
+
const classes = [node.attribs.class ?? "", "u-text-center"].filter(c => !!c).join(" ");
|
|
21
21
|
return (0, _jsxRuntime.jsx)("p", {
|
|
22
22
|
...props,
|
|
23
23
|
lang: opts.articleLanguage,
|
|
@@ -15,12 +15,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
const spanPlugin = (node, opts) => {
|
|
18
|
-
if (node.attribs[
|
|
18
|
+
if (node.attribs["data-size"] === "large") {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
20
|
return (0, _jsxRuntime.jsx)("span", {
|
|
21
21
|
...props,
|
|
22
22
|
"data-size": undefined,
|
|
23
|
-
className: `${node.attribs.class ??
|
|
23
|
+
className: `${node.attribs.class ?? ""} u-large-body-text`,
|
|
24
24
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
25
25
|
});
|
|
26
26
|
}
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
/// <reference types="react" />
|
|
9
|
-
import { Element, HTMLReactParserOptions } from
|
|
10
|
-
import { HeartButtonType, RenderContext, CanonicalUrlFuncs } from
|
|
9
|
+
import { Element, HTMLReactParserOptions } from "html-react-parser";
|
|
10
|
+
import { HeartButtonType, RenderContext, CanonicalUrlFuncs } from "@ndla/ui";
|
|
11
11
|
export interface DynamicComponents {
|
|
12
12
|
heartButton?: HeartButtonType;
|
|
13
13
|
}
|
package/lib/plugins/ulPlugin.js
CHANGED
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const ulPlugin = (node, converterOpts, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
-
const classes = [node.attribs.class ??
|
|
20
|
+
const classes = [node.attribs.class ?? "", node.attribs["data-type"] === "two-column" ? "o-list--two-columns" : ""].filter(c => !!c).join(" ");
|
|
21
21
|
return (0, _jsxRuntime.jsx)(_ui.UnOrderedList, {
|
|
22
22
|
...props,
|
|
23
23
|
className: classes,
|
package/lib/transform.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
/// <reference types="react" />
|
|
9
|
-
import { TransformOptions } from
|
|
9
|
+
import { TransformOptions } from "./plugins/types";
|
|
10
10
|
declare const transform: (content: string, opts: TransformOptions) => string | JSX.Element | JSX.Element[];
|
|
11
11
|
export default transform;
|
package/lib/transform.js
CHANGED
|
@@ -22,17 +22,17 @@ const transform = (content, opts) => {
|
|
|
22
22
|
const plugins = opts?.isOembed ? _plugins.oembedPlugins : _plugins.basePlugins;
|
|
23
23
|
const options = {
|
|
24
24
|
replace: node => {
|
|
25
|
-
if (!(
|
|
25
|
+
if (!("attribs" in node)) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
if (plugins[node.name]) {
|
|
29
29
|
return plugins[node.name](node, options, opts);
|
|
30
30
|
}
|
|
31
|
-
if (node.name ===
|
|
32
|
-
if (_embed.embedPlugins[node.attribs[
|
|
33
|
-
return _embed.embedPlugins[node.attribs[
|
|
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
34
|
} else {
|
|
35
|
-
const embed = JSON.parse(node.attribs[
|
|
35
|
+
const embed = JSON.parse(node.attribs["data-json"]);
|
|
36
36
|
return (0, _jsxRuntime.jsx)(_ui.UnknownEmbed, {
|
|
37
37
|
embed: embed
|
|
38
38
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.44",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
],
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@ndla/types-backend": "^0.2.21",
|
|
31
|
-
"@ndla/types-embed": "^4.0.
|
|
31
|
+
"@ndla/types-embed": "^4.0.13"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ndla/code": "^5.0.
|
|
35
|
-
"@ndla/ui": "^50.8.
|
|
34
|
+
"@ndla/code": "^5.0.31",
|
|
35
|
+
"@ndla/ui": "^50.8.2",
|
|
36
36
|
"html-react-parser": "^4.2.2",
|
|
37
37
|
"lodash": "^4.17.20"
|
|
38
38
|
},
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ca60118709ca3cd878081b8ea0d20d1100b54508"
|
|
52
52
|
}
|
package/src/extractEmbedMeta.ts
CHANGED
|
@@ -6,36 +6,36 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import parse from
|
|
10
|
-
import { EmbedMetaData } from
|
|
9
|
+
import parse from "html-react-parser";
|
|
10
|
+
import { EmbedMetaData } from "@ndla/types-embed";
|
|
11
11
|
|
|
12
12
|
const extractEmbedMeta = (embed: string): EmbedMetaData | undefined => {
|
|
13
13
|
const node = parse(embed);
|
|
14
|
-
if (typeof node ===
|
|
14
|
+
if (typeof node === "string" || Array.isArray(node) || node.type !== "ndlaembed" || !node.props["data-json"]) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return JSON.parse(node.props[
|
|
18
|
+
return JSON.parse(node.props["data-json"]) as EmbedMetaData;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const extractEmbedMetas = (embed: string): EmbedMetaData[] => {
|
|
22
22
|
const nodes = parse(embed);
|
|
23
23
|
|
|
24
24
|
// There are no embeds in the string
|
|
25
|
-
if (typeof nodes ===
|
|
25
|
+
if (typeof nodes === "string") {
|
|
26
26
|
return [];
|
|
27
27
|
}
|
|
28
28
|
// There is only one embed in the string
|
|
29
|
-
else if (!Array.isArray(nodes) && nodes.type ===
|
|
30
|
-
return [JSON.parse(nodes.props[
|
|
29
|
+
else if (!Array.isArray(nodes) && nodes.type === "ndlaembed" && !!nodes.props["data-json"]) {
|
|
30
|
+
return [JSON.parse(nodes.props["data-json"]) as EmbedMetaData];
|
|
31
31
|
}
|
|
32
32
|
// There are multiple embeds in the string
|
|
33
33
|
else if (
|
|
34
34
|
Array.isArray(nodes) &&
|
|
35
35
|
nodes.length &&
|
|
36
|
-
nodes.every((n) => n.type ===
|
|
36
|
+
nodes.every((n) => n.type === "ndlaembed" && !!n.props["data-json"])
|
|
37
37
|
) {
|
|
38
|
-
return nodes.map((n) => JSON.parse(n.props[
|
|
38
|
+
return nodes.map((n) => JSON.parse(n.props["data-json"]) as EmbedMetaData);
|
|
39
39
|
} else {
|
|
40
40
|
return [];
|
|
41
41
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export { default as transform } from
|
|
10
|
-
export { default as extractEmbedMeta, extractEmbedMetas } from
|
|
11
|
-
export type { TransformOptions, DynamicComponents } from
|
|
9
|
+
export { default as transform } from "./transform";
|
|
10
|
+
export { default as extractEmbedMeta, extractEmbedMetas } from "./extractEmbedMeta";
|
|
11
|
+
export type { TransformOptions, DynamicComponents } from "./plugins/types";
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
10
|
-
import SafeLink from
|
|
11
|
-
import { getPossiblyRelativeUrl } from
|
|
12
|
-
import { PluginType } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import SafeLink from "@ndla/safelink";
|
|
11
|
+
import { getPossiblyRelativeUrl } from "@ndla/ui";
|
|
12
|
+
import { PluginType } from "./types";
|
|
13
13
|
|
|
14
14
|
export const anchorPlugin: PluginType = (node, opts, { path }) => {
|
|
15
15
|
const props = attributesToProps(node.attribs);
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { domToReact } from
|
|
10
|
-
import { Aside, FactBox } from
|
|
11
|
-
import { PluginType } from
|
|
9
|
+
import { domToReact } from "html-react-parser";
|
|
10
|
+
import { Aside, FactBox } from "@ndla/ui";
|
|
11
|
+
import { PluginType } from "./types";
|
|
12
12
|
export const asidePlugin: PluginType = (node, opts) => {
|
|
13
|
-
if (node.attribs[
|
|
13
|
+
if (node.attribs["data-type"] === "factAside") {
|
|
14
14
|
return <FactBox>{domToReact(node.children, opts)}</FactBox>;
|
|
15
|
-
} else if (node.attribs[
|
|
15
|
+
} else if (node.attribs["data-type"] === "rightAside") {
|
|
16
16
|
return (
|
|
17
17
|
<Aside wideScreen alwaysShow>
|
|
18
18
|
{domToReact(node.children, opts)}
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { Element, domToReact } from
|
|
10
|
-
import { CopyParagraphButton } from
|
|
11
|
-
import { PluginType } from
|
|
9
|
+
import { Element, domToReact } from "html-react-parser";
|
|
10
|
+
import { CopyParagraphButton } from "@ndla/ui";
|
|
11
|
+
import { PluginType } from "./types";
|
|
12
12
|
export const copyParagraphPlugin: PluginType = (node, converterOpts, opts) => {
|
|
13
13
|
const parent = node.parent as Element | undefined;
|
|
14
|
-
if (parent?.name ===
|
|
14
|
+
if (parent?.name === "section" || (parent?.name === "div" && Object.keys(parent.attribs ?? {}).length === 0)) {
|
|
15
15
|
return (
|
|
16
|
-
<CopyParagraphButton copyText={node.attribs[
|
|
16
|
+
<CopyParagraphButton copyText={node.attribs["data-text"]} lang={opts.articleLanguage}>
|
|
17
17
|
{domToReact(node.children, converterOpts)}
|
|
18
18
|
</CopyParagraphButton>
|
|
19
19
|
);
|
package/src/plugins/ddPlugin.tsx
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps, domToReact } from
|
|
10
|
-
import { DefinitionDescription } from
|
|
11
|
-
import { PluginType } from
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { DefinitionDescription } from "@ndla/ui";
|
|
11
|
+
import { PluginType } from "./types";
|
|
12
12
|
|
|
13
13
|
export const ddPlugin: PluginType = (node, converterOpts, opts) => {
|
|
14
14
|
const props = attributesToProps(node.attribs);
|