Skip to content

Commit

Permalink
refactor: Replace HTML serializer with the unified ecosystem
Browse files Browse the repository at this point in the history
  • Loading branch information
rfgamaral committed May 30, 2023
1 parent d609bc6 commit 7734a54
Show file tree
Hide file tree
Showing 19 changed files with 1,026 additions and 803 deletions.
750 changes: 517 additions & 233 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
"@testing-library/dom": "9.3.0",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@types/hast": "2.3.4",
"@types/lodash-es": "4.17.7",
"@types/marked": "4.3.1",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"@types/react-syntax-highlighter": "15.5.6",
Expand Down Expand Up @@ -127,8 +127,6 @@
"react-icons": "4.8.0",
"react-markdown": "8.0.7",
"react-syntax-highlighter": "15.5.0",
"rehype-raw": "6.1.1",
"remark-gfm": "3.0.1",
"rimraf": "5.0.1",
"semantic-release": "21.0.2",
"storybook": "7.0.17",
Expand All @@ -141,10 +139,24 @@
"peerDependencies": {
"@react-hookz/web": "^14.2.3 || >=15.x",
"emoji-regex": "^10.2.1",
"hast-util-is-element": "^2.1.0",
"lodash-es": "^4.17.21",
"marked": "^4.1.1",
"mdast-util-gfm-strikethrough": "^1.0.0",
"micromark-extension-gfm-strikethrough": "^1.0.0",
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0",
"turndown": "^7.1.1"
"rehype": "^12.0.0",
"rehype-minify-whitespace": "^5.0.0",
"rehype-raw": "^6.1.0",
"rehype-stringify": "^9.0.0",
"remark": "^14.0.0",
"remark-breaks": "^3.0.0",
"remark-gfm": "^3.0.0",
"remark-rehype": "^10.1.0",
"turndown": "^7.1.0",
"unified": "^10.1.0",
"unist-util-is": "^5.2.0",
"unist-util-remove": "^3.1.0",
"unist-util-visit": "^4.1.0"
}
}
13 changes: 13 additions & 0 deletions src/helpers/unified.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { isTextNode } from './unified'

describe('Helper: Unified', () => {
describe('#isTextNode', () => {
test('returns `true` when the given node is a hast text node', () => {
expect(isTextNode({ type: 'text' })).toBe(true)
})

test('returns `false` when the given node is NOT a hast text node', () => {
expect(isTextNode({ type: 'element' })).toBe(false)
})
})
})
16 changes: 16 additions & 0 deletions src/helpers/unified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { is } from 'unist-util-is'

import type { Node, Text } from 'hast'

/**
* Check if a given node is a unist text node.
*
* @param node The node to check.
*
* @returns `true` if the node is a unist text node, `false` otherwise.
*/
function isTextNode(node: Node): node is Text {
return is(node, { type: 'text' })
}

export { isTextNode }
15 changes: 0 additions & 15 deletions src/serializers/html/extensions/checkbox.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/serializers/html/extensions/code.ts

This file was deleted.

160 changes: 0 additions & 160 deletions src/serializers/html/extensions/disabled.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/serializers/html/extensions/html.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/serializers/html/extensions/link.ts

This file was deleted.

66 changes: 0 additions & 66 deletions src/serializers/html/extensions/paragraph.ts

This file was deleted.

Loading

0 comments on commit 7734a54

Please sign in to comment.