Skip to content

Commit

Permalink
Markdown block: Add Align and Spacing features (#22429)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-ottinger authored Jan 24, 2022
1 parent 2693eda commit af70dd2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Markdown block: Add Align and Spacing features
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/extensions/blocks/markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export const settings = {
},

supports: {
align: [ 'wide', 'full' ],
html: false,
spacing: {
padding: true,
},
},

edit,
Expand Down
10 changes: 8 additions & 2 deletions projects/plugins/jetpack/extensions/blocks/markdown/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { __ } from '@wordpress/i18n';
import MarkdownIt from 'markdown-it';
import { RawHTML } from '@wordpress/element';
import { __experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles } from '@wordpress/block-editor';

/**
* Module variables
Expand All @@ -21,8 +22,13 @@ const handleLinkClick = event => {
}
};

export default ( { className, source = '' } ) => (
<RawHTML className={ className } onClick={ handleLinkClick }>
const getStyles = ( attributes = {} ) => {
const spacingProps = getSpacingClassesAndStyles?.( attributes );
return spacingProps?.style ? spacingProps.style : {};
};

export default ( { className, source = '', attributes } ) => (
<RawHTML className={ className } onClick={ handleLinkClick } style={ getStyles( attributes ) }>
{ source.length ? markdownConverter.render( source ) : '' }
</RawHTML>
);
6 changes: 5 additions & 1 deletion projects/plugins/jetpack/extensions/blocks/markdown/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
import MarkdownRenderer from './renderer';

export default ( { attributes, className } ) => (
<MarkdownRenderer className={ className } source={ attributes.source } />
<MarkdownRenderer
className={ className }
source={ attributes.source }
attributes={ attributes }
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`MarkdownRenderer renders markdown to HTML as expected 1`] = `
<RawHTML
className="markdown"
onClick={[Function]}
style={Object {}}
>
&lt;h1&gt;Heading&lt;/h1&gt;
&lt;h2&gt;2nd Heading&lt;/h2&gt;
Expand Down

0 comments on commit af70dd2

Please sign in to comment.