@ndla/article-converter 9.0.12-alpha.0 → 9.0.14-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/plugins/blockquotePlugin.js +18 -0
- package/es/plugins/copyParagraphPlugin.js +1 -2
- package/es/plugins/{ddPlugin.js → detailsPlugin.js} +4 -5
- package/es/plugins/divPlugin.js +2 -1
- package/es/plugins/{dtPlugin.js → dlPlugin.js} +3 -3
- package/es/plugins/embed/blogPostEmbedPlugin.js +2 -3
- package/es/plugins/embed/conceptEmbedPlugin.js +0 -1
- package/es/plugins/embed/contactBlockEmbedPlugin.js +1 -2
- package/es/plugins/embed/imageEmbedPlugin.js +0 -3
- package/es/plugins/index.js +9 -5
- package/es/plugins/olPlugin.js +2 -3
- package/es/plugins/summaryPlugin.js +18 -0
- package/es/plugins/tablePlugin.js +1 -1
- package/es/transform.js +1 -1
- package/lib/plugins/blockquotePlugin.d.ts +9 -0
- package/lib/plugins/blockquotePlugin.js +25 -0
- package/lib/plugins/copyParagraphPlugin.js +1 -2
- package/lib/plugins/{ddPlugin.d.ts → detailsPlugin.d.ts} +2 -2
- package/lib/plugins/{ddPlugin.js → detailsPlugin.js} +6 -7
- package/lib/plugins/divPlugin.js +2 -1
- package/lib/plugins/{dtPlugin.d.ts → dlPlugin.d.ts} +1 -1
- package/lib/plugins/{dtPlugin.js → dlPlugin.js} +5 -5
- package/lib/plugins/embed/blogPostEmbedPlugin.js +2 -3
- package/lib/plugins/embed/conceptEmbedPlugin.js +0 -1
- package/lib/plugins/embed/contactBlockEmbedPlugin.js +1 -2
- package/lib/plugins/embed/imageEmbedPlugin.js +0 -3
- package/lib/plugins/index.js +9 -5
- package/lib/plugins/olPlugin.js +2 -3
- package/lib/plugins/summaryPlugin.d.ts +9 -0
- package/lib/plugins/summaryPlugin.js +25 -0
- package/lib/plugins/tablePlugin.js +2 -2
- package/lib/transform.js +1 -1
- package/package.json +4 -3
- package/src/plugins/blockquotePlugin.tsx +16 -0
- package/src/plugins/detailsPlugin.tsx +17 -0
- package/src/plugins/divPlugin.tsx +2 -1
- package/src/plugins/{dtPlugin.tsx → dlPlugin.tsx} +4 -4
- package/src/plugins/embed/conceptEmbedPlugin.tsx +1 -1
- package/src/plugins/embed/imageEmbedPlugin.tsx +1 -3
- package/src/plugins/index.ts +8 -4
- package/src/plugins/{ddPlugin.tsx → summaryPlugin.tsx} +4 -6
- package/src/plugins/tablePlugin.tsx +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { BlockQuote } from "@ndla/primitives";
|
|
11
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
+
export const blockquotePlugin = (node, opts) => {
|
|
13
|
+
const props = attributesToProps(node.attribs);
|
|
14
|
+
return _jsx(BlockQuote, {
|
|
15
|
+
...props,
|
|
16
|
+
children: domToReact(node.children, opts)
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -10,9 +10,8 @@ import { domToReact } from "html-react-parser";
|
|
|
10
10
|
import { CopyParagraphButton } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const copyParagraphPlugin = (node, converterOpts, opts) => {
|
|
13
|
-
var _parent$attribs;
|
|
14
13
|
const parent = node.parent;
|
|
15
|
-
if (
|
|
14
|
+
if (parent?.name === "section" || parent?.name === "div" && Object.keys(parent.attribs ?? {}).length === 0 || parent?.name === "ndlaembed" && parent.attribs["data-resource"] === "uu-disclaimer") {
|
|
16
15
|
return _jsx(CopyParagraphButton, {
|
|
17
16
|
copyText: node.attribs["data-text"],
|
|
18
17
|
lang: opts.articleLanguage,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024-present, NDLA.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the GPLv3 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,13 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { ExpandableBox } from "@ndla/primitives";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
-
export const
|
|
12
|
+
export const detailsPlugin = (node, converterOpts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
|
14
|
-
return _jsx(
|
|
14
|
+
return _jsx(ExpandableBox, {
|
|
15
15
|
...props,
|
|
16
|
-
lang: opts.articleLanguage,
|
|
17
16
|
children: domToReact(node.children, converterOpts)
|
|
18
17
|
});
|
|
19
18
|
};
|
package/es/plugins/divPlugin.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { domToReact, attributesToProps } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { FramedContent } from "@ndla/primitives";
|
|
11
|
+
import { FileList, RelatedArticleList, Grid, GridParallaxItem } from "@ndla/ui";
|
|
11
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
12
13
|
export const divPlugin = (node, opts) => {
|
|
13
14
|
if (node.attribs["data-type"] === "framed-content" || node.attribs.class === "c-bodybox") {
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { DefinitionList } from "@ndla/primitives";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
-
export const
|
|
12
|
+
export const dlPlugin = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
|
14
|
-
return _jsx(
|
|
14
|
+
return _jsx(DefinitionList, {
|
|
15
15
|
...props,
|
|
16
16
|
lang: opts.articleLanguage,
|
|
17
17
|
children: domToReact(node.children, converterOpts)
|
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
import { attributesToProps } from "html-react-parser";
|
|
10
10
|
import { BlogPostV2 } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
-
export const errorSvgSrc =
|
|
12
|
+
export const errorSvgSrc = `data:image/svg+xml;charset=UTF-8,%3Csvg fill='%238A8888' height='400' viewBox='0 0 24 12' width='100%25' xmlns='http://www.w3.org/2000/svg' style='background-color: %23EFF0F2'%3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath transform='scale(0.3) translate(28, 8.5)' d='M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z'/%3E%3C/svg%3E`;
|
|
13
13
|
export const blogPostEmbedPlugin = (element, _, opts) => {
|
|
14
|
-
var _data$data$metaImage$, _data$data$metaImage;
|
|
15
14
|
const props = attributesToProps(element.attribs);
|
|
16
15
|
const data = JSON.parse(props["data-json"]);
|
|
17
16
|
const {
|
|
@@ -29,7 +28,7 @@ export const blogPostEmbedPlugin = (element, _, opts) => {
|
|
|
29
28
|
path: opts.path,
|
|
30
29
|
metaImage: {
|
|
31
30
|
alt: alt ? alt : "",
|
|
32
|
-
url: data.status === "success" ?
|
|
31
|
+
url: data.status === "success" ? data.data.metaImage?.image.imageUrl ?? errorSvgSrc : errorSvgSrc
|
|
33
32
|
}
|
|
34
33
|
});
|
|
35
34
|
};
|
|
@@ -10,7 +10,6 @@ import { attributesToProps } from "html-react-parser";
|
|
|
10
10
|
import { ContactBlock } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
13
|
-
var _opts$canonicalUrls;
|
|
14
13
|
const props = attributesToProps(element.attribs);
|
|
15
14
|
const embedData = JSON.parse(props["data-json"]);
|
|
16
15
|
const {
|
|
@@ -32,6 +31,6 @@ export const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
|
32
31
|
name: name,
|
|
33
32
|
blob: blob,
|
|
34
33
|
lang: opts.articleLanguage,
|
|
35
|
-
imageCanonicalUrl:
|
|
34
|
+
imageCanonicalUrl: opts.canonicalUrls?.image
|
|
36
35
|
});
|
|
37
36
|
};
|
|
@@ -10,12 +10,9 @@ import { attributesToProps } from "html-react-parser";
|
|
|
10
10
|
import { ImageEmbed } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const imageEmbedPlugin = (element, _, opts) => {
|
|
13
|
-
var _element$parentNode;
|
|
14
13
|
const props = attributesToProps(element.attribs);
|
|
15
14
|
const data = JSON.parse(props["data-json"]);
|
|
16
|
-
const inGrid = ((_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.attribs) === null || _element$parentNode === void 0 ? void 0 : _element$parentNode["data-type"]) === "grid";
|
|
17
15
|
return _jsx(ImageEmbed, {
|
|
18
|
-
inGrid: inGrid,
|
|
19
16
|
embed: data,
|
|
20
17
|
previewAlt: opts.previewAlt,
|
|
21
18
|
lang: opts.articleLanguage,
|
package/es/plugins/index.js
CHANGED
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
|
|
9
9
|
import { anchorPlugin } from "./anchorPlugin";
|
|
10
10
|
import { asidePlugin } from "./asidePlugin";
|
|
11
|
+
import { blockquotePlugin } from "./blockquotePlugin";
|
|
11
12
|
import { copyParagraphPlugin } from "./copyParagraphPlugin";
|
|
12
|
-
import {
|
|
13
|
+
import { detailsPlugin } from "./detailsPlugin";
|
|
13
14
|
import { divPlugin } from "./divPlugin";
|
|
14
|
-
import {
|
|
15
|
+
import { dlPlugin } from "./dlPlugin";
|
|
15
16
|
import { h3Plugin } from "./h3Plugin";
|
|
16
17
|
import { mathPlugin } from "./mathPlugin";
|
|
17
18
|
import { navPlugin } from "./navPlugin";
|
|
18
19
|
import { anchorPlugin as oembedAnchorPlugin } from "./oembed/anchorPlugin";
|
|
19
20
|
import { olPlugin } from "./olPlugin";
|
|
20
21
|
import { paragraphPlugin } from "./paragraphPlugin";
|
|
22
|
+
import { summaryPlugin } from "./summaryPlugin";
|
|
21
23
|
import { tablePlugin } from "./tablePlugin";
|
|
22
24
|
import { ulPlugin } from "./ulPlugin";
|
|
23
25
|
export const basePlugins = {
|
|
@@ -30,10 +32,12 @@ export const basePlugins = {
|
|
|
30
32
|
table: tablePlugin,
|
|
31
33
|
aside: asidePlugin,
|
|
32
34
|
ul: ulPlugin,
|
|
33
|
-
dd: ddPlugin,
|
|
34
|
-
dt: dtPlugin,
|
|
35
35
|
nav: navPlugin,
|
|
36
|
-
a: anchorPlugin
|
|
36
|
+
a: anchorPlugin,
|
|
37
|
+
summary: summaryPlugin,
|
|
38
|
+
details: detailsPlugin,
|
|
39
|
+
dl: dlPlugin,
|
|
40
|
+
blockquote: blockquotePlugin
|
|
37
41
|
};
|
|
38
42
|
export const oembedPlugins = {
|
|
39
43
|
...basePlugins,
|
package/es/plugins/olPlugin.js
CHANGED
|
@@ -10,12 +10,11 @@ import { attributesToProps, domToReact } from "html-react-parser";
|
|
|
10
10
|
import { OrderedList } from "@ndla/ui";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const olPlugin = (node, converterOpts, opts) => {
|
|
13
|
-
var _node$attribs$class;
|
|
14
13
|
const props = attributesToProps(node.attribs);
|
|
15
14
|
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
16
15
|
const num = node.attribs.start;
|
|
17
|
-
const numClass = num ?
|
|
18
|
-
const classes = [
|
|
16
|
+
const numClass = num ? `ol-reset-${num}` : false;
|
|
17
|
+
const classes = [node.attribs.class ?? false, letterClass, numClass].filter(c => !!c).join(" ");
|
|
19
18
|
return _jsx(OrderedList, {
|
|
20
19
|
...props,
|
|
21
20
|
className: classes.length ? classes : undefined,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { ExpandableBoxSummary } from "@ndla/primitives";
|
|
11
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
|
+
export const summaryPlugin = (node, converterOpts) => {
|
|
13
|
+
const props = attributesToProps(node.attribs);
|
|
14
|
+
return _jsx(ExpandableBoxSummary, {
|
|
15
|
+
...props,
|
|
16
|
+
children: domToReact(node.children, converterOpts)
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
-
import { Table } from "@ndla/
|
|
10
|
+
import { Table } from "@ndla/primitives";
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export const tablePlugin = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|
package/es/transform.js
CHANGED
|
@@ -12,7 +12,7 @@ import { basePlugins, oembedPlugins } from "./plugins";
|
|
|
12
12
|
import { embedPlugins } from "./plugins/embed";
|
|
13
13
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
14
14
|
const transform = (content, opts) => {
|
|
15
|
-
const plugins = opts
|
|
15
|
+
const plugins = opts?.isOembed ? oembedPlugins : basePlugins;
|
|
16
16
|
const options = {
|
|
17
17
|
replace: node => {
|
|
18
18
|
if (!("attribs" in node)) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024-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 blockquotePlugin: PluginType;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.blockquotePlugin = void 0;
|
|
7
|
+
var _htmlReactParser = require("html-react-parser");
|
|
8
|
+
var _primitives = require("@ndla/primitives");
|
|
9
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) 2024-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
|
+
const blockquotePlugin = (node, opts) => {
|
|
19
|
+
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
+
return (0, _jsxRuntime.jsx)(_primitives.BlockQuote, {
|
|
21
|
+
...props,
|
|
22
|
+
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.blockquotePlugin = blockquotePlugin;
|
|
@@ -16,9 +16,8 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const copyParagraphPlugin = (node, converterOpts, opts) => {
|
|
19
|
-
var _parent$attribs;
|
|
20
19
|
const parent = node.parent;
|
|
21
|
-
if (
|
|
20
|
+
if (parent?.name === "section" || parent?.name === "div" && Object.keys(parent.attribs ?? {}).length === 0 || parent?.name === "ndlaembed" && parent.attribs["data-resource"] === "uu-disclaimer") {
|
|
22
21
|
return (0, _jsxRuntime.jsx)(_ui.CopyParagraphButton, {
|
|
23
22
|
copyText: node.attribs["data-text"],
|
|
24
23
|
lang: opts.articleLanguage,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024-present, NDLA.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the GPLv3 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { PluginType } from "./types";
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const detailsPlugin: PluginType;
|
|
@@ -3,24 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.detailsPlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
-
var
|
|
8
|
+
var _primitives = require("@ndla/primitives");
|
|
9
9
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
10
|
/**
|
|
11
|
-
* Copyright (c)
|
|
11
|
+
* Copyright (c) 2024-present, NDLA.
|
|
12
12
|
*
|
|
13
13
|
* This source code is licensed under the GPLv3 license found in the
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const detailsPlugin = (node, converterOpts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
-
return (0, _jsxRuntime.jsx)(
|
|
20
|
+
return (0, _jsxRuntime.jsx)(_primitives.ExpandableBox, {
|
|
21
21
|
...props,
|
|
22
|
-
lang: opts.articleLanguage,
|
|
23
22
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
|
24
23
|
});
|
|
25
24
|
};
|
|
26
|
-
exports.
|
|
25
|
+
exports.detailsPlugin = detailsPlugin;
|
package/lib/plugins/divPlugin.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.divPlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
+
var _primitives = require("@ndla/primitives");
|
|
8
9
|
var _ui = require("@ndla/ui");
|
|
9
10
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
11
|
/**
|
|
@@ -17,7 +18,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
18
|
|
|
18
19
|
const divPlugin = (node, opts) => {
|
|
19
20
|
if (node.attribs["data-type"] === "framed-content" || node.attribs.class === "c-bodybox") {
|
|
20
|
-
return (0, _jsxRuntime.jsx)(
|
|
21
|
+
return (0, _jsxRuntime.jsx)(_primitives.FramedContent, {
|
|
21
22
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
22
23
|
});
|
|
23
24
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.dlPlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
-
var
|
|
8
|
+
var _primitives = require("@ndla/primitives");
|
|
9
9
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
10
|
/**
|
|
11
11
|
* Copyright (c) 2023-present, NDLA.
|
|
@@ -15,12 +15,12 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const dlPlugin = (node, converterOpts, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
-
return (0, _jsxRuntime.jsx)(
|
|
20
|
+
return (0, _jsxRuntime.jsx)(_primitives.DefinitionList, {
|
|
21
21
|
...props,
|
|
22
22
|
lang: opts.articleLanguage,
|
|
23
23
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
|
-
exports.
|
|
26
|
+
exports.dlPlugin = dlPlugin;
|
|
@@ -15,9 +15,8 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const errorSvgSrc = exports.errorSvgSrc =
|
|
18
|
+
const errorSvgSrc = exports.errorSvgSrc = `data:image/svg+xml;charset=UTF-8,%3Csvg fill='%238A8888' height='400' viewBox='0 0 24 12' width='100%25' xmlns='http://www.w3.org/2000/svg' style='background-color: %23EFF0F2'%3E%3Cpath d='M0 0h24v24H0V0z' fill='none'/%3E%3Cpath transform='scale(0.3) translate(28, 8.5)' d='M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z'/%3E%3C/svg%3E`;
|
|
19
19
|
const blogPostEmbedPlugin = (element, _, opts) => {
|
|
20
|
-
var _data$data$metaImage$, _data$data$metaImage;
|
|
21
20
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
22
21
|
const data = JSON.parse(props["data-json"]);
|
|
23
22
|
const {
|
|
@@ -35,7 +34,7 @@ const blogPostEmbedPlugin = (element, _, opts) => {
|
|
|
35
34
|
path: opts.path,
|
|
36
35
|
metaImage: {
|
|
37
36
|
alt: alt ? alt : "",
|
|
38
|
-
url: data.status === "success" ?
|
|
37
|
+
url: data.status === "success" ? data.data.metaImage?.image.imageUrl ?? errorSvgSrc : errorSvgSrc
|
|
39
38
|
}
|
|
40
39
|
});
|
|
41
40
|
};
|
|
@@ -16,7 +16,6 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
19
|
-
var _opts$canonicalUrls;
|
|
20
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
21
20
|
const embedData = JSON.parse(props["data-json"]);
|
|
22
21
|
const {
|
|
@@ -38,7 +37,7 @@ const contactBlockEmbedPlugin = (element, _, opts) => {
|
|
|
38
37
|
name: name,
|
|
39
38
|
blob: blob,
|
|
40
39
|
lang: opts.articleLanguage,
|
|
41
|
-
imageCanonicalUrl:
|
|
40
|
+
imageCanonicalUrl: opts.canonicalUrls?.image
|
|
42
41
|
});
|
|
43
42
|
};
|
|
44
43
|
exports.contactBlockEmbedPlugin = contactBlockEmbedPlugin;
|
|
@@ -16,12 +16,9 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const imageEmbedPlugin = (element, _, opts) => {
|
|
19
|
-
var _element$parentNode;
|
|
20
19
|
const props = (0, _htmlReactParser.attributesToProps)(element.attribs);
|
|
21
20
|
const data = JSON.parse(props["data-json"]);
|
|
22
|
-
const inGrid = ((_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.parentNode) === null || _element$parentNode === void 0 || (_element$parentNode = _element$parentNode.attribs) === null || _element$parentNode === void 0 ? void 0 : _element$parentNode["data-type"]) === "grid";
|
|
23
21
|
return (0, _jsxRuntime.jsx)(_ui.ImageEmbed, {
|
|
24
|
-
inGrid: inGrid,
|
|
25
22
|
embed: data,
|
|
26
23
|
previewAlt: opts.previewAlt,
|
|
27
24
|
lang: opts.articleLanguage,
|
package/lib/plugins/index.js
CHANGED
|
@@ -6,16 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.oembedPlugins = exports.basePlugins = void 0;
|
|
7
7
|
var _anchorPlugin = require("./anchorPlugin");
|
|
8
8
|
var _asidePlugin = require("./asidePlugin");
|
|
9
|
+
var _blockquotePlugin = require("./blockquotePlugin");
|
|
9
10
|
var _copyParagraphPlugin = require("./copyParagraphPlugin");
|
|
10
|
-
var
|
|
11
|
+
var _detailsPlugin = require("./detailsPlugin");
|
|
11
12
|
var _divPlugin = require("./divPlugin");
|
|
12
|
-
var
|
|
13
|
+
var _dlPlugin = require("./dlPlugin");
|
|
13
14
|
var _h3Plugin = require("./h3Plugin");
|
|
14
15
|
var _mathPlugin = require("./mathPlugin");
|
|
15
16
|
var _navPlugin = require("./navPlugin");
|
|
16
17
|
var _anchorPlugin2 = require("./oembed/anchorPlugin");
|
|
17
18
|
var _olPlugin = require("./olPlugin");
|
|
18
19
|
var _paragraphPlugin = require("./paragraphPlugin");
|
|
20
|
+
var _summaryPlugin = require("./summaryPlugin");
|
|
19
21
|
var _tablePlugin = require("./tablePlugin");
|
|
20
22
|
var _ulPlugin = require("./ulPlugin");
|
|
21
23
|
/**
|
|
@@ -36,10 +38,12 @@ const basePlugins = exports.basePlugins = {
|
|
|
36
38
|
table: _tablePlugin.tablePlugin,
|
|
37
39
|
aside: _asidePlugin.asidePlugin,
|
|
38
40
|
ul: _ulPlugin.ulPlugin,
|
|
39
|
-
dd: _ddPlugin.ddPlugin,
|
|
40
|
-
dt: _dtPlugin.dtPlugin,
|
|
41
41
|
nav: _navPlugin.navPlugin,
|
|
42
|
-
a: _anchorPlugin.anchorPlugin
|
|
42
|
+
a: _anchorPlugin.anchorPlugin,
|
|
43
|
+
summary: _summaryPlugin.summaryPlugin,
|
|
44
|
+
details: _detailsPlugin.detailsPlugin,
|
|
45
|
+
dl: _dlPlugin.dlPlugin,
|
|
46
|
+
blockquote: _blockquotePlugin.blockquotePlugin
|
|
43
47
|
};
|
|
44
48
|
const oembedPlugins = exports.oembedPlugins = {
|
|
45
49
|
...basePlugins,
|
package/lib/plugins/olPlugin.js
CHANGED
|
@@ -16,12 +16,11 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
const olPlugin = (node, converterOpts, opts) => {
|
|
19
|
-
var _node$attribs$class;
|
|
20
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
21
20
|
const letterClass = node.attribs["data-type"] === "letters" ? "ol-list--roman" : false;
|
|
22
21
|
const num = node.attribs.start;
|
|
23
|
-
const numClass = num ?
|
|
24
|
-
const classes = [
|
|
22
|
+
const numClass = num ? `ol-reset-${num}` : false;
|
|
23
|
+
const classes = [node.attribs.class ?? false, letterClass, numClass].filter(c => !!c).join(" ");
|
|
25
24
|
return (0, _jsxRuntime.jsx)(_ui.OrderedList, {
|
|
26
25
|
...props,
|
|
27
26
|
className: classes.length ? classes : undefined,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024-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 summaryPlugin: PluginType;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.summaryPlugin = void 0;
|
|
7
|
+
var _htmlReactParser = require("html-react-parser");
|
|
8
|
+
var _primitives = require("@ndla/primitives");
|
|
9
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) 2024-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
|
+
const summaryPlugin = (node, converterOpts) => {
|
|
19
|
+
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
+
return (0, _jsxRuntime.jsx)(_primitives.ExpandableBoxSummary, {
|
|
21
|
+
...props,
|
|
22
|
+
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.summaryPlugin = summaryPlugin;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.tablePlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
-
var
|
|
8
|
+
var _primitives = require("@ndla/primitives");
|
|
9
9
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
10
10
|
/**
|
|
11
11
|
* Copyright (c) 2023-present, NDLA.
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
const tablePlugin = (node, converterOpts, opts) => {
|
|
19
19
|
const props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
20
|
-
return (0, _jsxRuntime.jsx)(
|
|
20
|
+
return (0, _jsxRuntime.jsx)(_primitives.Table, {
|
|
21
21
|
...props,
|
|
22
22
|
lang: opts.articleLanguage,
|
|
23
23
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
package/lib/transform.js
CHANGED
|
@@ -19,7 +19,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
const transform = (content, opts) => {
|
|
22
|
-
const plugins = opts
|
|
22
|
+
const plugins = opts?.isOembed ? _plugins.oembedPlugins : _plugins.basePlugins;
|
|
23
23
|
const options = {
|
|
24
24
|
replace: node => {
|
|
25
25
|
if (!("attribs" in node)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.14-alpha.0",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"@ndla/types-embed": "^4.1.8"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ndla/
|
|
34
|
+
"@ndla/primitives": "^0.0.18",
|
|
35
|
+
"@ndla/ui": "^55.0.14-alpha.0",
|
|
35
36
|
"html-react-parser": "^5.1.8"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"access": "public"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "6fdfbed9f18bbd725c837fb74de2f093e80d5605"
|
|
50
51
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024-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 { DOMNode, attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { BlockQuote } from "@ndla/primitives";
|
|
11
|
+
import { PluginType } from "./types";
|
|
12
|
+
|
|
13
|
+
export const blockquotePlugin: PluginType = (node, opts) => {
|
|
14
|
+
const props = attributesToProps(node.attribs);
|
|
15
|
+
return <BlockQuote {...props}>{domToReact(node.children as DOMNode[], opts)}</BlockQuote>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2024-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 { DOMNode, attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
+
import { ExpandableBox } from "@ndla/primitives";
|
|
11
|
+
import { PluginType } from "./types";
|
|
12
|
+
|
|
13
|
+
export const detailsPlugin: PluginType = (node, converterOpts) => {
|
|
14
|
+
const props = attributesToProps(node.attribs);
|
|
15
|
+
|
|
16
|
+
return <ExpandableBox {...props}>{domToReact(node.children as DOMNode[], converterOpts)}</ExpandableBox>;
|
|
17
|
+
};
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { domToReact, attributesToProps, Element, DOMNode } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { FramedContent } from "@ndla/primitives";
|
|
11
|
+
import { FileList, RelatedArticleList, Grid, GridType, GridParallaxItem } from "@ndla/ui";
|
|
11
12
|
import { PluginType } from "./types";
|
|
12
13
|
|
|
13
14
|
export const divPlugin: PluginType = (node, opts) => {
|
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { DOMNode, attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { DefinitionList } from "@ndla/primitives";
|
|
11
11
|
import { PluginType } from "./types";
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const dlPlugin: PluginType = (node, converterOpts, opts) => {
|
|
14
14
|
const props = attributesToProps(node.attribs);
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
|
-
<
|
|
17
|
+
<DefinitionList {...props} lang={opts.articleLanguage}>
|
|
18
18
|
{domToReact(node.children as DOMNode[], converterOpts)}
|
|
19
|
-
</
|
|
19
|
+
</DefinitionList>
|
|
20
20
|
);
|
|
21
21
|
};
|
|
@@ -14,5 +14,5 @@ import { PluginType } from "../types";
|
|
|
14
14
|
export const conceptEmbedPlugin: PluginType = (element, _, opts) => {
|
|
15
15
|
const props = attributesToProps(element.attribs);
|
|
16
16
|
const data = JSON.parse(props["data-json"] as string) as ConceptMetaData;
|
|
17
|
-
return <ConceptEmbed embed={data}
|
|
17
|
+
return <ConceptEmbed embed={data} lang={opts.articleLanguage} renderContext={opts.renderContext} />;
|
|
18
18
|
};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { attributesToProps
|
|
9
|
+
import { attributesToProps } from "html-react-parser";
|
|
10
10
|
import { ImageMetaData } from "@ndla/types-embed";
|
|
11
11
|
import { ImageEmbed } from "@ndla/ui";
|
|
12
12
|
import { PluginType } from "../types";
|
|
@@ -14,11 +14,9 @@ import { PluginType } from "../types";
|
|
|
14
14
|
export const imageEmbedPlugin: PluginType = (element, _, opts) => {
|
|
15
15
|
const props = attributesToProps(element.attribs);
|
|
16
16
|
const data = JSON.parse(props["data-json"] as string) as ImageMetaData;
|
|
17
|
-
const inGrid = (element.parentNode?.parentNode as Element)?.attribs?.["data-type"] === "grid";
|
|
18
17
|
|
|
19
18
|
return (
|
|
20
19
|
<ImageEmbed
|
|
21
|
-
inGrid={inGrid}
|
|
22
20
|
embed={data}
|
|
23
21
|
previewAlt={opts.previewAlt}
|
|
24
22
|
lang={opts.articleLanguage}
|
package/src/plugins/index.ts
CHANGED
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
|
|
9
9
|
import { anchorPlugin } from "./anchorPlugin";
|
|
10
10
|
import { asidePlugin } from "./asidePlugin";
|
|
11
|
+
import { blockquotePlugin } from "./blockquotePlugin";
|
|
11
12
|
import { copyParagraphPlugin } from "./copyParagraphPlugin";
|
|
12
|
-
import {
|
|
13
|
+
import { detailsPlugin } from "./detailsPlugin";
|
|
13
14
|
import { divPlugin } from "./divPlugin";
|
|
14
|
-
import {
|
|
15
|
+
import { dlPlugin } from "./dlPlugin";
|
|
15
16
|
import { h3Plugin } from "./h3Plugin";
|
|
16
17
|
import { mathPlugin } from "./mathPlugin";
|
|
17
18
|
import { navPlugin } from "./navPlugin";
|
|
18
19
|
import { anchorPlugin as oembedAnchorPlugin } from "./oembed/anchorPlugin";
|
|
19
20
|
import { olPlugin } from "./olPlugin";
|
|
20
21
|
import { paragraphPlugin } from "./paragraphPlugin";
|
|
22
|
+
import { summaryPlugin } from "./summaryPlugin";
|
|
21
23
|
import { tablePlugin } from "./tablePlugin";
|
|
22
24
|
import { PluginType } from "./types";
|
|
23
25
|
import { ulPlugin } from "./ulPlugin";
|
|
@@ -32,10 +34,12 @@ export const basePlugins: Record<string, PluginType> = {
|
|
|
32
34
|
table: tablePlugin,
|
|
33
35
|
aside: asidePlugin,
|
|
34
36
|
ul: ulPlugin,
|
|
35
|
-
dd: ddPlugin,
|
|
36
|
-
dt: dtPlugin,
|
|
37
37
|
nav: navPlugin,
|
|
38
38
|
a: anchorPlugin,
|
|
39
|
+
summary: summaryPlugin,
|
|
40
|
+
details: detailsPlugin,
|
|
41
|
+
dl: dlPlugin,
|
|
42
|
+
blockquote: blockquotePlugin,
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
export const oembedPlugins: Record<string, PluginType> = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024-present, NDLA.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the GPLv3 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,15 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { DOMNode, attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
-
import {
|
|
10
|
+
import { ExpandableBoxSummary } from "@ndla/primitives";
|
|
11
11
|
import { PluginType } from "./types";
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const summaryPlugin: PluginType = (node, converterOpts) => {
|
|
14
14
|
const props = attributesToProps(node.attribs);
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
|
-
<
|
|
18
|
-
{domToReact(node.children as DOMNode[], converterOpts)}
|
|
19
|
-
</DefinitionDescription>
|
|
17
|
+
<ExpandableBoxSummary {...props}>{domToReact(node.children as DOMNode[], converterOpts)}</ExpandableBoxSummary>
|
|
20
18
|
);
|
|
21
19
|
};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { DOMNode, attributesToProps, domToReact } from "html-react-parser";
|
|
10
|
-
import { Table } from "@ndla/
|
|
10
|
+
import { Table } from "@ndla/primitives";
|
|
11
11
|
import { PluginType } from "./types";
|
|
12
12
|
export const tablePlugin: PluginType = (node, converterOpts, opts) => {
|
|
13
13
|
const props = attributesToProps(node.attribs);
|