mundschenk-at / wp-typography

Improve your WordPress micro typography.
https://code.mundschenk.at/wp-typography/
Other
22 stars 3 forks source link

Escaped typography markup in URL autocomplete (Gutenberg) #245

Open strarsis opened 5 years ago

strarsis commented 5 years ago

Issue Overview

In Gutenberg editor the URL autocomplete for links shows escaped markup for typography (e.g. <span class="amp">&</span>). Either the raw HTML markup should be somehow injected (so it is not escaped) or the page names shouldn't be filtered at all.

Steps to Reproduce (for bugs)

  1. Install + activate wp-typography plugin.
  2. Create a page that contains text in its title that wp-typography should process (& is a good example as this should be handled by default).
  3. Open a page in Gutenberg editor.
  4. Highlight text in editor and select the link button.
  5. In autocomplete, the page title should appear with escaped markup (HTML visible).

Expected Behavior

No escaped HTML in URL autocompletion.

Current Behavior

Escaped HTML in URL autocompletion.

Possible Solution

Related Issues and/or PRs

https://github.com/mundschenk-at/wp-typography/issues/229

mundschenk-at commented 5 years ago

That's a Gutenberg bug. The REST-API search endpoint intentionally uses get_the_title() to retrieve the "rendered" title attribute. They should either strip the tags themselves or not escape the value.

strarsis commented 5 years ago

@mundschenk-at: Would you recommend that I create an issue in the Gutenberg issue tracker for this?

mundschenk-at commented 5 years ago

Only if it still happens with the current development release of the Gutenberg plugin, otherwise it should be reported in the WordPress.org trac. I can't say how quickly it will be fixed (so I may create a workaround in the next release anyway), but it should be reported there.

mundschenk-at commented 5 years ago

@strarsis Have you opened a ticket?

strarsis commented 5 years ago

@mundschenk-at: No, I haven't yet. I have been unsure whether you or me should create it. 😸

mundschenk-at commented 5 years ago

@strarsis Feel free to create the ticket. I'll comment with any follow-up information.

strarsis commented 5 years ago

https://github.com/WordPress/gutenberg/issues/15727

strarsis commented 4 years ago

Now I encountered this issue, too, in a different context. I use the_title filter to add something to the markup that the Latest Posts Gutenberg core block uses (server-side rendering). In the autocomplete this markup crops up, even when using if(is_admin()) return $title; // skip.

mundschenk-at commented 4 years ago

Probably because the REST API is its own thing, and Gutenberg uses the rendered attribute value from the JSON response.

strarsis commented 4 years ago

@mundschenk-at: Any workaround for this until Gutenberg fixes this issue? I use the filter in the theme, it should not interfere with the backend.

mundschenk-at commented 4 years ago

@mundschenk-at: Any workaround for this until Gutenberg fixes this issue? I use the filter in the theme, it should not interfere with the backend.

You can use the typo_content_filters filter to unset the heading filter and use \WP_Typography::filter( $title, true ) in your templates (where appropriate).