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

Add preformatted block #825

Merged
merged 2 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions blocks/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ import './separator';
import './button';
import './pullquote';
import './table';
import './preformatted';
63 changes: 63 additions & 0 deletions blocks/library/preformatted/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Internal dependencies
*/
import './style.scss';
import { registerBlock, createBlock, query } from '../../api';
import Editable from '../../editable';

const { children } = query;

registerBlock( 'core/preformatted', {
title: wp.i18n.__( 'Preformatted' ),

icon: 'text',

category: 'common',

attributes: {
content: children( 'pre' ),
},

transforms: {
from: [
{
type: 'block',
blocks: [ 'core/text' ],
transform: ( attributes ) =>
createBlock( 'core/preformatted', attributes ),
},
],
to: [
{
type: 'block',
blocks: [ 'core/text' ],
transform: ( attributes ) =>
createBlock( 'core/text', attributes ),
},
],
},

edit( { attributes, setAttributes, focus, setFocus } ) {
const { content } = attributes;

return (
<Editable
tagName="pre"
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
} );
} }
focus={ focus }
onFocus={ setFocus }
/>
);
},

save( { attributes } ) {
const { content } = attributes;

return <pre>{ content }</pre>;
},
} );
5 changes: 5 additions & 0 deletions blocks/library/preformatted/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
div[data-type="core/preformatted"] {
pre {
white-space: pre-wrap;
}
}
5 changes: 5 additions & 0 deletions post-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ window._wpGutenbergPost = {
'<!-- wp:core/table -->',
'<table class="widefat"><thead><tr><th>Version</th><th>Musician</th><th>Date</th></tr></thead><tbody><tr class="alt"><th><a href="https://wordpress.org/news/2003/05/wordpress-now-available/">.70</a></th><td>No musician chosen.</td><td>May 27, 2003</td></tr><tr><th><a href="https://wordpress.org/news/2004/01/wordpress-10/">1.0</a></th><td>Miles Davis</td><td>January 3, 2004</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2004/05/heres-the-beef/">1.2</a></th><td>Charles Mingus</td><td>May 22, 2004</td></tr><tr><th><a href="https://wordpress.org/news/2005/02/strayhorn/">1.5</a></th><td>Billy Strayhorn</td><td>February 17, 2005</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2005/12/wp2/">2.0</a></th><td>Duke Ellington</td><td>December 31, 2005</td></tr><tr><th><a href="https://wordpress.org/news/2007/01/ella-21/">2.1</a></th><td>Ella Fitzgerald</td><td>January 22, 2007</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2007/05/wordpress-22/">2.2</a></th><td>Stan Getz</td><td>May 16, 2007</td></tr><tr><th><a href="https://wordpress.org/news/2007/09/wordpress-23/">2.3</a></th><td>Dexter Gordon</td><td>September 24, 2007</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2008/03/wordpress-25-brecker/">2.5</a></th><td>Michael Brecker</td><td>March 29, 2008</td></tr><tr><th><a href="https://wordpress.org/news/2008/07/wordpress-26-tyner/">2.6</a></th><td>McCoy Tyner</td><td>July 15, 2008</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2008/12/coltrane/">2.7</a></th><td>John Coltrane</td><td>December 10, 2008</td></tr><tr><th><a href="https://wordpress.org/news/2009/06/wordpress-28/">2.8</a></th><td>Chet Baker</td><td>June 11, 2009</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2009/12/wordpress-2-9/">2.9</a></th><td>Carmen McRae</td><td>December 18, 2009</td></tr><tr><th><a href="https://wordpress.org/news/2010/06/thelonious/">3.0</a></th><td>Thelonious Monk</td><td>June 17, 2010</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2011/02/threeone/">3.1</a></th><td>Django Reinhardt</td><td>February 23, 2011</td></tr><tr><th><a href="https://wordpress.org/news/2011/07/gershwin/">3.2</a></th><td>George Gershwin</td><td>July 4, 2011</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2011/12/sonny/">3.3</a></th><td>Sonny Stitt</td><td>December 12, 2011</td></tr><tr><th><a href="https://wordpress.org/news/2012/06/green/">3.4</a></th><td>Grant Green</td><td>June 13, 2012</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2012/12/elvin/">3.5</a></th><td>Elvin Jones</td><td>December 11, 2012</td></tr><tr><th><a href="https://wordpress.org/news/2013/08/oscar/">3.6</a></th><td>Oscar Peterson</td><td>August 1, 2013</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2013/10/basie/">3.7</a></th><td>Count Basie</td><td>October 24, 2013</td></tr><tr><th><a href="https://wordpress.org/news/2013/12/parker/">3.8</a></th><td>Charlie Parker</td><td>December 12, 2013</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2014/04/smith/">3.9</a></th><td>Jimmy Smith</td><td>April 16, 2014</td></tr><tr><th><a href="https://wordpress.org/news/2014/09/benny/">4.0</a></th><td>Benny Goodman</td><td>September 4, 2014</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2014/12/dinah/">4.1</a></th><td>Dinah Washington</td><td>December 18, 2014</td></tr><tr><th><a href="https://wordpress.org/news/2015/04/powell/">4.2</a></th><td>Bud Powell</td><td>April 23, 2015</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2015/08/billie/">4.3</a></th><td>Billie Holiday</td><td>August 18, 2015</td></tr><tr><th><a href="https://wordpress.org/news/2015/12/clifford/">4.4</a></th><td>Clifford Brown</td><td>December 8, 2015</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2016/04/coleman/">4.5</a></th><td>Coleman Hawkins</td><td>April 12, 2016</td></tr><tr><th><a href="https://wordpress.org/news/2016/08/pepper/">4.6</a></th><td>Pepper Adams</td><td>August 16, 2016</td></tr><tr class="alt"><th><a href="https://wordpress.org/news/2016/12/vaughan/">4.7</a></th><td>Sarah Vaughan</td><td>December 6, 2016</td></tr></tbody></table>',
'<!-- /wp:core/table -->',

'<!-- wp:core/preformatted -->',
'<pre>Some <em>preformatted</em> text...<br>And more!</pre>',
'<!-- /wp:core/preformatted -->',

].join( '' ),
},
};