Sha256: 61d4ff8bff9176b7743d94b3ceccd5589928f74665810808b9f5171a4d06346b
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
module DraftjsHtml module HtmlDefaults BLOCK_TYPE_TO_HTML = { 'paragraph' => 'p', 'unstyled' => 'p', 'header-one' => 'h1', 'header-two' => 'h2', 'header-three' => 'h3', 'header-four' => 'h4', 'header-five' => 'h5', 'header-six' => 'h6', 'blockquote' => 'blockquote', 'code-block' => 'code', 'ordered-list-item' => 'li', 'unordered-list-item' => 'li', 'atomic' => 'figure', }.freeze HTML_STYLE_TAGS_TO_STYLE = { 'strong' => 'BOLD', 'b' => 'BOLD', 'em' => 'ITALIC', 'i' => 'ITALIC', 'del' => 'STRIKETHROUGH', 'u' => 'UNDERLINE', 'small' => 'SMALL', 'sub' => 'SUBSCRIPT', 'sup' => 'SUPERSCRIPT', 'code' => 'CODE', }.freeze STYLE_MAP = HTML_STYLE_TAGS_TO_STYLE.invert.merge( 'HIGHLIGHT' => 'em', 'RTL' => ['div', dir: 'rtl'] ).freeze ENTITY_ATTRIBUTE_NAME_MAP = { 'className' => 'class', 'url' => 'href', }.freeze DEFAULT_ENTITY_STYLE_FN = ->(_entity, chars, _doc) { chars } ENTITY_CONVERSION_MAP = { 'LINK' => ->(entity, content, *) { attributes = entity.data.slice('url', 'href', 'rel', 'target', 'title', 'className').each_with_object({}) do |(attr, value), h| h[ENTITY_ATTRIBUTE_NAME_MAP.fetch(attr, attr)] = value end DraftjsHtml::Node.new('a', attributes, content) }, 'IMAGE' => ->(entity, *) { attributes = entity.data.slice('src', 'alt', 'className', 'width', 'height').each_with_object({}) do |(attr, value), h| h[ENTITY_ATTRIBUTE_NAME_MAP.fetch(attr, attr)] = value end DraftjsHtml::Node.new('img', attributes) } }.freeze end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
draftjs_html-0.23.0 | lib/draftjs_html/html_defaults.rb |
draftjs_html-0.22.0 | lib/draftjs_html/html_defaults.rb |
draftjs_html-0.21.0 | lib/draftjs_html/html_defaults.rb |