Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export elements functions #107

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-lions-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphcms/rich-text-html-renderer': minor
---

Export `defaultElements`
35 changes: 1 addition & 34 deletions examples/content-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ export const content: RichTextContent = {
type: 'heading-two',
children: [{ text: 'Awesome new Hygraph cap!' }],
},
{
src: 'https://media.graphassets.com/bFyCrmvuQfO7n0l5ZmH5',
type: 'image',
title: 'logo.svg',
width: 0,
handle: 'mQeGmwkXTnqTfcgUXVr7',
height: 0,
children: [
{
text: '',
},
],
mimeType: 'image/svg+xml',
},
{
type: 'paragraph',
children: [
Expand Down Expand Up @@ -88,19 +74,9 @@ export const content: RichTextContent = {
type: 'code-block',
children: [
{
text: 'const graph = \'cms\'\n\n<?php $echo "Hello" ?>',
},
],
},
{
type: 'embed',
nodeId: 'cknjbzowggjo90b91kjisy03a',
children: [
{
text: '',
text: 'const hy = \'graph\'\n\n<?php $echo "Hello" ?>',
},
],
nodeType: 'Asset',
},
{
type: 'embed',
Expand Down Expand Up @@ -146,15 +122,6 @@ export const content: RichTextContent = {
};

export const references: EmbedReferences = [
{
id: 'cknjbzowggjo90b91kjisy03a',
handle: 'dsQtt0ARqO28baaXbVy9',
fileName: 'nkkwzgz0bw6fg6mqzjc1.png',
height: 690,
width: 880,
url: 'https://media.graphassets.com/dsQtt0ARqO28baaXbVy9',
mimeType: 'image/png',
},
{
id: 'ckrus0f14ao760b32mz2dwvgx',
handle: '7M0lXLdCQfeIDXnT2SVS',
Expand Down
20 changes: 20 additions & 0 deletions packages/html-renderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ const html = astToHtmlString({
});
```

If needed, you can also import the `defaultElements` from the package and use it as a base for your custom renderers.

```js
import {
astToHtmlString,
defaultElements,
} from '@graphcms/rich-text-html-renderer';

const content = {
/* ... */
};

const html = astToHtmlString({
content: inlineContent,
renderers: {
bold: props => defaultElements.bold(props),
},
});
```

Below you can check the full list of elements you can customize, alongside the props available for each of them.

- `a`
Expand Down
1 change: 1 addition & 0 deletions packages/html-renderer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,5 @@ export function astToHtmlString({
}).join('');
}

export { defaultElements } from './defaultElements';
export * from './types';
Loading