Files
gitbook/src/components/DocumentView/CodeBlock/PlainCodeBlock.tsx
T
Samy Pessé 1e1d202b5a Improve PDF export for tabs/expandables/api blocks (#204)
* Fix integrations blocks and text being too long

* Fix size of code blocks

* Open expandable by default on print mode

* Render tabs one after the other

* Adjust colors

* Open all in openapi when printing

* Fix title

* Format

* Fix TS
2024-02-29 19:49:03 +01:00

55 lines
1.3 KiB
TypeScript

import { DocumentBlockCode, JSONDocument } from '@gitbook/api';
import { CodeBlock } from './CodeBlock';
/**
* Plain code block with syntax highlighting.
* For simplicity, this is just a wrapper around the CodeBlock component, emulating a document.
*/
export function PlainCodeBlock(props: { code: string; syntax: string }) {
const { code, syntax } = props;
const block: DocumentBlockCode = {
object: 'block',
type: 'code',
data: {
syntax,
},
nodes: code.split('\n').map((line) => ({
object: 'block',
type: 'code-line',
data: {},
nodes: [
{
object: 'text',
leaves: [
{
object: 'leaf',
text: line,
marks: [],
},
],
},
],
})),
};
const document: JSONDocument = {
object: 'document',
data: {},
nodes: [block],
};
return (
<CodeBlock
document={document}
context={{
mode: 'default',
resolveContentRef: async () => null,
}}
block={block}
ancestorBlocks={[]}
/>
);
}