Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] wp-editor not adding brakes on first save #2397

Closed
danyj opened this issue Feb 12, 2017 · 16 comments
Closed

[bug] wp-editor not adding brakes on first save #2397

danyj opened this issue Feb 12, 2017 · 16 comments
Labels

Comments

@danyj
Copy link
Contributor

danyj commented Feb 12, 2017

Video
https://monosnap.com/file/H664TMolqSEzHyTEs76zqi1o7p2Ghg

options to test

			'text' => array(
				'type' => 'wp-editor',
				'size' => 'large',
				'editor_height' => 200,
				'shortcodes' => true,
				'editor_type' => 'tinymce',
				'wpautop' => false,
				'label' => __('Content', 'fw'),
				'value' =>''
			),

on first save I get this

screenshot_20

on second save I see brakes and even the p ,

as you can see in option wpautop is false

screenshot_21

the wpautop has been lingering around this option since the first release.
It would be great to be fixed once and for all.

#1621

@danyj danyj changed the title [bug] wp-editor not aading brakes on first save [bug] wp-editor not adding brakes on first save Feb 12, 2017
@danyj
Copy link
Contributor Author

danyj commented Feb 12, 2017

I tried to do , nl2br but on second save we have trouble since brakes and p are added so with nl2br second save gets 2 brakes each , and third one cleans it up. It is very hard to get this working.

Also the p is trouble inside headings , so there is no way to fix any of the issues until wpautop is fixed and we either get new line or brakes not both and not different on every save.

@ghost ghost self-assigned this Feb 13, 2017
@ghost ghost added the bug label Feb 13, 2017
@ghost
Copy link

ghost commented Feb 14, 2017

No need to save the post, it happens on modal save https://sendvid.com/zjlvgc0u

I haven't figure out a solution yet.

@ghost ghost closed this as completed in eba92e5 Feb 15, 2017
@ghost
Copy link

ghost commented Feb 15, 2017

Please test

@danyj
Copy link
Contributor Author

danyj commented Feb 15, 2017

ok wpautop seems like it works , but now we have no more brakes but new lines when wpautop is false right?
so we must accommodate those with nl2br ?
screenshot_24

@danyj
Copy link
Contributor Author

danyj commented Feb 15, 2017

ok I see you did try replacing it here
eba92e5#diff-58175d25bee5fa21b5af04e384540b24R83

maybe this one works better ?
http://stackoverflow.com/a/7467863/594423 ?

@danyj
Copy link
Contributor Author

danyj commented Feb 15, 2017

@moldcraft and this text/ visual tab bug , please see this till end
http://take.ms/i7NFH

tab works on first load until you save the popup, once you save popup and reopen tabs dont work anymore

@ghost
Copy link

ghost commented Feb 15, 2017

When autop is off there are no <br> added.

This code is executed once on editor init.
You can delete editor content and write new text with new lines and it will not add `

@ghost
Copy link

ghost commented Feb 15, 2017

Tabs work fine on my side. Please check browser console, maybe there is an error.

@danyj
Copy link
Contributor Author

danyj commented Feb 15, 2017

there are no errors I am looking at it , see the video please , you must save the popup to see the bug , not just open/close

@ghost
Copy link

ghost commented Feb 15, 2017

I have saved it many times.

@danyj
Copy link
Contributor Author

danyj commented Feb 15, 2017

ok fixed the tab , it was my typography option had this on doc click event.stopImmediatePropagation();
sorry thnx for looking at that now to the br's and line brakes

autop is false

do this on line 84

console.log(initialContent.replace(/\r?\n/g, '<br />'));

I see this

d957459d42eb466792f3dfce902be530

but output is

55de31ddaf7c4beeb2791626a4a7f759

so I have to accommodate and check if br is there if not do nl2br

what I am sayings that when autop is false , we should replace new lines with brakes
if autop is true editor would do this automatically right?

@ghost
Copy link

ghost commented Feb 15, 2017

console.log(initialContent.replace(/\r?\n/g, '<br />'));

Initially I set the editor content with <br> because there is no other way to preserve new lines in editor. If I set "Hello\r\nWorld" the editor shows one line.

check if br is there if not do nl2br

It should be always without br

if autop is true editor would do this automatically right?

Yes.

@danyj
Copy link
Contributor Author

danyj commented Feb 15, 2017

im bit lost now but all I am trying to do is match the visual to the output and currently we dont have that unless we massage the output

so if you have autop false and to this

one 
two
three

your output is this

one two three

if autop is true

visual

one 
two
three 

output

<p>
one <br />
two <br />
three
</p>

in my opinion autop false should produce this

one <br />
two <br />
three

since autop false does not mean strip all tags but strip p tag

@ghost
Copy link

ghost commented Feb 15, 2017

autop is a WP feature, you should contact WP core devs to ask for feature requests.

This this in browser console

var text = "Hello\r\nWorld\r\nFoo",
    textautop = wp.editor.autop(text);
console.log(textautop);
console.log(wp.editor.removep(textautop));

output

<p>Hello<br />
World<br />
Foo</p>

Hello
World
Foo

@danyj
Copy link
Contributor Author

danyj commented Feb 15, 2017

you should contact WP core devs to ask for feature requests.

cmon man dont be so harsh , I am trying to make sense out of it and you must admit that it makes no sense to see one thing in editor and get different result

@ghost
Copy link

ghost commented Feb 15, 2017

I tried to disable auto for default post content editor via this filter

add_filter('tiny_mce_before_init', function ($mceInit) {
	$mceInit['wpautop'] = false;
	return $mceInit;
});

but it doesn't disable autop. In js the parameter is set

tinyMCEPreInit.mceInit['content'].wpautop

I tried to disable autop for default editor to show that it works the same as I described above (without br)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant