@ndla/article-converter 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/es/extractEmbedMeta.js +17 -0
- package/es/index.js +10 -0
- package/es/plugins/AsidePlugin.js +25 -0
- package/es/plugins/CopyParagraphPlugin.js +17 -0
- package/es/plugins/DivPlugin.js +48 -0
- package/es/plugins/H3Plugin.js +23 -0
- package/es/plugins/MathPlugin.js +18 -0
- package/es/plugins/OLPlugin.js +28 -0
- package/es/plugins/ParagraphPlugin.js +28 -0
- package/es/plugins/SpanPlugin.js +25 -0
- package/es/plugins/TablePlugin.js +20 -0
- package/es/plugins/ULPlugin.js +28 -0
- package/es/plugins/embed/AudioEmbedPlugin.js +19 -0
- package/es/plugins/embed/BrightcoveEmbedPlugin.js +18 -0
- package/es/plugins/embed/CodeEmbedPlugin.js +18 -0
- package/es/plugins/embed/ConceptEmbedPlugin.js +19 -0
- package/es/plugins/embed/ConceptListEmbedPlugin.js +18 -0
- package/es/plugins/embed/ContentLinkEmbedPlugin.js +20 -0
- package/es/plugins/embed/ExternalEmbedPlugin.js +18 -0
- package/es/plugins/embed/FileEmbedPlugin.js +33 -0
- package/es/plugins/embed/FootnoteEmbedPlugin.js +18 -0
- package/es/plugins/embed/H5pEmbedPlugin.js +18 -0
- package/es/plugins/embed/IframeEmbedPlugin.js +18 -0
- package/es/plugins/embed/ImageEmbedPlugin.js +20 -0
- package/es/plugins/embed/RelatedContentEmbedPlugin.js +20 -0
- package/es/plugins/embed/index.js +36 -0
- package/es/plugins/index.js +35 -0
- package/es/plugins/oembed/AnchorPlugin.js +20 -0
- package/es/plugins/types.js +1 -0
- package/es/transform.js +39 -0
- package/lib/extractEmbedMeta.d.ts +10 -0
- package/lib/extractEmbedMeta.js +25 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +20 -0
- package/lib/plugins/AsidePlugin.d.ts +9 -0
- package/lib/plugins/AsidePlugin.js +32 -0
- package/lib/plugins/CopyParagraphPlugin.d.ts +9 -0
- package/lib/plugins/CopyParagraphPlugin.js +24 -0
- package/lib/plugins/DivPlugin.d.ts +9 -0
- package/lib/plugins/DivPlugin.js +46 -0
- package/lib/plugins/H3Plugin.d.ts +9 -0
- package/lib/plugins/H3Plugin.js +22 -0
- package/lib/plugins/MathPlugin.d.ts +9 -0
- package/lib/plugins/MathPlugin.js +25 -0
- package/lib/plugins/OLPlugin.d.ts +9 -0
- package/lib/plugins/OLPlugin.js +27 -0
- package/lib/plugins/ParagraphPlugin.d.ts +9 -0
- package/lib/plugins/ParagraphPlugin.js +27 -0
- package/lib/plugins/SpanPlugin.d.ts +9 -0
- package/lib/plugins/SpanPlugin.js +24 -0
- package/lib/plugins/TablePlugin.d.ts +9 -0
- package/lib/plugins/TablePlugin.js +19 -0
- package/lib/plugins/ULPlugin.d.ts +9 -0
- package/lib/plugins/ULPlugin.js +27 -0
- package/lib/plugins/embed/AudioEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/AudioEmbedPlugin.js +26 -0
- package/lib/plugins/embed/BrightcoveEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/BrightcoveEmbedPlugin.js +25 -0
- package/lib/plugins/embed/CodeEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/CodeEmbedPlugin.js +25 -0
- package/lib/plugins/embed/ConceptEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/ConceptEmbedPlugin.js +26 -0
- package/lib/plugins/embed/ConceptListEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/ConceptListEmbedPlugin.js +25 -0
- package/lib/plugins/embed/ContentLinkEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/ContentLinkEmbedPlugin.js +27 -0
- package/lib/plugins/embed/ExternalEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/ExternalEmbedPlugin.js +25 -0
- package/lib/plugins/embed/FileEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/FileEmbedPlugin.js +40 -0
- package/lib/plugins/embed/FootnoteEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/FootnoteEmbedPlugin.js +25 -0
- package/lib/plugins/embed/H5pEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/H5pEmbedPlugin.js +25 -0
- package/lib/plugins/embed/IframeEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/IframeEmbedPlugin.js +25 -0
- package/lib/plugins/embed/ImageEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/ImageEmbedPlugin.js +27 -0
- package/lib/plugins/embed/RelatedContentEmbedPlugin.d.ts +9 -0
- package/lib/plugins/embed/RelatedContentEmbedPlugin.js +27 -0
- package/lib/plugins/embed/index.d.ts +9 -0
- package/lib/plugins/embed/index.js +43 -0
- package/lib/plugins/index.d.ts +10 -0
- package/lib/plugins/index.js +35 -0
- package/lib/plugins/oembed/AnchorPlugin.d.ts +9 -0
- package/lib/plugins/oembed/AnchorPlugin.js +19 -0
- package/lib/plugins/types.d.ts +17 -0
- package/lib/plugins/types.js +5 -0
- package/lib/transform.d.ts +11 -0
- package/lib/transform.js +47 -0
- package/package.json +48 -0
- package/src/extractEmbedMeta.ts +21 -0
- package/src/index.ts +11 -0
- package/src/plugins/AsidePlugin.tsx +24 -0
- package/src/plugins/CopyParagraphPlugin.tsx +18 -0
- package/src/plugins/DivPlugin.tsx +40 -0
- package/src/plugins/H3Plugin.tsx +19 -0
- package/src/plugins/MathPlugin.tsx +14 -0
- package/src/plugins/OLPlugin.tsx +23 -0
- package/src/plugins/ParagraphPlugin.tsx +23 -0
- package/src/plugins/SpanPlugin.tsx +22 -0
- package/src/plugins/TablePlugin.tsx +15 -0
- package/src/plugins/ULPlugin.tsx +23 -0
- package/src/plugins/embed/AudioEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/BrightcoveEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/CodeEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/ConceptEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/ConceptListEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/ContentLinkEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/ExternalEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/FileEmbedPlugin.tsx +31 -0
- package/src/plugins/embed/FootnoteEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/H5pEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/IframeEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/ImageEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/RelatedContentEmbedPlugin.tsx +18 -0
- package/src/plugins/embed/index.ts +38 -0
- package/src/plugins/index.ts +36 -0
- package/src/plugins/oembed/AnchorPlugin.tsx +18 -0
- package/src/plugins/types.ts +23 -0
- package/src/transform.tsx +41 -0
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ndla/article-converter",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Transforms NDLA articles into extended html versions",
|
|
5
|
+
"license": "GPL-3.0",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "es/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "yarn build:types",
|
|
12
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
13
|
+
"prepublish": "yarn build"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/NDLANO/frontend-packages.git",
|
|
18
|
+
"directory": "packages/article-converter"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"ndla"
|
|
22
|
+
],
|
|
23
|
+
"author": "ndla@knowit.no",
|
|
24
|
+
"files": [
|
|
25
|
+
"lib",
|
|
26
|
+
"es",
|
|
27
|
+
"src"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@ndla/types-embed": "^1.0.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@ndla/code": "^2.1.18",
|
|
34
|
+
"@ndla/ui": "^34.6.3",
|
|
35
|
+
"html-react-parser": "^3.0.8",
|
|
36
|
+
"lodash": "^4.17.20"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@emotion/react": "^11.10.4",
|
|
40
|
+
"@emotion/styled": "^11.10.4",
|
|
41
|
+
"react": "^16.9.0 || ^17.0.0",
|
|
42
|
+
"react-i18next": "^11.18.6"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "3be4405a57a209633f9e8534b5f208ab50bae6f0"
|
|
48
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 parse from 'html-react-parser';
|
|
10
|
+
import { EmbedMetaData } from '@ndla/types-embed';
|
|
11
|
+
|
|
12
|
+
const extractEmbedMeta = (embed: string): EmbedMetaData | undefined => {
|
|
13
|
+
const node = parse(embed);
|
|
14
|
+
if (typeof node === 'string' || Array.isArray(node) || node.type !== 'ndlaembed' || !node.props['data-json']) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return JSON.parse(node.props['data-json']) as EmbedMetaData;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default extractEmbedMeta;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2023-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export { default as transform } from './transform';
|
|
10
|
+
export { default as extractEmbedMeta } from './extractEmbedMeta';
|
|
11
|
+
export type { TransformOptions } from './plugins/types';
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { domToReact } from 'html-react-parser';
|
|
10
|
+
import { Aside, FactBoxV2 } from '@ndla/ui';
|
|
11
|
+
import { PluginType } from './types';
|
|
12
|
+
export const AsidePlugin: PluginType = (node, opts) => {
|
|
13
|
+
if (node.attribs['data-type'] === 'factAside') {
|
|
14
|
+
return <FactBoxV2>{domToReact(node.children, opts)}</FactBoxV2>;
|
|
15
|
+
} else if (node.attribs['data-type'] === 'rightAside') {
|
|
16
|
+
return (
|
|
17
|
+
<Aside wideScreen alwaysShow>
|
|
18
|
+
{domToReact(node.children, opts)}
|
|
19
|
+
</Aside>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { CopyParagraphButtonV2 } from '@ndla/ui';
|
|
10
|
+
import { domToReact } from 'html-react-parser';
|
|
11
|
+
import { PluginType } from './types';
|
|
12
|
+
export const CopyParagraphPlugin: PluginType = (node, opts) => {
|
|
13
|
+
return (
|
|
14
|
+
<CopyParagraphButtonV2 copyText={node.attribs['data-text']}>
|
|
15
|
+
{domToReact(node.children, opts)}
|
|
16
|
+
</CopyParagraphButtonV2>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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 partition from 'lodash/partition';
|
|
10
|
+
import { domToReact, attributesToProps, Element } from 'html-react-parser';
|
|
11
|
+
import { FileListV2, RelatedArticleListV2 } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from './types';
|
|
13
|
+
export const DivPlugin: PluginType = (node, opts) => {
|
|
14
|
+
if (node.attribs['data-type'] === 'related-content' && node.children.length) {
|
|
15
|
+
const props = attributesToProps(node.attribs);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<RelatedArticleListV2 {...props} headingLevel="h3">
|
|
19
|
+
{/* @ts-ignore */}
|
|
20
|
+
{domToReact(node.children, opts)}
|
|
21
|
+
</RelatedArticleListV2>
|
|
22
|
+
);
|
|
23
|
+
} else if (node.attribs['data-type'] === 'file' && node.childNodes.length) {
|
|
24
|
+
const elements = node.childNodes.filter(
|
|
25
|
+
(c): c is Element => c.type === 'tag' && c.name === 'ndlaembed' && c.attribs['data-resource'] === 'file',
|
|
26
|
+
);
|
|
27
|
+
const [pdfs, files] = partition(
|
|
28
|
+
elements,
|
|
29
|
+
(el) => el.attribs['data-type'] === 'pdf' && el.attribs['data-display'] === 'block',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
{files.length ? <FileListV2>{domToReact(files, opts)}</FileListV2> : undefined}
|
|
35
|
+
{domToReact(pdfs, opts)}
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { PluginType } from './types';
|
|
11
|
+
export const H3Plugin: PluginType = (node, opts) => {
|
|
12
|
+
const props = attributesToProps(node.attribs);
|
|
13
|
+
return (
|
|
14
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
15
|
+
<h3 {...props} tabIndex={0}>
|
|
16
|
+
{domToReact(node.children, opts)}
|
|
17
|
+
</h3>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { PluginType } from './types';
|
|
11
|
+
export const MathPlugin: PluginType = (node) => {
|
|
12
|
+
const props = attributesToProps(node.attribs);
|
|
13
|
+
return <span dangerouslySetInnerHTML={{ __html: `<math display="block">${props['data-math']}</math>` }} />;
|
|
14
|
+
};
|
|
@@ -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 { PluginType } from './types';
|
|
11
|
+
export const OLPlugin: PluginType = (node, opts) => {
|
|
12
|
+
const props = attributesToProps(node.attribs);
|
|
13
|
+
const letterClass = node.attribs['data-type'] === 'letters' ? 'ol-list--roman' : false;
|
|
14
|
+
const num = node.attribs['start'];
|
|
15
|
+
const numClass = num ? `ol-reset-${num}` : false;
|
|
16
|
+
const classes = [node.attribs.class ?? false, letterClass, numClass].filter((c): c is string => !!c).join(' ');
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ol {...props} data-type={undefined} className={classes.length ? classes : undefined}>
|
|
20
|
+
{domToReact(node.children, opts)}
|
|
21
|
+
</ol>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -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 { PluginType } from './types';
|
|
11
|
+
export const ParagraphPlugin: PluginType = (node, opts) => {
|
|
12
|
+
if (node.attribs['data-align'] === 'center') {
|
|
13
|
+
const props = attributesToProps(node.attribs);
|
|
14
|
+
const classes = [node.attribs.class ?? '', 'u-text-center'].filter((c) => !!c).join(' ');
|
|
15
|
+
return (
|
|
16
|
+
<p {...props} data-align={undefined} className={classes}>
|
|
17
|
+
{domToReact(node.children, opts)}
|
|
18
|
+
</p>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { PluginType } from './types';
|
|
11
|
+
export const SpanPlugin: PluginType = (node, opts) => {
|
|
12
|
+
if (node.attribs['data-size'] === 'large') {
|
|
13
|
+
const props = attributesToProps(node.attribs);
|
|
14
|
+
return (
|
|
15
|
+
<span {...props} data-size={undefined} className={`${node.attribs.class ?? ''} u-large-body-text`}>
|
|
16
|
+
{domToReact(node.children, opts)}
|
|
17
|
+
</span>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { Table } from '@ndla/ui';
|
|
10
|
+
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
11
|
+
import { PluginType } from './types';
|
|
12
|
+
export const TablePlugin: PluginType = (node, opts) => {
|
|
13
|
+
const props = attributesToProps(node.attribs);
|
|
14
|
+
return <Table {...props}>{domToReact(node.children, opts)}</Table>;
|
|
15
|
+
};
|
|
@@ -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 { PluginType } from './types';
|
|
11
|
+
export const OLPlugin: PluginType = (node, opts) => {
|
|
12
|
+
if (node.attribs['data-type'] === 'two-column') {
|
|
13
|
+
const props = attributesToProps(node.attribs);
|
|
14
|
+
const classes = [node.attribs.class ?? '', 'o-list--two-columns'].filter((c) => !!c).join(' ');
|
|
15
|
+
return (
|
|
16
|
+
<ul {...props} data-type={undefined} className={classes}>
|
|
17
|
+
{domToReact(node.children, opts)}
|
|
18
|
+
</ul>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { AudioMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { AudioEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const AudioEmbedPlugin: PluginType = (element, _, opts) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as AudioMetaData;
|
|
17
|
+
return <AudioEmbed embed={data} articlePath={opts.path} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { BrightcoveMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { BrightcoveEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const BrightcoveEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as BrightcoveMetaData;
|
|
17
|
+
return <BrightcoveEmbed embed={data} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { CodeMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { CodeEmbed } from '@ndla/code';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const CodeEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as CodeMetaData;
|
|
17
|
+
return <CodeEmbed embed={data} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { ConceptMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { ConceptEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const ConceptEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as ConceptMetaData;
|
|
17
|
+
return <ConceptEmbed embed={data} fullWidth />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { ConceptListMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { ConceptListEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const ConceptListEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as ConceptListMetaData;
|
|
17
|
+
return <ConceptListEmbed embed={data} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { ContentLinkMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { ContentLinkEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const ContentLinkEmbedPlugin: PluginType = (element, _, { isOembed }) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as ContentLinkMetaData;
|
|
17
|
+
return <ContentLinkEmbed embed={data} isOembed={isOembed} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { OembedMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { ExternalEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const ExternalEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as OembedMetaData;
|
|
17
|
+
return <ExternalEmbed embed={data} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { FileMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { PdfFile, FileV2 } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const FileEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as FileMetaData;
|
|
17
|
+
const { type, title, url } = data.embedData;
|
|
18
|
+
if (type === 'pdf') {
|
|
19
|
+
return <PdfFile title={title} url={url} />;
|
|
20
|
+
} else {
|
|
21
|
+
return (
|
|
22
|
+
<FileV2
|
|
23
|
+
id={`file-${data.seq}`}
|
|
24
|
+
url={url}
|
|
25
|
+
title={title}
|
|
26
|
+
fileExists={data.status === 'success' ? !!data.data.exists : false}
|
|
27
|
+
fileType={type}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { FootnoteMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { FootnoteEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const FootnoteEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as FootnoteMetaData;
|
|
17
|
+
return <FootnoteEmbed embed={data} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { H5pMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { H5pEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const H5pEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as H5pMetaData;
|
|
17
|
+
return <H5pEmbed embed={data} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { IframeMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { IframeEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const IframeEmbedPlugin: PluginType = (element) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as IframeMetaData;
|
|
17
|
+
return <IframeEmbed embed={data} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { ImageEmbed } from '@ndla/ui';
|
|
10
|
+
import { attributesToProps } from 'html-react-parser';
|
|
11
|
+
import { ImageMetaData } from '@ndla/types-embed';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const ImageEmbedPlugin: PluginType = (element, _, opts) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as ImageMetaData;
|
|
17
|
+
return <ImageEmbed embed={data} articlePath={opts.path} previewAlt={opts.previewAlt} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 } from 'html-react-parser';
|
|
10
|
+
import { RelatedContentMetaData } from '@ndla/types-embed';
|
|
11
|
+
import { RelatedContentEmbed } from '@ndla/ui';
|
|
12
|
+
import { PluginType } from '../types';
|
|
13
|
+
|
|
14
|
+
export const RelatedContentEmbedPlugin: PluginType = (element, _, opts) => {
|
|
15
|
+
const props = attributesToProps(element.attribs);
|
|
16
|
+
const data = JSON.parse(props['data-json']) as RelatedContentMetaData;
|
|
17
|
+
return <RelatedContentEmbed embed={data} subject={opts.subject} ndlaFrontendDomain={opts.frontendDomain} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { PluginType } from '../types';
|
|
10
|
+
import { AudioEmbedPlugin } from './AudioEmbedPlugin';
|
|
11
|
+
import { ExternalEmbedPlugin } from './ExternalEmbedPlugin';
|
|
12
|
+
import { H5pEmbedPlugin } from './H5pEmbedPlugin';
|
|
13
|
+
import { IframeEmbedPlugin } from './IframeEmbedPlugin';
|
|
14
|
+
import { ImageEmbedPlugin } from './ImageEmbedPlugin';
|
|
15
|
+
import { FootnoteEmbedPlugin } from './FootnoteEmbedPlugin';
|
|
16
|
+
import { BrightcoveEmbedPlugin } from './BrightcoveEmbedPlugin';
|
|
17
|
+
import { RelatedContentEmbedPlugin } from './RelatedContentEmbedPlugin';
|
|
18
|
+
import { ContentLinkEmbedPlugin } from './ContentLinkEmbedPlugin';
|
|
19
|
+
import { ConceptEmbedPlugin } from './ConceptEmbedPlugin';
|
|
20
|
+
import { ConceptListEmbedPlugin } from './ConceptListEmbedPlugin';
|
|
21
|
+
import { FileEmbedPlugin } from './FileEmbedPlugin';
|
|
22
|
+
import { CodeEmbedPlugin } from './CodeEmbedPlugin';
|
|
23
|
+
|
|
24
|
+
export const embedPlugins: Record<string, PluginType> = {
|
|
25
|
+
image: ImageEmbedPlugin,
|
|
26
|
+
audio: AudioEmbedPlugin,
|
|
27
|
+
h5p: H5pEmbedPlugin,
|
|
28
|
+
'code-block': CodeEmbedPlugin,
|
|
29
|
+
external: ExternalEmbedPlugin,
|
|
30
|
+
iframe: IframeEmbedPlugin,
|
|
31
|
+
footnote: FootnoteEmbedPlugin,
|
|
32
|
+
brightcove: BrightcoveEmbedPlugin,
|
|
33
|
+
'related-content': RelatedContentEmbedPlugin,
|
|
34
|
+
'content-link': ContentLinkEmbedPlugin,
|
|
35
|
+
concept: ConceptEmbedPlugin,
|
|
36
|
+
'concept-list': ConceptListEmbedPlugin,
|
|
37
|
+
file: FileEmbedPlugin,
|
|
38
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { CopyParagraphPlugin } from './CopyParagraphPlugin';
|
|
10
|
+
import { PluginType } from './types';
|
|
11
|
+
import { OLPlugin } from './OLPlugin';
|
|
12
|
+
import { ParagraphPlugin } from './ParagraphPlugin';
|
|
13
|
+
import { SpanPlugin } from './SpanPlugin';
|
|
14
|
+
import { H3Plugin } from './H3Plugin';
|
|
15
|
+
import { MathPlugin } from './MathPlugin';
|
|
16
|
+
import { AnchorPlugin } from './oembed/AnchorPlugin';
|
|
17
|
+
import { DivPlugin } from './DivPlugin';
|
|
18
|
+
import { TablePlugin } from './TablePlugin';
|
|
19
|
+
import { AsidePlugin } from './AsidePlugin';
|
|
20
|
+
|
|
21
|
+
export const basePlugins: Record<string, PluginType> = {
|
|
22
|
+
h2: CopyParagraphPlugin,
|
|
23
|
+
h3: H3Plugin,
|
|
24
|
+
ol: OLPlugin,
|
|
25
|
+
p: ParagraphPlugin,
|
|
26
|
+
span: SpanPlugin,
|
|
27
|
+
math: MathPlugin,
|
|
28
|
+
div: DivPlugin,
|
|
29
|
+
table: TablePlugin,
|
|
30
|
+
aside: AsidePlugin,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const oembedPlugins: Record<string, PluginType> = {
|
|
34
|
+
...basePlugins,
|
|
35
|
+
a: AnchorPlugin,
|
|
36
|
+
};
|