Jump to content

Body text HTML has no line breaks in code


Recommended Posts

Hi All,

I just noticed that the HTML of the body text field has no line breaks in the code, so that when you view source, the content is on one very, very long line.

The line contains <p> codes, so the browser displays it correctly, but the source is very hard to read.

I would also wonder if a maximum line length might be reached in the browser. Not sure on that.

It becomes a significant issue for source code readability, especially with articles or stories that are long (e.g. a short story that is 25,000 words.)

It seems like ProcessWire is not adding on \n line break characters after each </p> or < /br> code.

Is there a setting that I'm missing?

Thanks,

Peter

Link to comment
Share on other sites

You have to look into tinyMCE settings (or whatever editor you are using) to add newlines. If that doesn't work, you could create textformatter, that adds few newlines after </p>, </h1>,</h2>, </h3>, </h4>..

Link to comment
Share on other sites

It seems that TinyMCE used to have an option to do what Peter wants but it is nowhere to be found in the tinymce source (TinyMCE configuration: remove_linebreaks)

The TextFormatter should look something like this (not tested apart from the regexp):

<?php
/**
 * TextFormatter to put new line character after a specified set of end tags.
 */
class TextformatterNewlineAfterTags extends Textformatter {

  public static function getModuleInfo() {
    return array(
      'title' => 'Line characters after specific HTML tags',
      'version' => 100,
      'summary' => "Adds line characters after the <br> and </p> end tags. ",
    );
  }
  public function format(&$str) {
    $str = preg_replace('/(?:<\\/p>)|(?:<br\\s*\\/?>)/', '$0\\n', $str);
  }
}
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...