You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Draft.js is a framework for
building rich text editors. However, it does not support exporting
documents at HTML. This gem is designed to take the raw ContentState
(output of convertToRaw)
from Draft.js and convert it to HTML using Ruby.
Usage
# Create configuration for entities and stylesconfig={entity_decorators: {'LINK'=>DraftjsExporter::Entities::Link.new(className: 'link')},block_map: {'header-one'=>{element: 'h1'},'unordered-list-item'=>{element: 'li',wrapper: ['ul',{className: 'public-DraftStyleDefault-ul'}]},'unstyled'=>{element: 'div'}},style_map: {'ITALIC'=>{fontStyle: 'italic'}}}# New up the exporterexporter=DraftjsExporter::HTML.new(config)# Provide raw content stateexporter.call({entityMap: {'0'=>{type: 'LINK',mutability: 'MUTABLE',data: {url: 'https://example.com'}}},blocks: [{key: '5s7g9',text: 'Header',type: 'header-one',depth: 0,inlineStyleRanges: [],entityRanges: []},{key: 'dem5p',text: 'some paragraph text',type: 'unstyled',depth: 0,inlineStyleRanges: [{offset: 0,length: 4,style: 'ITALIC'}],entityRanges: [{offset: 5,length: 9,key: 0}]}]})# => "<h1>Header</h1><div>\n<span style=\"font-style: italic;\">some</span> <a href=\"https://example.com\" class=\"link\">paragraph</a> text</div>"