diff options
Diffstat (limited to 'actiontext/lib/action_text/html_conversion.rb')
-rw-r--r-- | actiontext/lib/action_text/html_conversion.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/actiontext/lib/action_text/html_conversion.rb b/actiontext/lib/action_text/html_conversion.rb new file mode 100644 index 0000000000..1e1062ea3f --- /dev/null +++ b/actiontext/lib/action_text/html_conversion.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module ActionText + module HtmlConversion + extend self + + def node_to_html(node) + node.to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_HTML) + end + + def fragment_for_html(html) + document.fragment(html) + end + + def create_element(tag_name, attributes = {}) + document.create_element(tag_name, attributes) + end + + private + def document + Nokogiri::HTML::Document.new.tap { |doc| doc.encoding = "UTF-8" } + end + end +end |