aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext/lib/action_text/html_conversion.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-01-04 19:43:11 -0500
committerGeorge Claghorn <george@basecamp.com>2019-01-04 22:22:49 -0500
commit0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93 (patch)
tree91b8ddcf86b15356cd8d3dee235bf53a1778572b /actiontext/lib/action_text/html_conversion.rb
parent8a23a0e8c20c0cccf0073906d7dd7f809bfa836d (diff)
parentcfe4674d3637c746cdb3c2b5131e2de498775529 (diff)
downloadrails-0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93.tar.gz
rails-0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93.tar.bz2
rails-0decd2ddc4a94cf522fc8ea8e6c73b9deedfdd93.zip
Import Action Text
Diffstat (limited to 'actiontext/lib/action_text/html_conversion.rb')
-rw-r--r--actiontext/lib/action_text/html_conversion.rb24
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