medium-draft icon indicating copy to clipboard operation
medium-draft copied to clipboard

How Can I get html content

Open geekpeng opened this issue 10 years ago • 4 comments

I use plugin draft-js-import-html https://github.com/sstur/draft-js-import-html but I cannot get tag , cannot get Image content

geekpeng avatar Oct 17 '16 16:10 geekpeng

I have been getting a lot of questions for the above feature. I will create a medium-draft-exporter project for the same use case and will update here.

brijeshb42 avatar Oct 17 '16 17:10 brijeshb42

@brijeshb42 what's with medium-draft-exporter now?

cutbko avatar Nov 29 '16 12:11 cutbko

Just use draft-js-export-html with options

        const contentState = this.state.editorState.getCurrentContent();
        const options = {
            blockRenderers: {
                 'atomic:image': (block) => {
                     const data = block.getData();
                     const src = data.get("src");
                     const caption = block.getText();
                     return `<figure><img src="${src}"/><figcaption>${caption}</figcaption></figure>`;
                },
            },
        };
        const html = stateToHTML(contentState, options);

atronov avatar Jan 23 '17 21:01 atronov

As of version 0.4.1, medium-draft-exporter is part of the project. See the docs here.

brijeshb42 avatar Jan 25 '17 06:01 brijeshb42