Problem with private img tag

submitted in HTML format and sent to a server that performs some preliminary processing.

It works with the "src" attribute of the "img" tag.

After pre-processing and saving, all pre-processed "img" tags are not self-closing.

For example, if the tag "img" was checked:

<img src="image.png" />

after pre-processing with Nokogiri or Hpricot, this will be:

<img src="/preprocessed_path/image.png">

The code is pretty simple:

doc = Hpricot(self.content)
doc.search("img").each do |tag|
  preprocess tag
end
self.content = doc.to_html

For Nokorigi, it looks the same.

How to solve this problem?


Update 1

Forget noting - I have an HTML 5 page that I'm trying to test with the W3C Validator .

When the "img" tag is inside a div, it complains about the following:

required character (found d) (expected i)
</div>

For example, try checking the following code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
</head>
<body>
    <div>
        <img src="image.png">
    </div>
</body>
</html>

You will get the same error:

Line 9, Column 4: required character (found d) (expected i)
</div>
+3
3

, <html>, xmlns XHTML. , , XHTML. xmlns, .

<!DOCTYPE html>
<html>
  <head>
  <meta charset="utf-8" />
  <title>something here</title>
</head>
<body>
  <div>
    <img src="image.png">
  </div>
</body>
</html>
+3

, HTML, "/" HTML. /xhtml + xml, - IMG HTML, "/" . /xhtml + xml, , Nokogiri to_xhtml.

+2

, , img? , , ?

0
source

Source: https://habr.com/ru/post/1745918/


All Articles