-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Format API - Provide a way for some attributes to be removed (or not included) in the saved format. #11484
Comments
Thought I'd mention that this part is really a bug (and the red border is also missing in the classic block), is it worth creating a separate bug ticket to track this? |
Could we not prevent invalid link from being added? Once an invalid link is added, how is the border applied on a new parse, if the attribute is gone? |
I don't think it's feasible that we could write validation to adequately check all types of href values, there are a huge number of variations—different protocols, schemes, forms that could be considered valid use cases. The only option would be to massively restrict the types of hrefs that can be used.
I did wonder about that, for example when loading a post into the editor that has an invalid link. The value would have to be revalidated. I think I see where the issues with this lie with this, it looks like the formatting would have to be re-applied. Using an attribute possibly isn't the best idea then, instead would we need validation to occur during parsing? Over here, #11286 (comment), @chrisvanpatten mentioned that the error is really metadata, and so potentially a similar use-case to the annotations api. I haven't looked too much into that, so I'm not sure if there are similarities. |
Maybe. For annotations it's the entire format. For links it would be just an attribute.
I'm just trying to figure out if it can't be done in a way that is currently possible, before introducing new APIs that might not even solve the issue entirely. So apologies to be a bit pushing back here. Why can't it just be saved with all the rest? I guess you don't want the attribute on the front-end? Maybe we need to make it so you can have an additional attribute set that sources from url: 'href',
isValid: ( { href } ) => isValidURL( href ), |
That seems like something that could work - how would the isValid attribute then affect the resulting format? |
I've assigned this to the 'WordPress 5.0.x Follow Ups' milestone as the issue it blocks (#11793) is also in that milestone. |
Closing as a stale issue. |
Is your feature request related to a problem? Please describe.
This request originates from working on #1838
Currently, in the classic editor, when a user creates a link with an invalid URL, an extra attribute
data-wp-url-error="true"
is added to the outputted<a>
tag. This is used as a selector to add a border around the formatting, indicating there's an error:Classic editor
HTML
CSS
Most importantly, the
data-wp-url-error
attribute is not included in the post content:In Gutenberg, the Format API supports adding an additional attribute like
data-wp-url-error
, but the attribute will always be saved to the post content (even in the classic block). Having a way to mark this attribute as something that shouldn't be included in the post content would enable the same sort of behaviour as the classic editor's link validation.Describe the solution you'd like
There are lots of options. When declaring a format, an additional property could be used to details attributes that aren't saved:
Alternatively, any attribute beginning with 'data-wp' could be removed, or this could be something configurable at a higher level.
Describe alternatives you've considered
The format api could have an entirely different way to specify things like errors that are stored separately from attributes. To allow styling, class names could be added to the formatting tags, but only on the editor side.
The text was updated successfully, but these errors were encountered: