@ndla/article-converter 5.1.7 → 6.0.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/anchorPlugin.js +27 -0
- package/es/plugins/asidePlugin.js +2 -2
- package/es/plugins/copyParagraphPlugin.js +2 -2
- package/es/plugins/divPlugin.js +3 -3
- package/es/plugins/embed/brightcoveEmbedPlugin.js +2 -1
- package/es/plugins/embed/fileEmbedPlugin.js +2 -2
- package/es/plugins/embed/imageEmbedPlugin.js +2 -1
- package/es/plugins/index.js +5 -3
- package/es/plugins/oembed/anchorPlugin.js +8 -2
- package/lib/plugins/anchorPlugin.d.ts +9 -0
- package/lib/plugins/anchorPlugin.js +33 -0
- package/lib/plugins/asidePlugin.js +1 -1
- package/lib/plugins/copyParagraphPlugin.js +1 -1
- package/lib/plugins/divPlugin.js +2 -2
- package/lib/plugins/embed/brightcoveEmbedPlugin.js +2 -1
- package/lib/plugins/embed/fileEmbedPlugin.js +1 -1
- package/lib/plugins/embed/imageEmbedPlugin.js +2 -1
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/oembed/anchorPlugin.js +9 -2
- package/lib/plugins/types.d.ts +2 -1
- package/package.json +4 -4
- package/src/plugins/anchorPlugin.tsx +23 -0
- package/src/plugins/asidePlugin.tsx +2 -2
- package/src/plugins/copyParagraphPlugin.tsx +3 -3
- package/src/plugins/divPlugin.tsx +4 -4
- package/src/plugins/embed/brightcoveEmbedPlugin.tsx +1 -1
- package/src/plugins/embed/fileEmbedPlugin.tsx +2 -2
- package/src/plugins/embed/imageEmbedPlugin.tsx +1 -0
- package/src/plugins/index.ts +4 -2
- package/src/plugins/oembed/anchorPlugin.tsx +7 -3
- package/src/plugins/types.ts +2 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) 2023-present, NDLA.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
16
|
+
import SafeLink from '@ndla/safelink';
|
|
17
|
+
import { getPossiblyRelativeUrl } from '@ndla/ui';
|
|
18
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
19
|
+
export var anchorPlugin = function anchorPlugin(node, opts, _ref) {
|
|
20
|
+
var path = _ref.path;
|
|
21
|
+
var props = attributesToProps(node.attribs);
|
|
22
|
+
var href = getPossiblyRelativeUrl(props.href, path);
|
|
23
|
+
return _jsx(SafeLink, _objectSpread(_objectSpread({}, props), {}, {
|
|
24
|
+
to: href,
|
|
25
|
+
children: domToReact(node.children, opts)
|
|
26
|
+
}));
|
|
27
|
+
};
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { domToReact } from 'html-react-parser';
|
|
10
|
-
import { Aside,
|
|
10
|
+
import { Aside, FactBox } from '@ndla/ui';
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export var asidePlugin = function asidePlugin(node, opts) {
|
|
13
13
|
if (node.attribs['data-type'] === 'factAside') {
|
|
14
|
-
return _jsx(
|
|
14
|
+
return _jsx(FactBox, {
|
|
15
15
|
children: domToReact(node.children, opts)
|
|
16
16
|
});
|
|
17
17
|
} else if (node.attribs['data-type'] === 'rightAside') {
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { CopyParagraphButton } from '@ndla/ui';
|
|
10
10
|
import { domToReact } from 'html-react-parser';
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export var copyParagraphPlugin = function copyParagraphPlugin(node, converterOpts, opts) {
|
|
13
13
|
var _parent$attribs;
|
|
14
14
|
var parent = node.parent;
|
|
15
15
|
if ((parent === null || parent === void 0 ? void 0 : parent.name) === 'section' || (parent === null || parent === void 0 ? void 0 : parent.name) === 'div' && Object.keys((_parent$attribs = parent.attribs) !== null && _parent$attribs !== void 0 ? _parent$attribs : {}).length === 0) {
|
|
16
|
-
return _jsx(
|
|
16
|
+
return _jsx(CopyParagraphButton, {
|
|
17
17
|
copyText: node.attribs['data-text'],
|
|
18
18
|
lang: opts.articleLanguage,
|
|
19
19
|
children: domToReact(node.children, converterOpts)
|
package/es/plugins/divPlugin.js
CHANGED
|
@@ -20,14 +20,14 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
20
20
|
|
|
21
21
|
import partition from 'lodash/partition';
|
|
22
22
|
import { domToReact, attributesToProps } from 'html-react-parser';
|
|
23
|
-
import {
|
|
23
|
+
import { FileList, RelatedArticleList, Grid, GridParallaxItem } from '@ndla/ui';
|
|
24
24
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
25
25
|
import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
26
26
|
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
27
27
|
export var divPlugin = function divPlugin(node, opts) {
|
|
28
28
|
if (node.attribs['data-type'] === 'related-content' && node.children.length) {
|
|
29
29
|
var props = attributesToProps(node.attribs);
|
|
30
|
-
return _jsx(
|
|
30
|
+
return _jsx(RelatedArticleList, _objectSpread(_objectSpread({}, props), {}, {
|
|
31
31
|
headingLevel: "h3",
|
|
32
32
|
children: domToReact(node.children, opts)
|
|
33
33
|
}));
|
|
@@ -42,7 +42,7 @@ export var divPlugin = function divPlugin(node, opts) {
|
|
|
42
42
|
pdfs = _partition2[0],
|
|
43
43
|
files = _partition2[1];
|
|
44
44
|
return _jsxs(_Fragment, {
|
|
45
|
-
children: [files.length ? _jsx(
|
|
45
|
+
children: [files.length ? _jsx(FileList, {
|
|
46
46
|
children: domToReact(files, opts)
|
|
47
47
|
}) : undefined, domToReact(pdfs, opts)]
|
|
48
48
|
});
|
|
@@ -15,6 +15,7 @@ export var brightcoveEmbedPlugin = function brightcoveEmbedPlugin(element, _, op
|
|
|
15
15
|
var data = JSON.parse(props['data-json']);
|
|
16
16
|
return _jsx(BrightcoveEmbed, {
|
|
17
17
|
embed: data,
|
|
18
|
-
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
|
|
18
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
19
|
+
renderContext: opts.renderContext
|
|
19
20
|
});
|
|
20
21
|
};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps } from 'html-react-parser';
|
|
10
|
-
import { PdfFile,
|
|
10
|
+
import { PdfFile, File } from '@ndla/ui';
|
|
11
11
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
12
12
|
export var fileEmbedPlugin = function fileEmbedPlugin(element) {
|
|
13
13
|
var props = attributesToProps(element.attribs);
|
|
@@ -23,7 +23,7 @@ export var fileEmbedPlugin = function fileEmbedPlugin(element) {
|
|
|
23
23
|
url: url
|
|
24
24
|
});
|
|
25
25
|
} else {
|
|
26
|
-
return _jsx(
|
|
26
|
+
return _jsx(File, {
|
|
27
27
|
url: url,
|
|
28
28
|
title: title,
|
|
29
29
|
fileExists: data.status === 'success' ? !!data.data.exists : false,
|
|
@@ -20,6 +20,7 @@ export var imageEmbedPlugin = function imageEmbedPlugin(element, _, opts) {
|
|
|
20
20
|
path: opts.path,
|
|
21
21
|
previewAlt: opts.previewAlt,
|
|
22
22
|
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
23
|
-
lang: opts.articleLanguage
|
|
23
|
+
lang: opts.articleLanguage,
|
|
24
|
+
renderContext: opts.renderContext
|
|
24
25
|
});
|
|
25
26
|
};
|
package/es/plugins/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { paragraphPlugin } from './paragraphPlugin';
|
|
|
18
18
|
import { spanPlugin } from './spanPlugin';
|
|
19
19
|
import { h3Plugin } from './h3Plugin';
|
|
20
20
|
import { mathPlugin } from './mathPlugin';
|
|
21
|
-
import { anchorPlugin } from './oembed/anchorPlugin';
|
|
21
|
+
import { anchorPlugin as oembedAnchorPlugin } from './oembed/anchorPlugin';
|
|
22
22
|
import { divPlugin } from './divPlugin';
|
|
23
23
|
import { tablePlugin } from './tablePlugin';
|
|
24
24
|
import { asidePlugin } from './asidePlugin';
|
|
@@ -26,6 +26,7 @@ import { ulPlugin } from './ulPlugin';
|
|
|
26
26
|
import { ddPlugin } from './ddPlugin';
|
|
27
27
|
import { dtPlugin } from './dtPlugin';
|
|
28
28
|
import { navPlugin } from './navPlugin';
|
|
29
|
+
import { anchorPlugin } from './anchorPlugin';
|
|
29
30
|
export var basePlugins = {
|
|
30
31
|
h2: copyParagraphPlugin,
|
|
31
32
|
h3: h3Plugin,
|
|
@@ -39,8 +40,9 @@ export var basePlugins = {
|
|
|
39
40
|
ul: ulPlugin,
|
|
40
41
|
dd: ddPlugin,
|
|
41
42
|
dt: dtPlugin,
|
|
42
|
-
nav: navPlugin
|
|
43
|
+
nav: navPlugin,
|
|
44
|
+
a: anchorPlugin
|
|
43
45
|
};
|
|
44
46
|
export var oembedPlugins = _objectSpread(_objectSpread({}, basePlugins), {}, {
|
|
45
|
-
a:
|
|
47
|
+
a: oembedAnchorPlugin
|
|
46
48
|
});
|
|
@@ -13,11 +13,17 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
16
|
+
import { getPossiblyRelativeUrl } from '@ndla/ui';
|
|
17
|
+
import SafeLink from '@ndla/safelink';
|
|
16
18
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
17
|
-
export var anchorPlugin = function anchorPlugin(node, options) {
|
|
19
|
+
export var anchorPlugin = function anchorPlugin(node, options, _ref) {
|
|
20
|
+
var path = _ref.path;
|
|
18
21
|
var props = attributesToProps(node.attribs);
|
|
19
|
-
|
|
22
|
+
var href = getPossiblyRelativeUrl(props.href, path);
|
|
23
|
+
return _jsx(SafeLink, _objectSpread(_objectSpread({}, props), {}, {
|
|
20
24
|
target: "_blank",
|
|
25
|
+
to: href,
|
|
26
|
+
rel: "noreferrer",
|
|
21
27
|
children: domToReact(node.children, options)
|
|
22
28
|
}));
|
|
23
29
|
};
|
|
@@ -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,33 @@
|
|
|
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 _safelink = _interopRequireDefault(require("@ndla/safelink"));
|
|
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 _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /**
|
|
18
|
+
* Copyright (c) 2023-present, NDLA.
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
21
|
+
* LICENSE file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
var anchorPlugin = function anchorPlugin(node, opts, _ref) {
|
|
25
|
+
var path = _ref.path;
|
|
26
|
+
var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
27
|
+
var href = (0, _ui.getPossiblyRelativeUrl)(props.href, path);
|
|
28
|
+
return (0, _jsxRuntime.jsx)(_safelink.default, _objectSpread(_objectSpread({}, props), {}, {
|
|
29
|
+
to: href,
|
|
30
|
+
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
exports.anchorPlugin = anchorPlugin;
|
|
@@ -17,7 +17,7 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
17
17
|
|
|
18
18
|
var asidePlugin = function asidePlugin(node, opts) {
|
|
19
19
|
if (node.attribs['data-type'] === 'factAside') {
|
|
20
|
-
return (0, _jsxRuntime.jsx)(_ui.
|
|
20
|
+
return (0, _jsxRuntime.jsx)(_ui.FactBox, {
|
|
21
21
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
22
22
|
});
|
|
23
23
|
} else if (node.attribs['data-type'] === 'rightAside') {
|
|
@@ -19,7 +19,7 @@ var copyParagraphPlugin = function copyParagraphPlugin(node, converterOpts, opts
|
|
|
19
19
|
var _parent$attribs;
|
|
20
20
|
var parent = node.parent;
|
|
21
21
|
if ((parent === null || parent === void 0 ? void 0 : parent.name) === 'section' || (parent === null || parent === void 0 ? void 0 : parent.name) === 'div' && Object.keys((_parent$attribs = parent.attribs) !== null && _parent$attribs !== void 0 ? _parent$attribs : {}).length === 0) {
|
|
22
|
-
return (0, _jsxRuntime.jsx)(_ui.
|
|
22
|
+
return (0, _jsxRuntime.jsx)(_ui.CopyParagraphButton, {
|
|
23
23
|
copyText: node.attribs['data-text'],
|
|
24
24
|
lang: opts.articleLanguage,
|
|
25
25
|
children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
|
package/lib/plugins/divPlugin.js
CHANGED
|
@@ -30,7 +30,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
30
30
|
var divPlugin = function divPlugin(node, opts) {
|
|
31
31
|
if (node.attribs['data-type'] === 'related-content' && node.children.length) {
|
|
32
32
|
var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
33
|
-
return (0, _jsxRuntime.jsx)(_ui.
|
|
33
|
+
return (0, _jsxRuntime.jsx)(_ui.RelatedArticleList, _objectSpread(_objectSpread({}, props), {}, {
|
|
34
34
|
headingLevel: "h3",
|
|
35
35
|
children: (0, _htmlReactParser.domToReact)(node.children, opts)
|
|
36
36
|
}));
|
|
@@ -45,7 +45,7 @@ var divPlugin = function divPlugin(node, opts) {
|
|
|
45
45
|
pdfs = _partition2[0],
|
|
46
46
|
files = _partition2[1];
|
|
47
47
|
return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
48
|
-
children: [files.length ? (0, _jsxRuntime.jsx)(_ui.
|
|
48
|
+
children: [files.length ? (0, _jsxRuntime.jsx)(_ui.FileList, {
|
|
49
49
|
children: (0, _htmlReactParser.domToReact)(files, opts)
|
|
50
50
|
}) : undefined, (0, _htmlReactParser.domToReact)(pdfs, opts)]
|
|
51
51
|
});
|
|
@@ -21,7 +21,8 @@ var brightcoveEmbedPlugin = function brightcoveEmbedPlugin(element, _, opts) {
|
|
|
21
21
|
var data = JSON.parse(props['data-json']);
|
|
22
22
|
return (0, _jsxRuntime.jsx)(_ui.BrightcoveEmbed, {
|
|
23
23
|
embed: data,
|
|
24
|
-
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton
|
|
24
|
+
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
25
|
+
renderContext: opts.renderContext
|
|
25
26
|
});
|
|
26
27
|
};
|
|
27
28
|
exports.brightcoveEmbedPlugin = brightcoveEmbedPlugin;
|
|
@@ -29,7 +29,7 @@ var fileEmbedPlugin = function fileEmbedPlugin(element) {
|
|
|
29
29
|
url: url
|
|
30
30
|
});
|
|
31
31
|
} else {
|
|
32
|
-
return (0, _jsxRuntime.jsx)(_ui.
|
|
32
|
+
return (0, _jsxRuntime.jsx)(_ui.File, {
|
|
33
33
|
url: url,
|
|
34
34
|
title: title,
|
|
35
35
|
fileExists: data.status === 'success' ? !!data.data.exists : false,
|
|
@@ -26,7 +26,8 @@ var imageEmbedPlugin = function imageEmbedPlugin(element, _, opts) {
|
|
|
26
26
|
path: opts.path,
|
|
27
27
|
previewAlt: opts.previewAlt,
|
|
28
28
|
heartButton: (_opts$components = opts.components) === null || _opts$components === void 0 ? void 0 : _opts$components.heartButton,
|
|
29
|
-
lang: opts.articleLanguage
|
|
29
|
+
lang: opts.articleLanguage,
|
|
30
|
+
renderContext: opts.renderContext
|
|
30
31
|
});
|
|
31
32
|
};
|
|
32
33
|
exports.imageEmbedPlugin = imageEmbedPlugin;
|
package/lib/plugins/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var _ulPlugin = require("./ulPlugin");
|
|
|
18
18
|
var _ddPlugin = require("./ddPlugin");
|
|
19
19
|
var _dtPlugin = require("./dtPlugin");
|
|
20
20
|
var _navPlugin = require("./navPlugin");
|
|
21
|
+
var _anchorPlugin2 = require("./anchorPlugin");
|
|
21
22
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
22
23
|
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; }
|
|
23
24
|
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; }
|
|
@@ -43,7 +44,8 @@ var basePlugins = {
|
|
|
43
44
|
ul: _ulPlugin.ulPlugin,
|
|
44
45
|
dd: _ddPlugin.ddPlugin,
|
|
45
46
|
dt: _dtPlugin.dtPlugin,
|
|
46
|
-
nav: _navPlugin.navPlugin
|
|
47
|
+
nav: _navPlugin.navPlugin,
|
|
48
|
+
a: _anchorPlugin2.anchorPlugin
|
|
47
49
|
};
|
|
48
50
|
exports.basePlugins = basePlugins;
|
|
49
51
|
var oembedPlugins = _objectSpread(_objectSpread({}, basePlugins), {}, {
|
|
@@ -5,7 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.anchorPlugin = void 0;
|
|
7
7
|
var _htmlReactParser = require("html-react-parser");
|
|
8
|
+
var _ui = require("@ndla/ui");
|
|
9
|
+
var _safelink = _interopRequireDefault(require("@ndla/safelink"));
|
|
8
10
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
12
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
13
|
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
14
|
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; }
|
|
@@ -18,10 +21,14 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
18
21
|
* LICENSE file in the root directory of this source tree.
|
|
19
22
|
*
|
|
20
23
|
*/
|
|
21
|
-
var anchorPlugin = function anchorPlugin(node, options) {
|
|
24
|
+
var anchorPlugin = function anchorPlugin(node, options, _ref) {
|
|
25
|
+
var path = _ref.path;
|
|
22
26
|
var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
|
|
23
|
-
|
|
27
|
+
var href = (0, _ui.getPossiblyRelativeUrl)(props.href, path);
|
|
28
|
+
return (0, _jsxRuntime.jsx)(_safelink.default, _objectSpread(_objectSpread({}, props), {}, {
|
|
24
29
|
target: "_blank",
|
|
30
|
+
to: href,
|
|
31
|
+
rel: "noreferrer",
|
|
25
32
|
children: (0, _htmlReactParser.domToReact)(node.children, options)
|
|
26
33
|
}));
|
|
27
34
|
};
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
/// <reference types="react" />
|
|
9
|
-
import { HeartButtonType } from '@ndla/ui';
|
|
9
|
+
import { HeartButtonType, RenderContext } from '@ndla/ui';
|
|
10
10
|
import { Element, HTMLReactParserOptions } from 'html-react-parser';
|
|
11
11
|
export interface DynamicComponents {
|
|
12
12
|
heartButton?: HeartButtonType;
|
|
@@ -19,5 +19,6 @@ export interface TransformOptions {
|
|
|
19
19
|
frontendDomain?: string;
|
|
20
20
|
components?: DynamicComponents;
|
|
21
21
|
articleLanguage?: string;
|
|
22
|
+
renderContext?: RenderContext;
|
|
22
23
|
}
|
|
23
24
|
export type PluginType = (element: Element, options: HTMLReactParserOptions, metaData: TransformOptions) => JSX.Element | undefined | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/article-converter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Transforms NDLA articles into extended html versions",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@ndla/types-embed": "^4.0.5"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ndla/code": "^5.0.
|
|
34
|
-
"@ndla/ui": "^
|
|
33
|
+
"@ndla/code": "^5.0.10",
|
|
34
|
+
"@ndla/ui": "^49.0.1",
|
|
35
35
|
"html-react-parser": "^4.2.2",
|
|
36
36
|
"lodash": "^4.17.20"
|
|
37
37
|
},
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "613a1b7bd697142fdcee7cca42c743f4c2431a40"
|
|
48
48
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
10
|
+
import SafeLink from '@ndla/safelink';
|
|
11
|
+
import { getPossiblyRelativeUrl } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from './types';
|
|
13
|
+
|
|
14
|
+
export const anchorPlugin: PluginType = (node, opts, { path }) => {
|
|
15
|
+
const props = attributesToProps(node.attribs);
|
|
16
|
+
const href = getPossiblyRelativeUrl(props.href, path);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<SafeLink {...props} to={href}>
|
|
20
|
+
{domToReact(node.children, opts)}
|
|
21
|
+
</SafeLink>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { domToReact } from 'html-react-parser';
|
|
10
|
-
import { Aside,
|
|
10
|
+
import { Aside, FactBox } from '@ndla/ui';
|
|
11
11
|
import { PluginType } from './types';
|
|
12
12
|
export const asidePlugin: PluginType = (node, opts) => {
|
|
13
13
|
if (node.attribs['data-type'] === 'factAside') {
|
|
14
|
-
return <
|
|
14
|
+
return <FactBox>{domToReact(node.children, opts)}</FactBox>;
|
|
15
15
|
} else if (node.attribs['data-type'] === 'rightAside') {
|
|
16
16
|
return (
|
|
17
17
|
<Aside wideScreen alwaysShow>
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { CopyParagraphButton } from '@ndla/ui';
|
|
10
10
|
import { Element, domToReact } from 'html-react-parser';
|
|
11
11
|
import { PluginType } from './types';
|
|
12
12
|
export const copyParagraphPlugin: PluginType = (node, converterOpts, opts) => {
|
|
13
13
|
const parent = node.parent as Element | undefined;
|
|
14
14
|
if (parent?.name === 'section' || (parent?.name === 'div' && Object.keys(parent.attribs ?? {}).length === 0)) {
|
|
15
15
|
return (
|
|
16
|
-
<
|
|
16
|
+
<CopyParagraphButton copyText={node.attribs['data-text']} lang={opts.articleLanguage}>
|
|
17
17
|
{domToReact(node.children, converterOpts)}
|
|
18
|
-
</
|
|
18
|
+
</CopyParagraphButton>
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
return null;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import partition from 'lodash/partition';
|
|
10
10
|
import { domToReact, attributesToProps, Element } from 'html-react-parser';
|
|
11
|
-
import {
|
|
11
|
+
import { FileList, RelatedArticleList, Grid, GridType, GridParallaxItem } from '@ndla/ui';
|
|
12
12
|
import { PluginType } from './types';
|
|
13
13
|
|
|
14
14
|
export const divPlugin: PluginType = (node, opts) => {
|
|
@@ -16,10 +16,10 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
16
16
|
const props = attributesToProps(node.attribs);
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
|
-
<
|
|
19
|
+
<RelatedArticleList {...props} headingLevel="h3">
|
|
20
20
|
{/* @ts-ignore */}
|
|
21
21
|
{domToReact(node.children, opts)}
|
|
22
|
-
</
|
|
22
|
+
</RelatedArticleList>
|
|
23
23
|
);
|
|
24
24
|
} else if (node.attribs['data-type'] === 'file' && node.childNodes.length) {
|
|
25
25
|
const elements = node.childNodes.filter(
|
|
@@ -32,7 +32,7 @@ export const divPlugin: PluginType = (node, opts) => {
|
|
|
32
32
|
|
|
33
33
|
return (
|
|
34
34
|
<>
|
|
35
|
-
{files.length ? <
|
|
35
|
+
{files.length ? <FileList>{domToReact(files, opts)}</FileList> : undefined}
|
|
36
36
|
{domToReact(pdfs, opts)}
|
|
37
37
|
</>
|
|
38
38
|
);
|
|
@@ -14,5 +14,5 @@ import { PluginType } from '../types';
|
|
|
14
14
|
export const brightcoveEmbedPlugin: PluginType = (element, _, opts) => {
|
|
15
15
|
const props = attributesToProps(element.attribs);
|
|
16
16
|
const data = JSON.parse(props['data-json']) as BrightcoveMetaData;
|
|
17
|
-
return <BrightcoveEmbed embed={data} heartButton={opts.components?.heartButton} />;
|
|
17
|
+
return <BrightcoveEmbed embed={data} heartButton={opts.components?.heartButton} renderContext={opts.renderContext} />;
|
|
18
18
|
};
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { attributesToProps } from 'html-react-parser';
|
|
10
10
|
import { FileMetaData } from '@ndla/types-embed';
|
|
11
|
-
import { PdfFile,
|
|
11
|
+
import { PdfFile, File } from '@ndla/ui';
|
|
12
12
|
import { PluginType } from '../types';
|
|
13
13
|
|
|
14
14
|
export const fileEmbedPlugin: PluginType = (element) => {
|
|
@@ -19,7 +19,7 @@ export const fileEmbedPlugin: PluginType = (element) => {
|
|
|
19
19
|
return <PdfFile title={title} url={url} />;
|
|
20
20
|
} else {
|
|
21
21
|
return (
|
|
22
|
-
<
|
|
22
|
+
<File
|
|
23
23
|
url={url}
|
|
24
24
|
title={title}
|
|
25
25
|
fileExists={data.status === 'success' ? !!data.data.exists : false}
|
package/src/plugins/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { paragraphPlugin } from './paragraphPlugin';
|
|
|
13
13
|
import { spanPlugin } from './spanPlugin';
|
|
14
14
|
import { h3Plugin } from './h3Plugin';
|
|
15
15
|
import { mathPlugin } from './mathPlugin';
|
|
16
|
-
import { anchorPlugin } from './oembed/anchorPlugin';
|
|
16
|
+
import { anchorPlugin as oembedAnchorPlugin } from './oembed/anchorPlugin';
|
|
17
17
|
import { divPlugin } from './divPlugin';
|
|
18
18
|
import { tablePlugin } from './tablePlugin';
|
|
19
19
|
import { asidePlugin } from './asidePlugin';
|
|
@@ -21,6 +21,7 @@ import { ulPlugin } from './ulPlugin';
|
|
|
21
21
|
import { ddPlugin } from './ddPlugin';
|
|
22
22
|
import { dtPlugin } from './dtPlugin';
|
|
23
23
|
import { navPlugin } from './navPlugin';
|
|
24
|
+
import { anchorPlugin } from './anchorPlugin';
|
|
24
25
|
|
|
25
26
|
export const basePlugins: Record<string, PluginType> = {
|
|
26
27
|
h2: copyParagraphPlugin,
|
|
@@ -36,9 +37,10 @@ export const basePlugins: Record<string, PluginType> = {
|
|
|
36
37
|
dd: ddPlugin,
|
|
37
38
|
dt: dtPlugin,
|
|
38
39
|
nav: navPlugin,
|
|
40
|
+
a: anchorPlugin,
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
export const oembedPlugins: Record<string, PluginType> = {
|
|
42
44
|
...basePlugins,
|
|
43
|
-
a:
|
|
45
|
+
a: oembedAnchorPlugin,
|
|
44
46
|
};
|
|
@@ -7,12 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
10
|
+
import { getPossiblyRelativeUrl } from '@ndla/ui';
|
|
11
|
+
import SafeLink from '@ndla/safelink';
|
|
10
12
|
import { PluginType } from '../types';
|
|
11
|
-
|
|
13
|
+
|
|
14
|
+
export const anchorPlugin: PluginType = (node, options, { path }) => {
|
|
12
15
|
const props = attributesToProps(node.attribs);
|
|
16
|
+
const href = getPossiblyRelativeUrl(props.href, path);
|
|
13
17
|
return (
|
|
14
|
-
<
|
|
18
|
+
<SafeLink {...props} target="_blank" to={href} rel="noreferrer">
|
|
15
19
|
{domToReact(node.children, options)}
|
|
16
|
-
</
|
|
20
|
+
</SafeLink>
|
|
17
21
|
);
|
|
18
22
|
};
|
package/src/plugins/types.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { HeartButtonType } from '@ndla/ui';
|
|
9
|
+
import { HeartButtonType, RenderContext } from '@ndla/ui';
|
|
10
10
|
import { Element, HTMLReactParserOptions } from 'html-react-parser';
|
|
11
11
|
|
|
12
12
|
export interface DynamicComponents {
|
|
@@ -21,6 +21,7 @@ export interface TransformOptions {
|
|
|
21
21
|
frontendDomain?: string;
|
|
22
22
|
components?: DynamicComponents;
|
|
23
23
|
articleLanguage?: string;
|
|
24
|
+
renderContext?: RenderContext;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export type PluginType = (
|