draft-js-ast-exporter
Version:
Export content from draft-js into an abstract syntax tree.
20 lines (17 loc) • 665 B
JavaScript
import processBlocks from './processor';
/**
* Exporter
*
* @param {EditorState} editorState Draft JS EditorState object
* @param {Object} options Additional configuration options
* @return {Array} An abstract syntax tree representing the draft-js editorState
*/
function exporter(editorState) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// Retrieve the content state and its blocks
var contentState = editorState.getCurrentContent();
var blocks = contentState.getBlocksAsArray();
// Convert to an abstract syntax tree
return processBlocks(blocks, contentState, options);
}
export default exporter;