Skip to content

Commit 3330fd3

Browse files
committed
feat: remove slate and lodash packages
1 parent 31f2d08 commit 3330fd3

File tree

4 files changed

+40
-88
lines changed

4 files changed

+40
-88
lines changed

package-lock.json

+26-83
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
},
5050
"dependencies": {
5151
"array-flat-polyfill": "^1.0.1",
52-
"lodash": "^4.17.21",
5352
"lodash.clonedeep": "^4.5.0",
5453
"lodash.flatten": "^4.4.0",
5554
"lodash.isempty": "^4.4.0",
@@ -58,7 +57,6 @@
5857
"lodash.isplainobject": "^4.0.6",
5958
"lodash.isundefined": "^3.0.1",
6059
"lodash.kebabcase": "^4.1.1",
61-
"slate": "^0.103.0",
6260
"uuid": "^8.3.2"
6361
},
6462
"files": [

src/jsonToMarkdown.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {IJsonToMarkdownElementTags, IJsonToMarkdownTextTags} from './types'
2-
import {cloneDeep} from 'lodash'
3-
import {Node} from 'slate'
2+
import cloneDeep from "lodash/cloneDeep"
3+
import { getString } from './utils/jsx'
44

55
let listTypes = ['ol', 'ul']
66
const elementsToAvoidWithinMarkdownTable = ['ol', 'ul', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'code', 'reference', 'img', 'fragment']
@@ -231,7 +231,7 @@ export const jsonToMarkdownSerializer = (jsonValue: any): string => {
231231
}
232232
if(jsonValue['type'] === 'td' || jsonValue['type'] === 'th') {
233233
let NonAllowedTableChild = Array.from(jsonValue['children']).find((child: any) => elementsToAvoidWithinMarkdownTable.includes(child.type))
234-
if(NonAllowedTableChild) children = Node.string(jsonValue)
234+
if(NonAllowedTableChild) children = getString(jsonValue)
235235
}
236236
return ELEMENT_TYPES[jsonValue['type']](jsonValue['attrs'], children)
237237
}

src/utils/jsx.ts

+11
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,15 @@ function isNode(value: any){
177177
isText(value) || isElement(value)
178178
// || Editor.isEditor(value) // // value cannot be editor
179179
)
180+
}
181+
182+
/**
183+
* Returns string for the specified node
184+
*/
185+
export function getString(node: any): string {
186+
if (isText(node)) {
187+
return node.text
188+
} else {
189+
return node.children.map(getString).join('')
190+
}
180191
}

0 commit comments

Comments
 (0)