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

Should Gutenberg continue to automatically add <p> paragraph tags? #4446

Closed
cr101 opened this issue Jan 13, 2018 · 23 comments
Closed

Should Gutenberg continue to automatically add <p> paragraph tags? #4446

cr101 opened this issue Jan 13, 2018 · 23 comments
Assignees
Labels
Needs Decision Needs a decision to be actionable or relevant [Type] Enhancement A suggestion for improvement.
Milestone

Comments

@cr101
Copy link

cr101 commented Jan 13, 2018

I'm using Gutenberg 2.0.0 Code Editor

When I open a CPT that I created with the Classic Text Editor the post content is automatically wrapped with <p> tags.
Is there a way to tell Gutenberg to not automatically wrap the content in <p> tags as I don't want any html tags in the database?

Since I'm using the Code Editor instead of the Visual Editor I except to have full control over the use of HTML tags.

@danielbachhuber danielbachhuber added the [Type] Help Request Help with setup, implementation, or "How do I?" questions. label Jan 23, 2018
@bobbingwide
Copy link
Contributor

See #4672 (comment)

@bobbingwide
Copy link
Contributor

You may wish to add why you can’t use the other block types to achieve what you could happily do in the Classic text editor. I recently discovered, though I’ve not raised an issue yet, that the Custom HTML editor has its own ideas about what you can do!

@cr101
Copy link
Author

cr101 commented Feb 24, 2018

You may wish to add why you can’t use the other block types to achieve what you could happily do in the Classic text editor.

I have over 10,000 CPTs that have been created using the Classic text editor. The issue is that when I activate Gutenberg and then open one of the CPTs the <p> tags are automatically created. Going through 10k CPTs to manually remove all the <p> tags and then use a different block type is a massively time consuming job.

Users should be given a third option as to which editor they would like to use: Visual Editor, Code Editor or Classic Text Editor (as in New lines remain as new lines, they do not get converted into <br /> tags or spaces and No automatic creation of <p> or <br /> tags.)

Not everyone uses WordPress for blogging!

@aduth
Copy link
Member

aduth commented Mar 28, 2018

Can you verify whether this is the same issue described at #3901 ?

@aduth aduth added the [Status] Needs More Info Follow-up required in order to be actionable. label Mar 28, 2018
@cr101
Copy link
Author

cr101 commented Mar 30, 2018

@aduth I'm not sure that it is the same.
To fully understand my issue see the steps below:

  1. Create a post using the Classic Text Editor
    screenshot_66

  2. Enable the Gutenberg plugin and then edit the post using the Code Editor. As you can see all the paragraphs were automatically wrapped in <p> tags which is annoying.
    screenshot_67

I personally never use the Visual Editor and I'd like to have full control over what HTML I use in my posts.

@aduth
Copy link
Member

aduth commented Mar 30, 2018

Okay, so I believe I understand better now. This is expected in current incarnation of Gutenberg, as it does not perpetuate the classic editor's assumptions of wpautop. Arguably, if your goal is to have full control over HTML in your posts, this is a more accurate representation. The paragraphs would have been applied previously, but magically so. This magic has been removed here: the tags are displayed as they will be effected on the front end of a site.

Whether we still want to add wpautop as an optional support is another question. I could, for example, imagine a separate mode which is not strictly HTML, but this mixed wpautop behavior.

@aduth aduth added [Type] Enhancement A suggestion for improvement. Needs Decision Needs a decision to be actionable or relevant and removed [Status] Needs More Info Follow-up required in order to be actionable. [Type] Help Request Help with setup, implementation, or "How do I?" questions. labels Mar 30, 2018
@danielbachhuber danielbachhuber added this to the Merge Proposal milestone Apr 11, 2018
@danielbachhuber danielbachhuber changed the title Automatic addition of <p> tags Should Gutenberg continue to automatically add <p> paragraph tags? Apr 11, 2018
@ZebulanStanphill
Copy link
Member

Personally, I always really disliked the magic invisible paragraph tags of wpautop in the Classic Editor. If the editor was going to add paragraph tags, I wanted to be able to see them. It always seemed inconsistent and weird that paragraph tags were invisible while every other tag was not.

@cr101
Copy link
Author

cr101 commented Apr 11, 2018

This also has implications when hiding/showing more text within a certain length on the front-end if the post content is wrapped with <p> paragraph tags. Please keep in mind that some of us use WordPress as a CMS instead of a blog.

@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented Apr 11, 2018

@cr101 Presumably, shouldn't something that counts content length in a post ignore HTML tags? At least, that seems like the proper way to do it. Adding/removing <strong>, <em> or other tags to your content should not change the size of an automatically-generated excerpt.

@cr101
Copy link
Author

cr101 commented Apr 15, 2018

We are building a headless WordPress web app using React and the WordPress API.
When a post is created from within the WordPress Admin the post content will have <p> tags wrapped around it but when the post content is created from the web app front-end and pushed through the WordPress API the content will not have the <p> tags.

Therefore, displaying the content on the front-end will not be consistent.

@aduth
Copy link
Member

aduth commented Apr 18, 2018

when the post content is created from the front-end and pushed through the WordPress API the content will not have the <p> tags.

Which front-end editor are you referring to? To be clear, you could pass <p> and they'd be respected. It's correct to note that if you choose not to, the default behavior of wpautop will take effect unless block demarcations are detected within the post's content.

@cr101
Copy link
Author

cr101 commented Apr 19, 2018

@aduth

Which front-end editor are you referring to?

Sorry, I was referring to the consumer front-end of the web app. A lot of our content is created outside the WordPress admin.

@danielbachhuber
Copy link
Member

Should Gutenberg continue to automatically add <p> paragraph tags?

At this point, the answer is yes: paragraph tags will continue to be added around text that's historically been magically transformed by wpautop. There is a non-zero number of bugs with this right now though. We'll continue to fix the bugs as they come up.

@cr101
Copy link
Author

cr101 commented Jun 6, 2018

@danielbachhuber From a consistency point of view, will the content of a post created through the WP REST API be automatically wrapped in <p> paragraph tags as well?

@danielbachhuber
Copy link
Member

From a consistency point of view, will the content of a post created through the WP REST API be automatically wrapped in <p> paragraph tags as well?

This is something we could consider if you'd like to open a core Trac ticket.

@rstmsn
Copy link

rstmsn commented Dec 9, 2018

Any updates on this ?

The fact that Gutenberg elects to add <p> tags when rendering content on the front end, that are hidden when editing using the 'View as HTML' editor on the backend, is rather frustrating and seemingly confused.

@cr101
Copy link
Author

cr101 commented Dec 9, 2018

@rstmsn That's exactly the frustration I've been having with using Gutenberg. The <p> tags are forced on you, are hidden and can't get rid of them.
Gutenberg should allow users to have full control over HTML in their posts when in "Code Editor" mode or "Edit as HTML".

@rstmsn
Copy link

rstmsn commented Dec 9, 2018

@cr101 agreed. Is this being discussed elsewhere ? Seems like a rather glaring issue to me...

@cr101
Copy link
Author

cr101 commented Dec 9, 2018

@rstmsn Not sure if it's discussed anywhere else. Gutenberg is very frustrating and time consuming to use so I will not be using it for for a few years. Currently using the Classic Editor plugin instead.

@aduth
Copy link
Member

aduth commented Dec 11, 2018

The fact that Gutenberg elects to add <p> tags when rendering content on the front end, that are hidden when editing using the 'View as HTML' editor on the backend, is rather frustrating and seemingly confused.

Can you clarify in what cases you see no <p> when using "View as HTML" ? Is this the block's "Edit as HTML" mode? Is it for a Paragraph block or for a Classic block?

For paragraphs, I cannot reproduce the missing <p>. They are shown:

image

For classic block, the block mimics pre-5.0 behavior, where the omission of paragraph tags has existed since 2003 (the "autop" behavior).

See: https://developer.wordpress.org/reference/functions/wpautop/

@emfluenceindia
Copy link

The fact that Gutenberg elects to add <p> tags when rendering content on the front end, that are hidden when editing using the 'View as HTML' editor on the backend, is rather frustrating and seemingly confused.

Can you clarify in what cases you see no <p> when using "View as HTML" ? Is this the block's "Edit as HTML" mode? Is it for a Paragraph block or for a Classic block?

For paragraphs, I cannot reproduce the missing <p>. They are shown:

image

For classic block, the block mimics pre-5.0 behavior, where the omission of paragraph tags has existed since 2003 (the "autop" behavior).

See: https://developer.wordpress.org/reference/functions/wpautop/

When I disable visual editor and code editor is my only option. I have the following two paragraphs written in code editor:

<p>The P tag disappears when I take the focus out of this editor</p>
<p style="font-weight: bold;">The P tag does not disappears even when I take the focus out of this editor if the P tag has an attribute</p>

@emfluenceindia
Copy link

emfluenceindia commented Dec 17, 2018

From a consistency point of view, will the content of a post created through the WP REST API be automatically wrapped in <p> paragraph tags as well?

This is something we could consider if you'd like to open a core Trac ticket.

Here a ticket in Trac which I found somewhat related to this.
https://core.trac.wordpress.org/ticket/45636

This is not exactly the same as this one, but could well be considered as related.

When there is no attribute set for the <p>...</p> the tag visually disappears. However it renders correctly on browser, i.e. the text gets wrapped inside a paragraph tag.

To my understanding the following line is doing the trick (removing the <p> tag)

// Remove paragraph tags.
//html = html.replace( /\s*<p>/gi, '' );
html = html.replace( /\s*<\/p>\s*/gi, '\n\n' );

Any specific reason Gutenberg is replacing <p>...</p> tag with \n\n characters when it has no attribute?

@ericbhanson
Copy link

My team is also affected by this decision, as it happens when they switch between the Code and Visual editors in the Classic block in Gutenberg. I would also like to be able to prevent the

tags from being added in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Decision Needs a decision to be actionable or relevant [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

8 participants