diff --git a/app/slate-to-html/docs/fixtures/default.ts b/app/slate-to-html/docs/fixtures/default.ts new file mode 100644 index 0000000..23a1b2d --- /dev/null +++ b/app/slate-to-html/docs/fixtures/default.ts @@ -0,0 +1,26 @@ +export const defaultExampleSlate = [ + { + children: [ + { + text: 'Heading 1', + }, + ], + type: 'h1', + }, + { + children: [ + { + text: 'Paragraph 1', + }, + ], + type: 'p', + }, +] + +export const defaultExample = ` +import { slateToHtml } from '@slate-serializers/html' + +const slate = ${JSON.stringify(defaultExampleSlate, undefined, 2)} + +const serializedToHtml = slateToHtml(slate) +` diff --git a/app/slate-to-html/docs/fixtures/elementMap.ts b/app/slate-to-html/docs/fixtures/elementMap.ts new file mode 100644 index 0000000..fe68200 --- /dev/null +++ b/app/slate-to-html/docs/fixtures/elementMap.ts @@ -0,0 +1,35 @@ +export const elementMapExampleSlate = [ + { + type: 'h1', + children: [ + { + text: 'Heading 1', + }, + ], + }, + { + type: 'heading-one', + children: [ + { + text: 'Heading 1 (identified with our custom type)', + }, + ], + }, +] + +export const elementMapExample = ` +import { slateToHtml, payloadSlateToHtmlConfig } from '@slate-serializers/html' + +const slate = ${JSON.stringify(elementMapExampleSlate, undefined, 2)} + +const config = { + ...slateToHtmlConfig, + elementMap: { + // default configuration includes 'h1' + ...slateToHtmlConfig.elementMap, + ['heading-one']: 'h1', + }, +} + +const serializedToHtml = slateToHtml(slate, config) +` diff --git a/app/slate-to-html/docs/fixtures/markMap.ts b/app/slate-to-html/docs/fixtures/markMap.ts new file mode 100644 index 0000000..bfda5f4 --- /dev/null +++ b/app/slate-to-html/docs/fixtures/markMap.ts @@ -0,0 +1,27 @@ +export const markMapExampleSlate = [{ + type: 'p', + children: [ + { + text: 'Subscript and bold text', + bold: true, + subScript: true, + }, + ], +}] + +export const markMapExample = ` +import { slateToHtml, payloadSlateToHtmlConfig } from '@slate-serializers/html' + +const slate = ${JSON.stringify(markMapExampleSlate, undefined, 2)} + +const config = { + ...slateToHtmlConfig, + markMap: { + // bold already in default configuration + ...slateToHtmlConfig.markMap, + subScript: ['sub'], + }, +} + +const serializedToHtml = slateToHtml(slate, config) +` diff --git a/app/slate-to-html/docs/fixtures/payload.ts b/app/slate-to-html/docs/fixtures/payload.ts new file mode 100644 index 0000000..e470554 --- /dev/null +++ b/app/slate-to-html/docs/fixtures/payload.ts @@ -0,0 +1,18 @@ +export const payloadExampleSlate = [ + { + children: [ + { + text: 'Heading 1', + }, + ], + type: 'h1', + }, +] + +export const payloadExample = ` +import { slateToHtml, payloadSlateToHtmlConfig } from '@slate-serializers/html' + +const slate = ${JSON.stringify(payloadExampleSlate, undefined, 2)} + +const serializedToHtml = slateToHtml(slate, payloadSlateToHtmlConfig) +` diff --git a/app/slate-to-html/docs/page.tsx b/app/slate-to-html/docs/page.tsx index 15f519e..486a17f 100644 --- a/app/slate-to-html/docs/page.tsx +++ b/app/slate-to-html/docs/page.tsx @@ -1,6 +1,98 @@ import { Code } from "bright" +import { slateToHtml, slateToHtmlConfig, payloadSlateToHtmlConfig } from '@slate-serializers/html' +import { ghUrl } from "@/app/utilities/docs" + +// fixtures +import { defaultExample, defaultExampleSlate } from "./fixtures/default" +import { markMapExample, markMapExampleSlate } from "./fixtures/markMap" +import { payloadExample, payloadExampleSlate } from "./fixtures/payload" +import { elementMapExample, elementMapExampleSlate } from "./fixtures/elementMap" export default function Page() { // eslint-disable-next-line react/no-unescaped-entities - return print("hello brightness") + return
+

slateToHtml

+ + All output.html file content on this page is generated with serializers. + +

Default

+ +

By default, slateToHtml incorporates transformation rules based on the example in Deserializing | Serializing | Slate.

+ +
+ {defaultExample} + {slateToHtml(defaultExampleSlate)} +
+ +

Configuration

+ +

Slate JS has a schema-less core. It makes few assumptions the schema of the data you will be transforming. See Principles | Introduction | Slate

+ +

As a result, it is likely that you will need to create your own configuration file that implements your schema.

+ +

Starting point

+ + + +
+ Payload CMS +

If you are using Payload CMS, import the Payload configuration file and pass it as a parameter to the serializer.

+
+ {payloadExample} + {slateToHtml(payloadExampleSlate, payloadSlateToHtmlConfig)} +
+
+ +

Options

+ +

markMap

+ +

Map Slate JSON properties to HTML formatting element tags.

+ + + +
+ {markMapExample} + {slateToHtml(markMapExampleSlate, { + ...slateToHtmlConfig, + markMap: { + // bold already in default configuration + ...slateToHtmlConfig.markMap, + subScript: ['sub'], + }, + })} +
+ +

elementMap

+ +

Map Slate JSON type values to HTML element tags.

+ + + +
+ {elementMapExample} + {slateToHtml(elementMapExampleSlate, { + ...slateToHtmlConfig, + elementMap: { + // default configuration includes 'h1' + ...slateToHtmlConfig.elementMap, + ['heading-one']: 'h1', + }, + })} +
+ +

+ +
} diff --git a/app/utilities/docs.ts b/app/utilities/docs.ts new file mode 100644 index 0000000..b3f48e3 --- /dev/null +++ b/app/utilities/docs.ts @@ -0,0 +1,3 @@ +const GITHUB_MAIN_ROOT = `https://github.com/thompsonsj/slate-serializers/blob/main/` + +export const ghUrl = (relativePath: string) => new URL(relativePath, GITHUB_MAIN_ROOT).href;