]> git.openstreetmap.org Git - rails.git/commitdiff
Detect <img> images in markdown rich text
authorAnton Khorev <tony29@yandex.ru>
Fri, 2 Aug 2024 17:01:52 +0000 (20:01 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 2 Aug 2024 17:04:59 +0000 (20:04 +0300)
lib/rich_text.rb
test/lib/rich_text_test.rb

index f19d3d3a952ddd2c8240e2ea8da228c434523ffc..de35aae9c195091ea1e0d64b0a5a95b5df8fb628 100644 (file)
@@ -104,7 +104,8 @@ module RichText
     end
 
     def first_image_element(element)
-      return element if element.type == :img
+      return element if element.type == :img ||
+                        (element.type == :html_element && element.value == "img")
 
       element.children.find do |child|
         nested_image = first_image_element(child)
index 8dc9e49b1180582535d0939b67fdd3ede88219be..8c12053179d2389b7575506905c49d453ef89075 100644 (file)
@@ -275,6 +275,11 @@ class RichTextTest < ActiveSupport::TestCase
     assert_equal "https://example.com/image1.jpg", r.image
   end
 
+  def test_markdown_html_image
+    r = RichText.new("markdown", "<img src='https://example.com/img_element.png'>")
+    assert_equal "https://example.com/img_element.png", r.image
+  end
+
   private
 
   def assert_html(richtext, &block)