Jump to content

Recommended Posts

Posted

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

Posted

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>..

Posted

Or just view via Chrome dev tools or equivalents in other browsers, you probably see nicely structured html.

Posted

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);
  }
}
 
Posted

Theres a plugin in TinyMCE called CodeMagic.

Its not enabled by default but you cab add codemagic to the plugin and controls in the field tinymce settings.

  • Like 1
Posted
:D. @diogo: I'll try to restrain myself a bit and nag about typos only when I feel it's useful to others in some way from now on.
Posted

Hi All,

Thanks for your tips. It got my brain working again and I (gasp) *Googled* for the answer. Which I should have done in the beginning.

Google is our friend. Well, sort of.

I found this tinyMCE directive, added it, and it worked like a charm:

apply_source_formatting:true
 

Thanks!

Peter

  • Like 3

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
  • Recently Browsing   0 members

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