{"id":13758286,"url":"https://github.com/icelab/draft-js-ast-exporter","last_synced_at":"2026-01-26T22:17:52.547Z","repository":{"id":51777307,"uuid":"57362630","full_name":"icelab/draft-js-ast-exporter","owner":"icelab","description":"Export content from draft-js into an abstract syntax tree.","archived":false,"fork":false,"pushed_at":"2022-12-04T04:08:46.000Z","size":199,"stargazers_count":37,"open_issues_count":4,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-15T16:26:22.634Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/icelab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-29T07:02:31.000Z","updated_at":"2022-03-30T21:31:49.000Z","dependencies_parsed_at":"2023-01-22T20:00:24.313Z","dependency_job_id":null,"html_url":"https://github.com/icelab/draft-js-ast-exporter","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icelab%2Fdraft-js-ast-exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icelab%2Fdraft-js-ast-exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icelab%2Fdraft-js-ast-exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icelab%2Fdraft-js-ast-exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icelab","download_url":"https://codeload.github.com/icelab/draft-js-ast-exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253379464,"owners_count":21899259,"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":[],"created_at":"2024-08-03T13:00:24.459Z","updated_at":"2026-01-26T22:17:52.517Z","avatar_url":"https://github.com/icelab.png","language":"JavaScript","funding_links":[],"categories":["Common Utilities"],"sub_categories":[],"readme":"# Draft.js AST Exporter\n\nAllows you to export the content from [Facebook’s Draft.js editor](https://facebook.github.io/draft-js/) to an abstract syntax tree (AST). Together with the companion [`draft-js-ast-importer`](https://github.com/icelab/draft-js-ast-importer) it forms the full cycle of exporting content from a Draft.js editor instance and then re-importing it.\n\n## Why?\n\nDraft.js supports exporting its content JSON, but this format is a little awkward. Blocks of text are disconnected from their style and entity ranges, and the depth of blocks isn’t implicit. So when it comes to rendering that content in contexts outside a Draft.js editor, you need to have an understanding of how those ranges should be applied and how blocks fit together.\n\nThe AST generated by `draft-js-ast-exporter` mitigates this issue by joining common ranges together into marked `inline` or `entity` sections, and by allowing blocks to be nested within one another based on their depth.\n\n## Installation\n\n```\nnpm install --save draft-js-ast-exporter\n```\n\n## Usage\n\n```js\nimport exporter from 'draft-js-ast-exporter'\nconst ast = exporter(editorState)\n```\n\n### Entity modification\n\nYou can modify the entity data as it’s being exported by passing in an `options.entityModifiers` object with a functions to modify that entity-type’s data:\n\n```js\nimport exporter from 'draft-js-ast-exporter'\nconst options = {\n  entityModifiers: {\n    'LINK': (data) =\u003e {\n      let copy = Object.assign({}, data)\n      // Strip protocols from `url` keys\n      copy.url = copy.url.replace(/^https?:/, '')\n      return copy\n    }\n  },\n}\nconst ast = exporter(editorState, options)\n```\n\nThis would be run for _every_ entity type of `LINK`.\n\n## Output\n\n[A simple example of the AST output](docs/output.md) is included in the `docs`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficelab%2Fdraft-js-ast-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficelab%2Fdraft-js-ast-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficelab%2Fdraft-js-ast-exporter/lists"}