Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updated package with new version. #44

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read more](https://www.contentstack.com/docs/).

The JSON RTE Serializer package helps you convert the data inside your JSON Rich Text Editor field from JSON to HTML format and vice versa.
The JSON RTE Serializer package assists in converting the content within your JSON Rich Text Editor field between JSON and HTML formats. This means you can easily change your data from JSON format to HTML format for display purposes, and vice versa, for data storage or processing.
If you need to convert JSON to Markdown format, we offer the Markdown Serializer function. This function is specifically designed to transform your JSON data into Markdown, making it easier to handle text formatting for platforms that use Markdown.

# Installation

Expand Down Expand Up @@ -102,6 +103,45 @@ The resulting JSON-formatted data will look as follows:
}
```

### JSON to Markdown Conversion Code

You can use the following JSON RTE Serializer code to convert your JSON RTE field data into Markdown format.

```javascript
import { jsonToMarkdown } from "@contentstack/json-rte-serializer";

const markdownValue = jsonToHtml({
type: "doc",
attrs: {},
uid: "547a479c68824767ce1d9725852f042b",
children: [
{
uid: "767a479c6882471d9725852f042b67ce",
type: "p",
attrs: {},
children: [
{ text: "This is Markdown-formatted content which has some " },
{ text: "BOLD", bold: true },
{ text: " text and some "},
{ text: "Italic", italic: true },
{ text: " text."}
]
},
],
});

console.log(markdownValue);
```

### Result of Conversion

The resulting Markdown data will look as follows:

```MARKDOWN

This is Markdown-formatted content which has some **BOLD** text and some *Italic* text.
```

## Custom Conversion

For customized conversion scenarios, you can customize your JSON RTE Serializer code to allow the support for additional tags or element types in the JSON Rich Text Editor field. Pass an `options` field (optional) within the `jsonToHtml` or `htmlToJson` method to manipulate the working of the JSON RTE Serializer package as per your requirements.
Expand Down
69 changes: 63 additions & 6 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/json-rte-serializer",
"version": "2.0.6",
"version": "2.0.7",
"description": "This Package converts Html Document to Json and vice-versa.",
"main": "lib/index.js",
"module": "lib/index.mjs",
Expand Down Expand Up @@ -49,6 +49,7 @@
},
"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 @@ -57,6 +58,7 @@
"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
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "array-flat-polyfill"
import { fromRedactor } from "./fromRedactor"
import { toRedactor } from "./toRedactor"
import {jsonToMarkdownSerializer} from './jsonToMarkdown'
export * from "./types"
export { fromRedactor as htmlToJson, toRedactor as jsonToHtml }
export { fromRedactor as htmlToJson, toRedactor as jsonToHtml, jsonToMarkdownSerializer as jsonToMarkdown }
Loading
Loading