Skip to content

Commit

Permalink
feat: remove slate and lodash packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayesh2812 committed Jul 9, 2024
1 parent 50b58d9 commit f690450
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 88 deletions.
109 changes: 26 additions & 83 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
},
"dependencies": {
"array-flat-polyfill": "^1.0.1",
"lodash": "^4.17.21",
"lodash.clonedeep": "^4.5.0",
"lodash.flatten": "^4.4.0",
"lodash.isempty": "^4.4.0",
Expand All @@ -58,7 +57,6 @@
"lodash.isplainobject": "^4.0.6",
"lodash.isundefined": "^3.0.1",
"lodash.kebabcase": "^4.1.1",
"slate": "^0.103.0",
"uuid": "^8.3.2"
},
"files": [
Expand Down
6 changes: 3 additions & 3 deletions src/jsonToMarkdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IJsonToMarkdownElementTags, IJsonToMarkdownTextTags} from './types'
import {cloneDeep} from 'lodash'
import {Node} from 'slate'
import cloneDeep from "lodash/cloneDeep"
import { getString } from './utils/jsx'

let listTypes = ['ol', 'ul']
const elementsToAvoidWithinMarkdownTable = ['ol', 'ul', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'code', 'reference', 'img', 'fragment']
Expand Down Expand Up @@ -231,7 +231,7 @@ export const jsonToMarkdownSerializer = (jsonValue: any): string => {
}
if(jsonValue['type'] === 'td' || jsonValue['type'] === 'th') {
let NonAllowedTableChild = Array.from(jsonValue['children']).find((child: any) => elementsToAvoidWithinMarkdownTable.includes(child.type))
if(NonAllowedTableChild) children = Node.string(jsonValue)
if(NonAllowedTableChild) children = getString(jsonValue)
}
return ELEMENT_TYPES[jsonValue['type']](jsonValue['attrs'], children)
}
Expand Down
11 changes: 11 additions & 0 deletions src/utils/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,15 @@ function isNode(value: any){
isText(value) || isElement(value)
// || Editor.isEditor(value) // // value cannot be editor
)
}

/**
* Returns string for the specified node
*/
export function getString(node: any): string {
if (isText(node)) {
return node.text
} else {
return node.children.map(getString).join('')
}
}

0 comments on commit f690450

Please sign in to comment.