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

Markdown block: Add Align and Spacing features #22429

Merged
merged 7 commits into from
Jan 24, 2022
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
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