{"id":13758293,"url":"https://github.com/ejilay/draftjs","last_synced_at":"2025-04-28T16:24:56.194Z","repository":{"id":17734063,"uuid":"81096940","full_name":"ejilay/draftjs","owner":"ejilay","description":"Draft.js exporter for Go","archived":false,"fork":false,"pushed_at":"2022-06-08T21:18:32.000Z","size":27,"stargazers_count":22,"open_issues_count":10,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T11:12:05.470Z","etag":null,"topics":["draft","draft-exporter","draft-js","draftjs-exporter","draftjs-utils","draftsjs","go","golang","html"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ejilay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-06T14:44:10.000Z","updated_at":"2024-01-10T12:07:28.000Z","dependencies_parsed_at":"2022-08-30T03:41:15.655Z","dependency_job_id":null,"html_url":"https://github.com/ejilay/draftjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejilay%2Fdraftjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejilay%2Fdraftjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejilay%2Fdraftjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ejilay%2Fdraftjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ejilay","download_url":"https://codeload.github.com/ejilay/draftjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251343869,"owners_count":21574445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["draft","draft-exporter","draft-js","draftjs-exporter","draftjs-utils","draftsjs","go","golang","html"],"created_at":"2024-08-03T13:00:24.949Z","updated_at":"2025-04-28T16:24:56.168Z","avatar_url":"https://github.com/ejilay.png","language":"Go","readme":"# Draft.js Exporter\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/ejilay/draftjs)](https://goreportcard.com/report/github.com/ejilay/draftjs)\n\n[Draft.js](https://facebook.github.io/draft-js/) is a framework for\nbuilding rich text editors. However, it does not support exporting\ndocuments at HTML. This package is designed to take the raw `ContentState`\n(output of [`convertToRaw`](https://facebook.github.io/draft-js/docs/api-reference-data-conversion.html#converttoraw))\nfrom Draft.js and convert it to HTML using [Go](https://golang.org). Mostly it\nuseful for server-side rendering. I should note this package does not provide\nany input validation and assumes correct and safe input data.\n\n## Usage\n\n```go\nfunc main() {\n\n\t// get your contentState JSON-string\n\tdraftState := exampleDraftStateSource\n\n\t// make auxiliary variable\n\tcontentState := draftjs.ContentState{}\n\tjson.Unmarshal([]byte(draftState), \u0026contentState) // don't forget error handling\n\n\t// prepare some config (HTML here)\n\tconfig := draftjs.DefaultConfig()\n\n\t// and just render content state to HTML-string\n\ts := draftjs.Render(\u0026contentState, config)\n\n\t// that's it\n\tfmt.Println(s)\n}\n```\nFor _RawContentState_ like this\n```json\n{\n  \"entityMap\": {\n    \"0\": {\n      \"type\": \"LINK\",\n      \"data\": {\n        \"url\": \"https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2#.ce9y2wyux\"\n      }\n    }\n  },\n  \"blocks\": [\n    {\n      \"text\": \"Rich text with link\",\n      \"type\": \"unstyled\",\n      \"depth\": 0,\n      \"inlineStyleRanges\": [\n        {\n          \"offset\": 0,\n          \"length\": 4,\n          \"style\": \"BOLD\"\n        }, {\n          \"offset\": 2,\n          \"length\": 10,\n          \"style\": \"UNDERLINE\"\n        }, {\n          \"offset\": 5,\n          \"length\": 4,\n          \"style\": \"ITALIC\"\n        }, {\n          \"offset\": 10,\n          \"length\": 4,\n          \"style\": \"CODE\"\n        }\n      ],\n      \"entityRanges\": [{\n          \"offset\": 15,\n          \"length\": 4,\n          \"key\": 0\n       }]\n}]}\n```\nIt will give something like this but without indention:\n```html\n\u003cp\u003e\n\t\u003cstrong\u003eRi\u003c/strong\u003e\n\t\u003cstrong\u003e\n\t\t\u003cins\u003ech\u003c/ins\u003e\n\t\u003c/strong\u003e\n\t\u003cins\u003e\n\t\t\u003cem\u003etext\u003c/em\u003e\n\t\u003c/ins\u003e\n\t\u003cins\u003e\n\t\t\u003ccode\u003ewi\u003c/code\u003e\n\t\u003c/ins\u003e\n\t\u003ccode\u003eth\u003c/code\u003e\n\t\u003ca href=\"https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2#.ce9y2wyux\" target=\"_blank\"\u003elink\u003c/a\u003e\n\u003c/p\u003e\n\n```\nThat look like\n\u003cp\u003e\n\t\u003cstrong\u003eRi\u003c/strong\u003e\n\t\u003cstrong\u003e\n\t\t\u003cins\u003ech\u003c/ins\u003e\n\t\u003c/strong\u003e\n\t\u003cins\u003e\u003c/ins\u003e\n\t\u003cins\u003e\n\t\t\u003cem\u003etext\u003c/em\u003e\n\t\u003c/ins\u003e\n\t\u003cins\u003e\u003c/ins\u003e\n\t\u003cins\u003e\n\t\t\u003ccode\u003ewi\u003c/code\u003e\n\t\u003c/ins\u003e\n\t\u003ccode\u003eth\u003c/code\u003e\n\t\u003ca href=\"https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2#.ce9y2wyux\" target=\"_blank\"\u003elink\u003c/a\u003e\n\u003c/p\u003e\n\n\n\n\n## Setup\n\nYou'll need Golang installed first :o)\n\n```bash\ngo get github.com/ejilay/draftjs\n```\n\n## Testing\n\nTo test run the following command in project's root directory:\n\n```bash\ngo test ./...\n```\n","funding_links":[],"categories":["Common Utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fejilay%2Fdraftjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fejilay%2Fdraftjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fejilay%2Fdraftjs/lists"}