Peter Falkenberg Brown Posted April 14, 2013 Share Posted April 14, 2013 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 More sharing options...
petsagouris Posted April 14, 2013 Share Posted April 14, 2013 Why would you want to read the article in the HTML source? Link to comment Share on other sites More sharing options...
apeisa Posted April 14, 2013 Share Posted April 14, 2013 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 More sharing options...
SiNNuT Posted April 14, 2013 Share Posted April 14, 2013 Or just view via Chrome dev tools or equivalents in other browsers, you probably see nicely structured html. Link to comment Share on other sites More sharing options...
petsagouris Posted April 14, 2013 Share Posted April 14, 2013 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 More sharing options...
nik Posted April 14, 2013 Share Posted April 14, 2013 @petsagouris: A tiny typo in your preg_replace(), change $input to $str. Link to comment Share on other sites More sharing options...
petsagouris Posted April 14, 2013 Share Posted April 14, 2013 @petsagouris: A tiny typo in your preg_replace(), change $input to $str. Thanks, done. Link to comment Share on other sites More sharing options...
Soma Posted April 14, 2013 Share Posted April 14, 2013 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. 1 Link to comment Share on other sites More sharing options...
diogo Posted April 14, 2013 Share Posted April 14, 2013 @Soma: A tiny typo in your verb, change cab to can. 1 Link to comment Share on other sites More sharing options...
nik Posted April 14, 2013 Share Posted April 14, 2013 . @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. Link to comment Share on other sites More sharing options...
diogo Posted April 14, 2013 Share Posted April 14, 2013 Nik, I'm just fooling around your correction was useful for sure Link to comment Share on other sites More sharing options...
Peter Falkenberg Brown Posted April 14, 2013 Author Share Posted April 14, 2013 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 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now