How would the `wordwrap` filter handle image links in AnQiCMS text?

In the template development of AnQiCMS,wordwrapFilter is a utility for handling line breaks in long text.The core function is to wrap a text according to the set character length, the purpose of which is to optimize the page layout and enhance the reading experience.wordwrapThe behavior has some places that require our special attention.

To understandwordwrapHow to handle image links, first of all, it is necessary to clarify its working principle. According to the AnQiCMS documentation,wordwrapThe filter will insert line breaks in the text according to the specified character length. It is worth noting that it “distinguishes words by spaces”, but if a “word” (i.e., a continuous string without spaces) itself exceeds the set line break threshold,wordwrapThe text will also be truncated and wrapped in the middle of the word. This means it is a relatively 'rough' character-level wrapping and does not have HTML structure understanding ability.

When the text contains an image link,wordwrapthere are two common situations:

  1. The image link exists in the form of plain text URL:Suppose your text content directly contains a very long image URL, for example:http://example.com/this/is/a/very/long/path/to/an/image/with/a/long_filename.jpg. Due towordwrapThe filter will truncate the string, even if it is a single "word", when it reaches the length limit during processing long strings, therefore, if the length of this plain text URL exceedswordwrapThe threshold set, it will insert a line break in the middle of the URL.Although this visually implements line breaks, the truncated URL will no longer be a valid link and may not be clickable or recognizable.

  2. Image link is in HTML format<img>Exists in tag form:More commonly, image links will be in HTML format:<img>Embedded in text in tag form, for example:<img src="http://example.com/very/long/image_name_that_exceeds_wrap_length.jpg" alt="描述文字">. Due towordwrapThe filter acts directly on the inputstring content. It does not intelligently identify and protect the integrity of HTML tags. Therefore, if this<img>Label as a whole string, its internalsrcattribute value (i.e., URL) or other parts cause the entire label's character length to exceedwordwrapthe set line break threshold,wordwrapThis behavior will also try to insert a line break inside the tag. The consequence of this is catastrophic, it will break<img>The HTML structure of the label, causing the image to fail to load and display normally, and even possibly trigger