Skip to content

Instantly share code, notes, and snippets.

@aduth
Created March 23, 2017 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aduth/ce3a63c9a9cf4c0377b7c6f5e1caeed1 to your computer and use it in GitHub Desktop.
Save aduth/ce3a63c9a9cf4c0377b7c6f5e1caeed1 to your computer and use it in GitHub Desktop.
const parse, { query, text, attr } = wp.blocks.parse;
const quote = parse( '<blockquote><p>...</p><p>...</p><cite>Andrew</cite></blockquote>', {
text: query( 'p', text() ),
cite: text( 'cite' )
} );
// { text: [ "...", "..." ], cite: "Andrew" }
const image = parse( '<figure><img src="img.png" alt="Image"><figcaption>An Image</figcaption></figure>', {
src: attr( 'img', 'src' ),
alt: attr( 'img', 'alt' ),
caption: text( 'figcaption' )
} );
// { src: "img.png", alt: "Image", caption: "An Image" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment