Help with changing how jWYSIWYG editor works - php

In jWYSIWYG editor, pushing enter inserts <br />s.
Instead of this, I would prefer that pushing enter would wrap chunks in <p> tags.
WHAT IS OUTPUT
line
<br />
new line
WHAT I WANT
<p>line</p>
<p>new line</p>
Quick examination of the config seems I can't do it without hacking it internally.
Do you suggest I hack the plugin, or use PHP to do it? The incoming HTML is parsed with HTML Purifier, so if that could do it, that would be great.
So - where should I do it, in the plugin or PHP?
Any quick implementations of how to do it?
Thanks

You could search replace <br>s with newlines, and then use %AutoFormat.AutoParagraph

Related

Make HTML readable again

I have some HTML code in a file created by an online JS editor
<h1>Title</h1><p>Some text</p><p>Some text</p>
that is not easily readable offline.
I'd like to split it like this with php, that is more readable
<h1>Title</h1>
<p>Some text</p>
<p>Some text</p>
I can make a string replace adding the newline after each closure, but if I save several times it adds newlines every time I save.
Do you have any suggestion?
Thank you.
P.S. the online JS editor is Summernote, maybe there is a config to work around this?
what you looking to is "unminify html",there is some online tools can do the work like:
unminify.com
textfixer.com
Following the suggestions of Mohamed, I found Tidy.
Tidy comes with both a shell command (http://tidy.sourceforge.net/) and a PHP library (http://php.net/manual/en/book.tidy.php), both of them work very well and provide sereal tools to maintain HTML code.

What is the best way to parse text and code in my PHP blog?

Usually, I use nl2br() and it does come out just like it's entered in the textarea, but this causes a problem when using bbcode or posting code in <code> or <pre> tags, since it adds extra line breaks.
For example this code
[sub-title]test[/sub-title]
some text here.
I'd like it to look like that when displayed in the browser, but because [sub-title] becomes <div class="sub-title"> the <br /> adds an extra line break, so it will look like this (with 2 line breaks in between)
**test**
some text here.
I haven't fully looked into it yet, but could the PHP bbcode parser help, or is the only/best solution to use regex?
You can use nl2br()
Example
$message = nl2br(preg_replace('#(\\]{1})(\\s?)\\n#Usi', ']', stripslashes($message)));

php strip_tags() troubles

I am making a project posting system that will have somewhat some markup, similar to bbcodes, When i'm fetching the data from the database I use
strip_tags($content,'<br />');
To remove any unwanted html tags, then I continue on to use
str_ireplace($markup,$html_t,$strip_tags);
And those are both placed in variables for easier working.
I want to allow the <br /> tag because that is what is in my database to achieve line downs (nl2br) now for some reason it's not echoing out <br />'s.
No whitespace in second param.
strip_tags($content,'<br>');
http://php.net/manual/en/function.strip-tags.php

I'm generating a word document with PHP, how do I make a page break?

I'm generating a word document with PHP (HTML with ms-word header), is there a way make a page break ?
Right now I'm witing a lot of <p> </p> until the page changes, but that's far from satisfying.
I've not tested to see if it works, but you could try:
<div style="page-break-before:always" />
A page-break has no meaning in HTML. It's more elegant to mark up the text which should be on the next page with, let's say Header. Then, in MS Word, create a style named "H2", and set it to "Page-break before" (Format/Paragraph/Line and Page Breaks).

Textarea without wysiwyg editor but have nice format

I have a textarea where someone can input text. I do not want a wysiwyg editor.
But what would be great:
Strip all tags, but make correct <p> and <br /> if user input has new lines.
Additionally convert all urls, with or without http// or parameter to clickable links.
I cannot find a solution.
So you could type into the textarea:
........
This is a paragraph
This ist still in the paragraph
this is a new paragraph www.this-would-be-clickable
new paragraphp `<strong>`this will be shown not bold`</strong>`
........
thankfull for every advice
Take a look at CKEditor. It may be more than what you need, but still very good.
http://ckeditor.com/
Another more simplistic alternative is Wymeditor.
Seems to me that Markdown or Textile would get you a long way, though.
But if all you need is the newline/paragraph control and url to link, you could easily build it yourself with some regex.
I found a function inside a famous blog software..... plus this regex for links, the regex seems to work, but most probably there are better solution:
/((http(s?)://)|(www.))([^\s()[]<>]+|([^\s)])|[[^\s]]])+(?

Categories