Skip to content

Commit

Permalink
feat: add strikethrough support
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesRijckaert committed May 24, 2024
1 parent 3cf9a90 commit 5266126
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/rich-text-html-renderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ The `renderMark` keys should be one of the following `MARKS` properties as defin
- `CODE`
- `SUPERSCRIPT`
- `SUBSCRIPT`
- `STRIKETHROUGH`

#### Preserving Whitespace

Expand Down
4 changes: 4 additions & 0 deletions packages/rich-text-html-renderer/src/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ describe('documentToHtmlString', () => {
doc: marksDoc(MARKS.SUBSCRIPT),
expected: '<p><sub>hello world</sub></p>',
},
{
doc: marksDoc(MARKS.STRIKETHROUGH),
expected: '<p><s>hello world</s></p>',
},
];

docs.forEach(({ doc, expected }) => {
Expand Down
1 change: 1 addition & 0 deletions packages/rich-text-html-renderer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const defaultMarkRenderers: RenderMark = {
[MARKS.CODE]: (text) => `<code>${text}</code>`,
[MARKS.SUPERSCRIPT]: (text) => `<sup>${text}</sup>`,
[MARKS.SUBSCRIPT]: (text) => `<sub>${text}</sub>`,
[MARKS.STRIKETHROUGH]: (text) => `<s>${text}</s>`,
};

const defaultInline = (type: string, node: Inline) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ exports[`documentToReactComponents renders marks with default mark renderer 6`]
]
`;

exports[`documentToReactComponents renders marks with default mark renderer 7`] = `
[
<p>
<s>
hello world
</s>
</p>,
]
`;

exports[`documentToReactComponents renders marks with the passed custom mark renderer 1`] = `
[
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('documentToReactComponents', () => {
marksDoc(MARKS.CODE),
marksDoc(MARKS.SUPERSCRIPT),
marksDoc(MARKS.SUBSCRIPT),
marksDoc(MARKS.STRIKETHROUGH),
];

docs.forEach((doc) => {
Expand Down
1 change: 1 addition & 0 deletions packages/rich-text-react-renderer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const defaultMarkRenderers: RenderMark = {
[MARKS.CODE]: (text) => <code>{text}</code>,
[MARKS.SUPERSCRIPT]: (text) => <sup>{text}</sup>,
[MARKS.SUBSCRIPT]: (text) => <sub>{text}</sub>,
[MARKS.STRIKETHROUGH]: (text) => <s>{text}</s>,
};

function defaultInline(type: string, node: Inline): ReactNode {
Expand Down
1 change: 1 addition & 0 deletions packages/rich-text-types/src/marks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export enum MARKS {
CODE = 'code',
SUPERSCRIPT = 'superscript',
SUBSCRIPT = 'subscript',
STRIKETHROUGH = 'strikethrough',
}

0 comments on commit 5266126

Please sign in to comment.