The line break converter is a shame we inherited from Wordpress. It is full of bugs, nobody really groks the implementation and it tries to parse HTML using regexps.

We need to rewrite this using proper DOM manipulations, like we refactored the HTML corrector.

But... what should this line break converter do exactly? This looks a bit like black-magic currently. Somehow, the line break converter should:

  1. Convert chunk of text separated by empty lines (\n\n) into HTML paragraphs (<p></p>)
  2. Retain text-level HTML tags in the chunk of text
  3. Ignore the content of some HTML tags (script, style, object, pre, ... maybe others)

But I'm not sure:

  • What to do with tables? We probably should only convert paragraphs into <td>s, not inside other elements... by the way, do we want to add <p> to mostly all <td>s?
  • What to do with <div>s?
  • ...

Comments

damien tournoud’s picture

I think we should only convert top-level text (ie. text that is not already inside an HTML container element). We could extend that to "all text that is not either top-level or inside a <p>" if required.

deviantintegral’s picture

Subscribing - as is, the _filter_autop() function is very difficult to work with, and the upstream version isn't any better.

Part of this fix should be cleaning up the test cases so they have better descriptions; currently many of them just repeat "Make sure line breaking produces matching paragraph tags.", which isn't helpful when they fail.

sun’s picture

Version: 7.x-dev » 8.x-dev
Garrett Albright’s picture

I've been experimenting with the DOM in PHP and how it relates to #653988: Line break filter corrupts existing XHTML.

Using the DOM could result in a smarter line break filter, sure. The problem is that by using the DOM to read HTML, then serializing it later, we're "correcting" the HTML in much the same way that the HTML corrector filter is - there doesn't seem to be any way to use this approach to convert line breaks independently that I can yet discern.

Does this mean we need to merge the line break conversion functionality in with the HTML correction filter?

damien tournoud’s picture

It's slightly more then that. We should implement part of the filter chain not as strings, but as DOM manipulations.

Currently a filter takes a string and returns a string. As soon as we are in an HTML context (ie. as soon as pre-process filters like BBCode or Markdown have done their jobs), we could simply manipulate DOM elements.

Garrett Albright’s picture

I understand that. Let me restate my comment perhaps a little bit clearer. We have two tasks which are currently (rightly) two separate filters: converting line breaks and cleaning HTML. The problem is that the mere act of calling filter_dom_load() means that whatever we're going to get from serializing it later is going to have clean HTML. That's great if we want to just clean HTML, or if we want to convert line breaks and clean HTML. However, if we want to just convert line breaks… I don't see how we can do that if we're using filter_dom_load() (or the DOM in general).

sun’s picture

Nice context idea, Damien -- food for thought for http://drupal.org/project/filter

I think the tests for the line break filter should cover a range of expected behaviors already. That said, I'm not entirely sure whether it will be easy (or easier) to implement this filter via DOM manipulations...

carlos8f’s picture

Interesting... for D8 it would be interesting to have filters hook into distinct phases, such as pre-process (for markdown, etc.), DOM (where the hook takes a dom object instead of a string), and post-process. That would allow filters to not have to resort to regexp's when manipulating XHTML, but that would also mean that the HTML corrector filter would be unavoidably embedded in the processing scheme.

For D7 though, I think we should at least try to fix the line break filter. See http://drupal.org/node/653988#comment-2998364 for an example of how broken it is.

Garrett Albright’s picture

Damien and carlos, I think you're on the right track. Requiring the DOM to be used in the filtering process is a huge step that we need to consider, but I think the net benefit from doing so could ultimately be very great. carlos, you mention "post-process…" What do you envision there? Perhaps filters that work on the HTML after it's been serialized from the DOM object?

Something else we could gain from this approach is getting rid of the fail that is the filter rearranging page!

carlos8f’s picture

@Garrett, yes, phase 3 would be after filter_dom_serialize() is called, filters operating on HTML strings exactly like how they currently do. Filters would still need to be weighted though, and I'm not sure if that can let us get rid of a weighting interface either.

From my recent research, I think a DOM-based line break filter would be extremely hard to implement, without dramatically simplifying its scope. DOM makes it easy to iterate over (or ignore) the children of a specific element, but doing things like searching for whitespace in relation to block level tags would be seemingly impossible without regexp's. DOM might be good for other types of filters that have a more direct target (ala getElementsByTagName), so I think it might still be valuable to have a three-phase filter system.

For now I'm attempting to fix some of the shortcomings of our current filter at #653988: Line break filter corrupts existing XHTML

Garrett Albright’s picture

carlos, sure, filters will still need to be weighted, but I disagree about not being able to ditch the weighting interface. What does that do exactly, anyway? It helps make sure that filters like Markdown or Textile or BBcode run before filters which expect HTML input. With this three-phase approach, filters can more easily specify themselves where they should go in the process. Further weighting may be necessary beyond that, but it still doesn't need a user-facing interface - after all, "normal" modules have weights in the System table too, and there's no user-facing interface to reorder those (which is something that almost never needs to be done anyway).

Garrett Albright’s picture

I created #807996: [meta] Input filters and text formats for further discussion along these lines, and hopefully some action.

jhedstrom’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for creating this issue to improve Drupal.

We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since there's been no follow up and was tagged for summary update 10 years ago going to close out. If still valid please reopen

Thanks all

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.