forked from Doist/typist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(serializers): Add
get*
functions for reusable singular instanc…
…es (Doist#88) * feat(serializers): Add `get*` functions for reusable singular instances * Remove `id` parameter requirement from `get*` functions Instead of an explicit `id` parameter to map a serializer to a given schema, the ID is now computed based on marks and nodes names available in the given schema. The ID will end up being a **very long string*, but this should never be a problem, because JavaScript object keys support very long strings: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length#description * chore: Update JSDoc for the `get*` functions * test: Add a couple of tests for each serializer new `get*` function * docs: Add Storybook documentation page for serializers * chore: Add missing JSDoc and tests for `computeSchemaId` function
- Loading branch information
Showing
12 changed files
with
183 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Serializers | ||
|
||
Unfortunately, Tiptap doesn't support Markdown as an input or output format, and while support for Markdown was considered, the Tiptap team decided against it (more information [here](https://tiptap.dev/guide/output#not-an-option-markdown)). However, at Doist, Markdown is a must, and that's why we implemented both an HTML and Markdown serializer to convert between both formats. | ||
|
||
Although the serializers are mostly meant to be used internally by the `TypistEditor` component and/or internal extensions, it's sometimes useful to have access to the same serializers externally for custom extensions. With that in mind, the `create*Serializer` and `get*Serializer` methods are publicly exported for both the HTML and Markdown serializers. | ||
|
||
## `get*Serializer` | ||
|
||
This function is the one everyone should be using most of the time because once a serializer is created for the first time, it will be cached and reused the next time this function is called. You shouldn't worry about using this function for multiple editors loaded with different extensions because the cache mechanism caches multiple serializers based on the given editor `schema`. | ||
|
||
## `create*Serializer` | ||
|
||
This function is the one that actually creates the serializer instance, and while it's used internally by the `get*Serializer` function, it's also available for public comsumption in the event of a very specific use case where it might be useful. Most of the time you should not need to call this function directly, but you should know that a new serializer instance will be created every time you do call this function directly, and you may incur in a small performance penalty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Meta } from '@storybook/addon-docs' | ||
|
||
import { MarkdownRenderer } from '../../components/markdown-renderer.tsx' | ||
|
||
import rawSerializers from './serializers.md?raw' | ||
|
||
<Meta | ||
title="Documentation/Reference/Serializers" | ||
parameters={{ | ||
viewMode: 'docs', | ||
options: { | ||
isToolshown: false, | ||
}, | ||
}} | ||
/> | ||
|
||
<MarkdownRenderer markdown={rawSerializers} /> |