@ndla/article-converter 4.0.20 → 4.2.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.
@@ -15,6 +15,7 @@ export var audioEmbedPlugin = function audioEmbedPlugin(element, _, opts) {
15
15
  var data = JSON.parse(props['data-json']);
16
16
  return _jsx(AudioEmbed, {
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
+ lang: opts.articleLanguage
19
20
  });
20
21
  };
@@ -30,7 +30,7 @@ export var campaignBlockPlugin = function campaignBlockPlugin(element, _, opts)
30
30
  imageSide: embed.imageSide,
31
31
  image: data.status === 'success' && data.data.image ? {
32
32
  src: data.data.image.image.imageUrl,
33
- alt: embed.alt ? embed.alt : data.data.image.alttext.alttext
33
+ alt: embed.alt === undefined ? '' : embed.alt === '' ? data.data.image.alttext.alttext : embed.alt
34
34
  } : undefined
35
35
  });
36
36
  };
@@ -15,7 +15,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
15
15
  import { OrderedList } from '@ndla/ui';
16
16
  import { attributesToProps, domToReact } from 'html-react-parser';
17
17
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
18
- export var olPlugin = function olPlugin(node, opts) {
18
+ export var olPlugin = function olPlugin(node, converterOpts, opts) {
19
19
  var _node$attribs$class;
20
20
  var props = attributesToProps(node.attribs);
21
21
  var letterClass = node.attribs['data-type'] === 'letters' ? 'ol-list--roman' : false;
@@ -26,6 +26,7 @@ export var olPlugin = function olPlugin(node, opts) {
26
26
  }).join(' ');
27
27
  return _jsx(OrderedList, _objectSpread(_objectSpread({}, props), {}, {
28
28
  className: classes.length ? classes : undefined,
29
- children: domToReact(node.children, opts)
29
+ lang: opts.articleLanguage,
30
+ children: domToReact(node.children, converterOpts)
30
31
  }));
31
32
  };
@@ -14,18 +14,22 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
14
14
 
15
15
  import { attributesToProps, domToReact } from 'html-react-parser';
16
16
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
17
- export var paragraphPlugin = function paragraphPlugin(node, opts) {
17
+ export var paragraphPlugin = function paragraphPlugin(node, converterOpts, opts) {
18
+ var props = attributesToProps(node.attribs);
18
19
  if (node.attribs['data-align'] === 'center') {
19
20
  var _node$attribs$class;
20
- var props = attributesToProps(node.attribs);
21
21
  var classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', 'u-text-center'].filter(function (c) {
22
22
  return !!c;
23
23
  }).join(' ');
24
24
  return _jsx("p", _objectSpread(_objectSpread({}, props), {}, {
25
+ lang: opts.articleLanguage,
25
26
  "data-align": undefined,
26
27
  className: classes,
27
- children: domToReact(node.children, opts)
28
+ children: domToReact(node.children, converterOpts)
28
29
  }));
29
30
  }
30
- return null;
31
+ return _jsx("p", _objectSpread(_objectSpread({}, props), {}, {
32
+ lang: opts.articleLanguage,
33
+ children: domToReact(node.children, converterOpts)
34
+ }));
31
35
  };
@@ -15,7 +15,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
15
15
  import { UnOrderedList } from '@ndla/ui';
16
16
  import { attributesToProps, domToReact } from 'html-react-parser';
17
17
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
18
- export var ulPlugin = function ulPlugin(node, opts) {
18
+ export var ulPlugin = function ulPlugin(node, converterOpts, opts) {
19
19
  var _node$attribs$class;
20
20
  var props = attributesToProps(node.attribs);
21
21
  var classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', node.attribs['data-type'] === 'two-column' ? 'o-list--two-columns' : ''].filter(function (c) {
@@ -23,6 +23,7 @@ export var ulPlugin = function ulPlugin(node, opts) {
23
23
  }).join(' ');
24
24
  return _jsx(UnOrderedList, _objectSpread(_objectSpread({}, props), {}, {
25
25
  className: classes,
26
- children: domToReact(node.children, opts)
26
+ lang: opts.articleLanguage,
27
+ children: domToReact(node.children, converterOpts)
27
28
  }));
28
29
  };
@@ -21,7 +21,8 @@ var audioEmbedPlugin = function audioEmbedPlugin(element, _, opts) {
21
21
  var data = JSON.parse(props['data-json']);
22
22
  return (0, _jsxRuntime.jsx)(_ui.AudioEmbed, {
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
+ lang: opts.articleLanguage
25
26
  });
26
27
  };
27
28
  exports.audioEmbedPlugin = audioEmbedPlugin;
@@ -36,7 +36,7 @@ var campaignBlockPlugin = function campaignBlockPlugin(element, _, opts) {
36
36
  imageSide: embed.imageSide,
37
37
  image: data.status === 'success' && data.data.image ? {
38
38
  src: data.data.image.image.imageUrl,
39
- alt: embed.alt ? embed.alt : data.data.image.alttext.alttext
39
+ alt: embed.alt === undefined ? '' : embed.alt === '' ? data.data.image.alttext.alttext : embed.alt
40
40
  } : undefined
41
41
  });
42
42
  };
@@ -19,7 +19,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
19
19
  * LICENSE file in the root directory of this source tree.
20
20
  *
21
21
  */
22
- var olPlugin = function olPlugin(node, opts) {
22
+ var olPlugin = function olPlugin(node, converterOpts, opts) {
23
23
  var _node$attribs$class;
24
24
  var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
25
25
  var letterClass = node.attribs['data-type'] === 'letters' ? 'ol-list--roman' : false;
@@ -30,7 +30,8 @@ var olPlugin = function olPlugin(node, opts) {
30
30
  }).join(' ');
31
31
  return (0, _jsxRuntime.jsx)(_ui.OrderedList, _objectSpread(_objectSpread({}, props), {}, {
32
32
  className: classes.length ? classes : undefined,
33
- children: (0, _htmlReactParser.domToReact)(node.children, opts)
33
+ lang: opts.articleLanguage,
34
+ children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
34
35
  }));
35
36
  };
36
37
  exports.olPlugin = olPlugin;
@@ -18,19 +18,23 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
18
18
  * LICENSE file in the root directory of this source tree.
19
19
  *
20
20
  */
21
- var paragraphPlugin = function paragraphPlugin(node, opts) {
21
+ var paragraphPlugin = function paragraphPlugin(node, converterOpts, opts) {
22
+ var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
22
23
  if (node.attribs['data-align'] === 'center') {
23
24
  var _node$attribs$class;
24
- var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
25
25
  var classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', 'u-text-center'].filter(function (c) {
26
26
  return !!c;
27
27
  }).join(' ');
28
28
  return (0, _jsxRuntime.jsx)("p", _objectSpread(_objectSpread({}, props), {}, {
29
+ lang: opts.articleLanguage,
29
30
  "data-align": undefined,
30
31
  className: classes,
31
- children: (0, _htmlReactParser.domToReact)(node.children, opts)
32
+ children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
32
33
  }));
33
34
  }
34
- return null;
35
+ return (0, _jsxRuntime.jsx)("p", _objectSpread(_objectSpread({}, props), {}, {
36
+ lang: opts.articleLanguage,
37
+ children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
38
+ }));
35
39
  };
36
40
  exports.paragraphPlugin = paragraphPlugin;
@@ -18,5 +18,6 @@ export interface TransformOptions {
18
18
  previewAlt?: boolean;
19
19
  frontendDomain?: string;
20
20
  components?: DynamicComponents;
21
+ articleLanguage?: string;
21
22
  }
22
23
  export type PluginType = (element: Element, options: HTMLReactParserOptions, metaData: TransformOptions) => JSX.Element | undefined | null;
@@ -19,7 +19,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
19
19
  * LICENSE file in the root directory of this source tree.
20
20
  *
21
21
  */
22
- var ulPlugin = function ulPlugin(node, opts) {
22
+ var ulPlugin = function ulPlugin(node, converterOpts, opts) {
23
23
  var _node$attribs$class;
24
24
  var props = (0, _htmlReactParser.attributesToProps)(node.attribs);
25
25
  var classes = [(_node$attribs$class = node.attribs.class) !== null && _node$attribs$class !== void 0 ? _node$attribs$class : '', node.attribs['data-type'] === 'two-column' ? 'o-list--two-columns' : ''].filter(function (c) {
@@ -27,7 +27,8 @@ var ulPlugin = function ulPlugin(node, opts) {
27
27
  }).join(' ');
28
28
  return (0, _jsxRuntime.jsx)(_ui.UnOrderedList, _objectSpread(_objectSpread({}, props), {}, {
29
29
  className: classes,
30
- children: (0, _htmlReactParser.domToReact)(node.children, opts)
30
+ lang: opts.articleLanguage,
31
+ children: (0, _htmlReactParser.domToReact)(node.children, converterOpts)
31
32
  }));
32
33
  };
33
34
  exports.ulPlugin = ulPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndla/article-converter",
3
- "version": "4.0.20",
3
+ "version": "4.2.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,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@ndla/code": "^4.0.6",
34
- "@ndla/ui": "^46.0.1",
34
+ "@ndla/ui": "^46.1.0",
35
35
  "html-react-parser": "^3.0.8",
36
36
  "lodash": "^4.17.20"
37
37
  },
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "20b3005ca76e8857ef750373d836ecbd00fecc18"
47
+ "gitHead": "444537e1bc636e9ed92272c88da91c83932b9a53"
48
48
  }
@@ -14,5 +14,5 @@ import { PluginType } from '../types';
14
14
  export const audioEmbedPlugin: PluginType = (element, _, opts) => {
15
15
  const props = attributesToProps(element.attribs);
16
16
  const data = JSON.parse(props['data-json']) as AudioMetaData;
17
- return <AudioEmbed embed={data} heartButton={opts.components?.heartButton} />;
17
+ return <AudioEmbed embed={data} heartButton={opts.components?.heartButton} lang={opts.articleLanguage} />;
18
18
  };
@@ -15,6 +15,7 @@ export const campaignBlockPlugin: PluginType = (element, _, opts) => {
15
15
  const props = attributesToProps(element.attribs);
16
16
  const data = JSON.parse(props['data-json']) as CampaignBlockMetaData;
17
17
  const embed = data.embedData;
18
+
18
19
  return (
19
20
  <CampaignBlock
20
21
  title={{ title: embed.title, language: embed.titleLanguage }}
@@ -24,7 +25,10 @@ export const campaignBlockPlugin: PluginType = (element, _, opts) => {
24
25
  imageSide={embed.imageSide}
25
26
  image={
26
27
  data.status === 'success' && data.data.image
27
- ? { src: data.data.image.image.imageUrl, alt: embed.alt ? embed.alt : data.data.image.alttext.alttext }
28
+ ? {
29
+ src: data.data.image.image.imageUrl,
30
+ alt: embed.alt === undefined ? '' : embed.alt === '' ? data.data.image.alttext.alttext : embed.alt,
31
+ }
28
32
  : undefined
29
33
  }
30
34
  />
@@ -9,7 +9,7 @@
9
9
  import { OrderedList } from '@ndla/ui';
10
10
  import { attributesToProps, domToReact } from 'html-react-parser';
11
11
  import { PluginType } from './types';
12
- export const olPlugin: PluginType = (node, opts) => {
12
+ export const olPlugin: PluginType = (node, converterOpts, opts) => {
13
13
  const props = attributesToProps(node.attribs);
14
14
  const letterClass = node.attribs['data-type'] === 'letters' ? 'ol-list--roman' : false;
15
15
  const num = node.attribs['start'];
@@ -17,8 +17,8 @@ export const olPlugin: PluginType = (node, opts) => {
17
17
  const classes = [node.attribs.class ?? false, letterClass, numClass].filter((c): c is string => !!c).join(' ');
18
18
 
19
19
  return (
20
- <OrderedList {...props} className={classes.length ? classes : undefined}>
21
- {domToReact(node.children, opts)}
20
+ <OrderedList {...props} className={classes.length ? classes : undefined} lang={opts.articleLanguage}>
21
+ {domToReact(node.children, converterOpts)}
22
22
  </OrderedList>
23
23
  );
24
24
  };
@@ -8,16 +8,19 @@
8
8
 
9
9
  import { attributesToProps, domToReact } from 'html-react-parser';
10
10
  import { PluginType } from './types';
11
- export const paragraphPlugin: PluginType = (node, opts) => {
11
+ export const paragraphPlugin: PluginType = (node, converterOpts, opts) => {
12
+ const props = attributesToProps(node.attribs);
12
13
  if (node.attribs['data-align'] === 'center') {
13
- const props = attributesToProps(node.attribs);
14
14
  const classes = [node.attribs.class ?? '', 'u-text-center'].filter((c) => !!c).join(' ');
15
15
  return (
16
- <p {...props} data-align={undefined} className={classes}>
17
- {domToReact(node.children, opts)}
16
+ <p {...props} lang={opts.articleLanguage} data-align={undefined} className={classes}>
17
+ {domToReact(node.children, converterOpts)}
18
18
  </p>
19
19
  );
20
20
  }
21
-
22
- return null;
21
+ return (
22
+ <p {...props} lang={opts.articleLanguage}>
23
+ {domToReact(node.children, converterOpts)}
24
+ </p>
25
+ );
23
26
  };
@@ -20,6 +20,7 @@ export interface TransformOptions {
20
20
  previewAlt?: boolean;
21
21
  frontendDomain?: string;
22
22
  components?: DynamicComponents;
23
+ articleLanguage?: string;
23
24
  }
24
25
 
25
26
  export type PluginType = (
@@ -9,14 +9,14 @@
9
9
  import { UnOrderedList } from '@ndla/ui';
10
10
  import { attributesToProps, domToReact } from 'html-react-parser';
11
11
  import { PluginType } from './types';
12
- export const ulPlugin: PluginType = (node, opts) => {
12
+ export const ulPlugin: PluginType = (node, converterOpts, opts) => {
13
13
  const props = attributesToProps(node.attribs);
14
14
  const classes = [node.attribs.class ?? '', node.attribs['data-type'] === 'two-column' ? 'o-list--two-columns' : '']
15
15
  .filter((c) => !!c)
16
16
  .join(' ');
17
17
  return (
18
- <UnOrderedList {...props} className={classes}>
19
- {domToReact(node.children, opts)}
18
+ <UnOrderedList {...props} className={classes} lang={opts.articleLanguage}>
19
+ {domToReact(node.children, converterOpts)}
20
20
  </UnOrderedList>
21
21
  );
22
22
  };