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

Allow ID attributes on any elements #8124

Merged
merged 2 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions packages/blocks/src/api/raw-handling/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,20 @@ describe( 'removeInvalidHTML', () => {
expect( removeInvalidHTML( input, schema ) ).toBe( output );
} );

it( 'should keep id attributes', () => {
const input = '<p id="foo">test</p>';
const output = '<p id="foo">test</p>';
expect( removeInvalidHTML( input, schema ) ).toBe( output );
} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a unit tests for headings (where we keep the attribute?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without moving things around, or copy/pasting code. Testing that functionality requires access to getRawTransformations(), which currently isn't exported.


it( 'should remove multiple attributes', () => {
const input = '<p class="test" id="test">test</p>';
const input = '<p class="test" style="test">test</p>';
const output = '<p>test</p>';
expect( removeInvalidHTML( input, schema ) ).toBe( output );
} );

it( 'should deep remove attributes', () => {
const input = '<p class="test">test <em id="test">test</em></p>';
const input = '<p class="test">test <em style="test">test</em></p>';
const output = '<p>test <em>test</em></p>';
expect( removeInvalidHTML( input, schema ) ).toBe( output );
} );
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/raw-handling/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function cleanNodeList( nodeList, doc, schema, inline ) {
if ( node.hasAttributes() ) {
// Strip invalid attributes.
Array.from( node.attributes ).forEach( ( { name } ) => {
if ( name !== 'class' && ! includes( attributes, name ) ) {
if ( name !== 'class' && name !== 'id' && ! includes( attributes, name ) ) {
node.removeAttribute( name );
}
} );
Expand Down