@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
|
@@ -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, domToReact } from 'html-react-parser';
|
|
10
|
+
import { PluginType } from '../types';
|
|
11
|
+
export const AnchorPlugin: PluginType = (node, options) => {
|
|
12
|
+
const props = attributesToProps(node.attribs);
|
|
13
|
+
return (
|
|
14
|
+
<a {...props} target="_blank">
|
|
15
|
+
{domToReact(node.children, options)}
|
|
16
|
+
</a>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -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 { Element, HTMLReactParserOptions } from 'html-react-parser';
|
|
10
|
+
|
|
11
|
+
export interface TransformOptions {
|
|
12
|
+
isOembed?: boolean;
|
|
13
|
+
subject?: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
previewAlt?: boolean;
|
|
16
|
+
frontendDomain?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type PluginType = (
|
|
20
|
+
element: Element,
|
|
21
|
+
options: HTMLReactParserOptions,
|
|
22
|
+
metaData: TransformOptions,
|
|
23
|
+
) => JSX.Element | undefined | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
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, { HTMLReactParserOptions } from 'html-react-parser';
|
|
10
|
+
import { UnknownEmbed } from '@ndla/ui';
|
|
11
|
+
import { MetaData } from '@ndla/types-embed';
|
|
12
|
+
import { basePlugins, oembedPlugins } from './plugins';
|
|
13
|
+
import { TransformOptions } from './plugins/types';
|
|
14
|
+
import { embedPlugins } from './plugins/embed';
|
|
15
|
+
|
|
16
|
+
const transform = (content: string, opts: TransformOptions) => {
|
|
17
|
+
const plugins = opts?.isOembed ? oembedPlugins : basePlugins;
|
|
18
|
+
const options: HTMLReactParserOptions = {
|
|
19
|
+
replace: (node) => {
|
|
20
|
+
if (!('attribs' in node)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (plugins[node.name]) {
|
|
24
|
+
return plugins[node.name](node, options, opts);
|
|
25
|
+
}
|
|
26
|
+
if (node.name === 'ndlaembed') {
|
|
27
|
+
if (embedPlugins[node.attribs['data-resource']]) {
|
|
28
|
+
return embedPlugins[node.attribs['data-resource']](node, options, opts);
|
|
29
|
+
} else {
|
|
30
|
+
const embed = JSON.parse(node.attribs['data-json']) as MetaData<any, any>;
|
|
31
|
+
return <UnknownEmbed embed={embed} />;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const replaced = parse(content, options);
|
|
37
|
+
|
|
38
|
+
return replaced;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default transform;
|