Does the `wordwrap` filter remove HTML tags from AnQiCMS text?

Calendar 👁️ 76

In AnQi CMS template development, filters are very practical tools for data processing, which can help us format, truncate, or convert content in various ways. Among them,wordwrapFilters are commonly used for automatic line breaks in text. So, does this filter remove HTML tags from the content when processing text? Let's discuss it in detail.

wordwrapThe core function of the filter

Firstly, we need to understandwordwrapWhat is the purpose of the filter design. According to the Anqi CMS documentation,wordwrapThe primary function of the filter is to automatically wrap the text content that is longer than specified.It will distinguish 'words' based on spaces in the text and then break lines on this basis.For example, if you have a long English text and setwordwrap:20it will try to insert line breaks at positions around every 20 characters (and as much as possible between words).

It is noteworthy that the document also clearly states,wordwrapThe filter treats continuous characters without spaces (such as Chinese) as a single 'word' when processing, and therefore does not break lines between these continuous characters.

wordwrapWill the HTML tags be removed?

In short,wordwrapThe filter will not automatically remove or parse HTML tags from the text.

Its original design was to optimize the display layout of text, rather than to perform content security filtering or structural transformation. When a text containing HTML tags is passed throughwordwrapWhen the filter is processed, these HTML tags themselves are considered as part of the normal string and are involved in the calculation of character length.The filter will look for suitable line breaks in the visible text content outside of HTML tags.

This means, if you pass a section that contains<p><strong>这是一段加粗的文字。</strong></p>such HTML code towordwrapa filter, it will not remove<p>or<strong>Label. It will only try to wrap the visible text in “This is a bold text.” at this point, while keeping the HTML tags intact.

WhywordwrapDo not remove HTML tags?

In the Anqi CMS template system, there are special filters for handling HTML tags, such as:

  • striptagsFilter: to remove all HTML and XML tags from the text.
  • removetagsFilter: Used to remove the specified HTML tags from the text.
  • truncatechars_htmlandtruncatewords_htmlFilter: These filters intelligently handle HTML structures during text extraction to avoid breaking the integrity of the tags.

These dedicated filters exist to separate the different needs of 'text layout processing' and 'HTML content processing'.wordwrapFocus on line breaks in plain text, while other filters are responsible for parsing and manipulating HTML tags.

Suggestions for application in practice.

  1. If you want to remove HTML tags before text wrapping: You should usestriptagsorremovetagsThe filter to remove HTML tags first and then applywordwrapfilter. For example:

    {{ your_html_content | striptags | wordwrap:50 | safe }}
    

    This ensures that the content has been purified into plain text before the line break.

  2. If you want to keep the HTML tags when line breaks occur: Can be used directlywordwrapFilter. But please note,wordwrapIt calculates and determines the line break point based on the length of visible text (excluding the HTML tags themselves).HTML tags themselves are not split by the filter, but the text around them is wrapped according to the rules.At the same time, in order to ensure that the front-end page can correctly parse and render these HTML tags instead of displaying them as plain text, you usually need to use at output time|safefilter. For example:

    {{ your_content_with_html | wordwrap:50 | safe }}
    

UnderstandingwordwrapThis feature of the filter can help you control the display effect of the Anqi CMS template more accurately and avoid unnecessary confusion.When processing text containing HTML content, combining different filters can achieve the output effect you expect.


Frequently Asked Questions (FAQ)

How do I keep HTML tags when I want to break lines?

wordwrapThe filter itself does not remove HTML tags, so you can use it directly on text containing HTML. However, to ensure that the browser parses and displays HTML tags correctly rather than treating them as plain text, you also need to add them in the final output.|safefilter.wordwrapAffects visible text content between HTML tags.

2.wordwrapFilters andtruncatecharsWhat are the differences between filters?

They serve different purposes.wordwrapThe function of the filter isAuto-wrap.It inserts line breaks in long text to improve reading layout, and the text content is complete.truncatecharsThe function of the filter isString slicing.It will truncate text according to the specified character length and add an ellipsis (...) at the end to limit the display length.

3.wordwrapDoes the filter work for line breaks in Chinese string?

wordwrapThe filter is by default set to identify "words" based on spaces and to wrap lines. For continuous Chinese text, since there are no spaces between Chinese characters,wordwrapIt treats a continuous Chinese text as a 'word', so it does not break the line in the middle.If your Chinese content needs to be wrapped, you may need to consider inserting line breaks manually at the source or through other custom logic.

Related articles

Can AnQiCMS automatically configure the line break rule for long text through the backend visual configuration?

In website content operation, the display effect of long text is a key aspect of user experience.Reasonable automatic line breaks can not only make the page look more organized, but also improve the reading comfort on different devices.Many users of Anqi CMS may be curious, whether the system's automatic line break rules for long text can be visually configured through the backend to allow more flexible control of content display.By deeply understanding the functions of Anqi CMS, we can find that the system has fully considered the flexibility and customizability of the content during its design.However, for the specific requirement of the 'auto-wrap rule' for long text

2025-11-09

How to dynamically adjust the `wordwrap` filter's line break parameter in AnQiCMS templates?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides a rich set of template tags and filters to help users achieve diverse content displays.Among them, the `wordwrap` filter is a practical tool for automatically wrapping long text.It is particularly important to dynamically adjust the line break parameters to improve the reading experience of website content, especially in responsive design.Understanding the `wordwrap` filter In the template design of AnQi CMS, `wordwrap`

2025-11-09

Does the `wordwrap` filter affect the SEO effect of the AnQiCMS page?

When managing content on AnQiCMS, we often encounter the need to handle long text, such as article content, product descriptions, etc.To make this content more beautiful and readable on the front-end page, Anqi CMS provides various template filters, including `wordwrap`.However, some friends may worry that filters like `wordwrap` might have a negative impact on the SEO effect of the website.Today, let's delve deeper into this issue. First, let's understand the role of the `wordwrap` filter.

2025-11-09

What is the practice of applying the `wordwrap` filter to the `archive.Content` field in AnQiCMS?

In AnQiCMS, the `archive.Content` field carries the core part of the website content, usually including article details, product descriptions, and other rich text information.How to properly handle the layout of fields that may contain a large amount of text and images, especially the automatic line break of text, is crucial for improving the user's reading experience.This article will discuss the practice of applying the `wordwrap` filter to the `archive.Content` field in AnQiCMS, helping content operators and template developers to better utilize this feature

2025-11-09

If AnQiCMS text contains image links, how will the `wordwrap` filter handle it?

In AnQiCMS template development, the `wordwrap` filter is a practical tool for long text wrapping.The core function is to automatically wrap a piece of text according to the set character length, the purpose of which is to optimize page layout and improve reading experience.However, when dealing with text containing image links, there are some specific points about `wordwrap`'s behavior that we need to pay special attention to.To understand how `wordwrap` handles image links, it is first necessary to clarify its working principle.According to AnQiCMS documentation

2025-11-09

How to prevent long URLs from being incorrectly wrapped when using `wordwrap` in AnQiCMS?

When building and operating websites, we often encounter situations where we need to handle long text content, especially when ensuring that the page layout is tidy and the responsive display is good, the text automatic wrapping (wordwrap) feature is particularly important.However, randomly adding line breaks to URL links on a website can cause the links to fail, negatively impacting user experience and SEO.AnQiCMS as a content management system that focuses on user experience and SEO optimization, has comprehensive considerations and solutions for the automatic line break problem in handling long URLs

2025-11-09

Can the `wordwrap` filter be used with AnQiCMS's `safe` filter?

When building a website with AnQiCMS, we often need to handle the display of various text content.How to make the text from article details to product descriptions both beautiful and easy to read, while also correctly parsing the format it contains, is an important detail in content operation.Today, let's talk about two very practical template filters - `wordwrap` and `safe`, and how they work together.### Understanding the `wordwrap` filter: Intelligent text wrapping The `wordwrap` filter, as the name suggests

2025-11-09

Does automatic line break of long text in AnQiCMS affect the page loading speed?

Does auto-wrapping long text in AnQiCMS really slow down page loading speed? In the process of using AnQiCMS to manage website content, we often encounter situations where we need to handle a large amount of text, such as long articles, detailed product descriptions, etc.At this point, the way long text auto-wraps has become a topic of concern for many operators. Many operators may wonder: Will this automatic wrapping mechanism affect the page loading speed of the website?After all, website loading speed is crucial for user experience and search engine optimization.From my experience using AnQiCMS

2025-11-09