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

Autocompleter lets you insert multiple More blocks #4225

Closed
noisysocks opened this issue Jan 2, 2018 · 8 comments · Fixed by #7166
Closed

Autocompleter lets you insert multiple More blocks #4225

noisysocks opened this issue Jan 2, 2018 · 8 comments · Fixed by #7166
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Bug An existing feature does not function as intended
Milestone

Comments

@noisysocks
Copy link
Member

noisysocks commented Jan 2, 2018

more-bug

Steps to reproduce

  1. Create a new post
  2. Insert a More block using the /slash shortcut.
  3. Insert another More block using the /slash shortcut.

Expected result

Step (3) should be impossible as only one More is allowed in a post.

Actual result

More, More, More!

Root cause

Autocompleter doesn't respect the useOnce property.

@noisysocks noisysocks added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Bug An existing feature does not function as intended labels Jan 2, 2018
@karmatosed karmatosed added this to the Merge Proposal milestone Jan 25, 2018
@bobbingwide
Copy link
Contributor

bobbingwide commented Feb 9, 2018

In the classic world it is quite valid to have the more tag multiple times in a post:

  • posts which support multiple languages
  • posts with shortcodes that check the viewers capability.
  • and possibly even paged pages

When implementing this fix we need to take backward compatibility into consideration.

Examples:
The qtranslate-x plugin supports multiple language using pseudo shortcodes

[:en]
English
<!--more-->
words - content
[:fr]
Francais
<!--more-->
mots - contenu
[:] 

@mcsf
Copy link
Contributor

mcsf commented Feb 9, 2018

Thanks for providing that perspective, @bobbingwide. Such an example, however, really pushes the editor's ability to accommodate for the disparate uses of shortcodes and tags. This is probably one of those scenarios where the most viable option is to use the Classic block. Otherwise, Gutenberg will treat the shortcodes markings as individual shortcodes, or actually not detect them at all, since these ([:en]) start with a colon, which is currently not part of the pattern Gutenberg looks for:

type: 'shortcode',
// Per "Shortcode names should be all lowercase and use all
// letters, but numbers and underscores should work fine too.
// Be wary of using hyphens (dashes), you'll be better off not
// using them." in https://codex.wordpress.org/Shortcode_API
// Require that the first character be a letter. This notably
// prevents footnote markings ([1]) from being caught as
// shortcodes.
tag: '[a-z][a-z0-9_-]*',

Interestingly, upon testing this, the fact that those shortcodes start with a colon means that, when pasting, Gutenberg resorts to the Classic block on its own, thus preserving the legacy content:

Without : support With : support
screen shot 2018-02-09 at 12 24 22 screen shot 2018-02-09 at 12 25 01

My takeaway is that we will never be able to anticipate all the possible ways in which shortcodes are used to structure special content. It it manageable to look at content within regular opening and closing tags:

[en]
Hello
[/en]
[fr]
Bonjour
[/fr]

but that's the extent of what we can infer.

@bobbingwide
Copy link
Contributor

Note: I have just created a prototype test case which demonstrates that it's quite possible to create and display paginated content with multiple excerpts being correctly extracted.

Page 1 excerpt
<!--more more-->
Page 1 content
<!--nextpage-->
Page 2 excerpt
<!--more again-->
Page 2 content
<!--nextpage-->
Page 3 excerpt
<!--more third-->
Page 3 content

Whilst WordPress core doesn't cater for multiple extracts they can be achieved using very little code.

add_filter( "get_the_excerpt", array( $this, "paginated_excerpt" ), 10, 2 );
	
function paginated_excerpt( $excerpt, $post ) {
  global $more;
  $saved = $more;
  $more = false;
  $excerpt = get_the_content();
  $more = $saved;
 return $excerpt;
}

@mcsf
Copy link
Contributor

mcsf commented Feb 9, 2018

Correct, though I'm not concerned about the server-side aspect, where I expect things to work the same way. I'm concerned about the editor, namely recognizing what is what.

@bobbingwide
Copy link
Contributor

So long as it's clearly documented what the differences are between old and new.

@mtias
Copy link
Member

mtias commented May 8, 2018

We show this if you add more than one now:

image

@mtias mtias closed this as completed May 8, 2018
@ocean90
Copy link
Member

ocean90 commented May 17, 2018

While the notice is nice, we shouldn't allow adding multiple useOnce blocks via autocompleter at first place.

See also #3968.

@ocean90 ocean90 reopened this May 17, 2018
@noisysocks
Copy link
Member Author

Noting that #6067 should fix this because it makes the autocompleter use getInserterItems which takes into account useOnce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Bug An existing feature does not function as intended
Projects
None yet
6 participants