lib/storyblok/richtext/html_renderer.rb in storyblok-richtext-renderer-0.0.6 vs lib/storyblok/richtext/html_renderer.rb in storyblok-richtext-renderer-0.0.7
- old
+ new
@@ -9,10 +9,15 @@
require_relative "html_renderer/marks/strong"
require_relative "html_renderer/marks/code"
require_relative "html_renderer/marks/italic"
require_relative "html_renderer/marks/link"
require_relative "html_renderer/marks/styled"
+ require_relative "html_renderer/marks/anchor"
+ require_relative "html_renderer/marks/highlight"
+ require_relative "html_renderer/marks/subscript"
+ require_relative "html_renderer/marks/superscript"
+ require_relative "html_renderer/marks/text_style"
require_relative "html_renderer/nodes/node"
require_relative "html_renderer/nodes/bullet_list"
require_relative "html_renderer/nodes/code_block"
require_relative "html_renderer/nodes/hard_break"
require_relative "html_renderer/nodes/heading"
@@ -23,10 +28,11 @@
require_relative "html_renderer/nodes/text"
require_relative "html_renderer/nodes/blockquote"
require_relative "html_renderer/nodes/horizontal_rule"
require_relative "html_renderer/nodes/text"
require_relative "html_renderer/nodes/blok"
+ require_relative "html_renderer/nodes/emoji"
class HtmlRenderer
def initialize
@marks = [
Storyblok::Richtext::Marks::Bold,
@@ -34,11 +40,16 @@
Storyblok::Richtext::Marks::Underline,
Storyblok::Richtext::Marks::Strong,
Storyblok::Richtext::Marks::Code,
Storyblok::Richtext::Marks::Italic,
Storyblok::Richtext::Marks::Link,
- Storyblok::Richtext::Marks::Styled
+ Storyblok::Richtext::Marks::Styled,
+ Storyblok::Richtext::Marks::Anchor,
+ Storyblok::Richtext::Marks::Highlight,
+ Storyblok::Richtext::Marks::Subscript,
+ Storyblok::Richtext::Marks::Superscript,
+ Storyblok::Richtext::Marks::TextStyle
]
@nodes = [
Storyblok::Richtext::Nodes::HorizontalRule,
Storyblok::Richtext::Nodes::Blockquote,
Storyblok::Richtext::Nodes::BulletList,
@@ -48,11 +59,12 @@
Storyblok::Richtext::Nodes::Image,
Storyblok::Richtext::Nodes::ListItem,
Storyblok::Richtext::Nodes::OrderedList,
Storyblok::Richtext::Nodes::Paragraph,
Storyblok::Richtext::Nodes::Text,
- Storyblok::Richtext::Nodes::Blok
+ Storyblok::Richtext::Nodes::Blok,
+ Storyblok::Richtext::Nodes::Emoji
]
end
def set_component_resolver(component_resolver)
Storyblok::Richtext::Nodes::Blok.send :define_method, :component_resolver, component_resolver
@@ -97,10 +109,12 @@
html.push(CGI.escapeHTML(node.text))
elsif node and node.single_tag
html.push(render_tag(node.single_tag))
elsif node and node.html
html.push(node.html)
+ elsif item['type'] == 'emoji'
+ html.push(render_emoji(item))
end
html.push(render_closing_tag(node.tag)) if node and node.tag
if item['marks']
item['marks'].reverse.each do |m|
@@ -156,9 +170,27 @@
if (instance.matching())
return instance
end
end
found.first
+ end
+
+ def render_emoji(item)
+ if item['attrs']['emoji']
+ return item['attrs']['emoji']
+ end
+
+ emoji_image_container = [{
+ tag: 'img',
+ attrs: {
+ src: item['attrs']['fallbackImage'],
+ draggable: 'false',
+ loading: 'lazy',
+ align: 'absmiddle',
+ },
+ }]
+
+ render_tag(emoji_image_container, ' /')
end
end
end
end