✨(frontend) interlinking export
Create interlinking link mapping for docx and pdf export.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 338 B |
@@ -10,7 +10,7 @@ export const blockMappingParagraphPDF: DocsExporterPDF['mappings']['blockMapping
|
||||
*/
|
||||
if (Array.isArray(block.content)) {
|
||||
block.content.forEach((content) => {
|
||||
if (content.type === 'text' && !content.text) {
|
||||
if (content.type === 'text' && 'text' in content && !content.text) {
|
||||
content.text = ' ';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,11 +8,17 @@ export const blockMappingQuoteDocx: DocsExporterDocx['mappings']['blockMapping']
|
||||
if (Array.isArray(block.content)) {
|
||||
block.content.forEach((content) => {
|
||||
if (content.type === 'text') {
|
||||
content.styles = {
|
||||
...content.styles,
|
||||
italic: true,
|
||||
textColor: 'gray',
|
||||
};
|
||||
if (
|
||||
'styles' in content &&
|
||||
typeof content.styles === 'object' &&
|
||||
content.styles !== null
|
||||
) {
|
||||
content.styles = {
|
||||
...content.styles,
|
||||
italic: true,
|
||||
textColor: 'gray',
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './interlinkingLinkPDF';
|
||||
export * from './interlinkingLinkDocx';
|
||||
@@ -0,0 +1,16 @@
|
||||
import { ExternalHyperlink, TextRun } from 'docx';
|
||||
|
||||
import { DocsExporterDocx } from '../types';
|
||||
|
||||
export const inlineContentMappingInterlinkingLinkDocx: DocsExporterDocx['mappings']['inlineContentMapping']['interlinkingLinkInline'] =
|
||||
(inline) => {
|
||||
return new ExternalHyperlink({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: `📄${inline.props.title}`,
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
link: window.location.origin + inline.props.url,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/* eslint-disable jsx-a11y/alt-text */
|
||||
import { Image, Link, Text } from '@react-pdf/renderer';
|
||||
|
||||
import DocSelectedIcon from '../assets/doc-selected.png';
|
||||
import { DocsExporterPDF } from '../types';
|
||||
|
||||
export const inlineContentMappingInterlinkingLinkPDF: DocsExporterPDF['mappings']['inlineContentMapping']['interlinkingLinkInline'] =
|
||||
(inline) => {
|
||||
return (
|
||||
<Link
|
||||
src={window.location.origin + inline.props.url}
|
||||
style={{
|
||||
textDecoration: 'none',
|
||||
color: 'black',
|
||||
}}
|
||||
>
|
||||
{' '}
|
||||
<Image src={DocSelectedIcon.src} />{' '}
|
||||
<Text>{inline.props.title}</Text>{' '}
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { docxDefaultSchemaMappings } from '@blocknote/xl-docx-exporter';
|
||||
import { Paragraph } from 'docx';
|
||||
|
||||
import {
|
||||
blockMappingCalloutDocx,
|
||||
@@ -6,6 +7,7 @@ import {
|
||||
blockMappingImageDocx,
|
||||
blockMappingQuoteDocx,
|
||||
} from './blocks-mapping';
|
||||
import { inlineContentMappingInterlinkingLinkDocx } from './inline-content-mapping';
|
||||
import { DocsExporterDocx } from './types';
|
||||
|
||||
export const docxDocsSchemaMappings: DocsExporterDocx['mappings'] = {
|
||||
@@ -17,4 +19,9 @@ export const docxDocsSchemaMappings: DocsExporterDocx['mappings'] = {
|
||||
quote: blockMappingQuoteDocx,
|
||||
image: blockMappingImageDocx,
|
||||
},
|
||||
inlineContentMapping: {
|
||||
...docxDefaultSchemaMappings.inlineContentMapping,
|
||||
interlinkingSearchInline: () => new Paragraph(''),
|
||||
interlinkingLinkInline: inlineContentMappingInterlinkingLinkDocx,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
blockMappingQuotePDF,
|
||||
blockMappingTablePDF,
|
||||
} from './blocks-mapping';
|
||||
import { inlineContentMappingInterlinkingLinkPDF } from './inline-content-mapping';
|
||||
import { DocsExporterPDF } from './types';
|
||||
|
||||
export const pdfDocsSchemaMappings: DocsExporterPDF['mappings'] = {
|
||||
@@ -23,4 +24,9 @@ export const pdfDocsSchemaMappings: DocsExporterPDF['mappings'] = {
|
||||
quote: blockMappingQuotePDF,
|
||||
table: blockMappingTablePDF,
|
||||
},
|
||||
inlineContentMapping: {
|
||||
...pdfDefaultSchemaMappings.inlineContentMapping,
|
||||
interlinkingSearchInline: () => <></>,
|
||||
interlinkingLinkInline: inlineContentMappingInterlinkingLinkPDF,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user