Skip to content

Commit

Permalink
Parser: Parse <!-- more --> tag and <!-- noteaser -->
Browse files Browse the repository at this point in the history
These tags are officially supported by WordPress and are an exception
with the concept of blocks. They contain structural data and yet they
are just HTML comments without any further indication.

The "more" tag supports an optional custom text string and if it is
immediately followed by the "no teaser" tag then that contains
additional information.

In this change we parse those tags and combine them into a single "more"
block with attributes of the custom text and whether or not the
`noTeaser` option has been selected.
  • Loading branch information
dmsnell committed Jul 3, 2017
1 parent 2d7d544 commit 5def46b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion blocks/api/post.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,25 @@ WP_Block_List
= WP_Block*

WP_Block
= WP_Block_Void
= WP_Tag_More
/ WP_Block_Void
/ WP_Block_Balanced
/ WP_Block_Html

WP_Tag_More
= "<!--" WS* "more" customText:(WS+ text:$((!(WS* "-->") .)+) { return text })? WS* "-->" noTeaser:(WS* WP_Tag_NoTeaser)?
{ return {
blockName: 'wp:core/more',
attrs: {
customText: customText,
noTeaser: !! noTeaser
},
rawContent: ''
} }

WP_Tag_NoTeaser
= "<!--" WS* "noteaser" WS* "-->"

WP_Block_Void
= "<!--" WS+ "wp:" blockName:WP_Block_Name WS+ attrs:(a:WP_Block_Attributes WS+ {
/** <?php return $a; ?> **/
Expand Down
3 changes: 3 additions & 0 deletions post-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ window._wpGutenbergPost = {
'<section className="cover-image wp-block-cover-image" style={ { backgroundImage: \'url("https://cldup.com/GCwahb3aOb.jpg");\' } }><h2>Of mountains & printing presses</h2></section>',
'<!-- /wp:core/cover-image -->',

'<!-- more Keep on reading! -->',
'<!-- noteaser -->',

'<!-- wp:core/text { "project": { "name": "gutenberg", "for": "WordPress" }, "isAwesome": true } -->',
'<p>The goal of this new editor is to make adding rich content to WordPress simple and enjoyable. This whole post is composed of <em>pieces of content</em>—somewhat similar to LEGO bricks—that you can move around and interact with. Move your cursor around and you\'ll notice the different blocks light up with outlines and arrows. Press the arrows to reposition blocks quickly, without fearing about losing things in the process of copying and pasting.</p>',
'<!-- /wp:core/text -->',
Expand Down

0 comments on commit 5def46b

Please sign in to comment.