Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
791305a
Add footnotes control button to paragraph block
Aljullu May 2, 2018
533aa51
Store footnote ids in the block object
Aljullu May 2, 2018
95237fc
Create footnotes block on editor setup and update footnotes on block …
Aljullu May 4, 2018
213150e
Create Footnotes block
Aljullu May 5, 2018
2e6de5e
Use auto-incrementing numbers instead of asterisks for footnotes
Aljullu May 5, 2018
40dc686
Update footnotes block when inserting or removing blocks
Aljullu May 5, 2018
b5cee89
Make footnotes block to render nothing if there are no footnotes
Aljullu May 5, 2018
3941d18
Rename variables like 'newState' to 'nextState' to keep consistency w…
Aljullu May 6, 2018
55889c2
Use a template literal for the footnotes markup
Aljullu May 6, 2018
202dfd9
Save block footnotes in the block attributes instead of a block prope…
Aljullu May 6, 2018
e8597a0
Use withSelect HOC in Footnotes block so it's automatically updated w…
Aljullu May 6, 2018
ec802ab
Clean up parser code no longer being used
Aljullu May 6, 2018
d2309af
Simplify the code which rendersthe footnotes block
Aljullu May 6, 2018
e7dc2bc
Create insertFootnotesBlock action to create the footnotes block when…
Aljullu May 8, 2018
23a3037
Remove footnotes block when the last footnote is deleted
Aljullu May 8, 2018
f519cac
Import parseFootnotesFromContent from @wordpress/editor instead of @w…
Aljullu May 8, 2018
e7715cd
Update paragraph snapshots with blockFootnotes attribute
Aljullu May 8, 2018
a9ddeee
Flatten the blocks before searching for footnotes
Aljullu May 9, 2018
db6e61d
Clean up unnecessary properties from footnotes tests
Aljullu May 9, 2018
991a67a
Allow only one instance of footnotes block
Aljullu May 10, 2018
bed9b39
Remove check if core/editor selector is defined in footnotes block
Aljullu May 15, 2018
33d0045
Add/remove the footnotes blocks every time the first footnote is adde…
Aljullu May 16, 2018
d06aff6
Rename footnote SUP element attribute from data-footnote-id to data-w…
Aljullu May 20, 2018
75fc957
Clean up footnotes block attributes
Aljullu May 20, 2018
089dd9d
Optimize checking if footnotes block must be added/removed
Aljullu May 20, 2018
c33beac
Update footnotes block fixtures
Aljullu May 21, 2018
8c2a1a2
Raise paragraph key in pullquote test so it doesn't collide with rece…
Aljullu May 21, 2018
b3c303d
Extract blockFootnotes paragraph attribute from the markup
Aljullu May 21, 2018
14b9b2d
Refactor getFootnotes selector
Aljullu May 21, 2018
0646693
Several minor fixes and typos corrected
Aljullu May 21, 2018
ac2e5af
Don't trigger updateFootnotes when spliting a paragraph block
Aljullu May 21, 2018
72277b5
Update footnotes attribute when the order is changed
Aljullu May 22, 2018
11794cc
Order footnotes when saving footnotes block
Aljullu May 27, 2018
c958cca
Rename FootnotesEditor to FootnotesEdit to keep consistency with othe…
Aljullu Jun 4, 2018
578d71a
Replace spaces with tabs in footnotes style sheets
Aljullu Jun 4, 2018
400140f
Make the footnote number non-editable
Aljullu Jun 10, 2018
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
Prev Previous commit
Next Next commit
Store footnote ids in the block object
Everytime the block is modified, it parses its code and stores the footnotes in the block object.
  • Loading branch information
Aljullu committed May 20, 2018
commit 533aa51007c20b2cdff7ec258d3271f2f3fe1dc8
1 change: 1 addition & 0 deletions blocks/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
export {
default as parse,
getBlockAttributes,
parseFootnotesFromContent,
parseWithAttributeSchema,
} from './parser';
export { default as rawHandler, getPhrasingContentSchema } from './raw-handling';
Expand Down
28 changes: 28 additions & 0 deletions blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@ export function getAttributesAndInnerBlocksFromDeprecatedVersion( blockType, inn
}
}

/**
* Parses the content and extracts the list of footnotes.
*
* @param {?Array} content The content to parse.
*
* @return {Array} Array of footnote ids.
*/
export function parseFootnotesFromContent( content ) {
if ( ! content || ! Array.isArray( content ) ) {
return [];
}

return content.reduce( ( footnotes, element ) => {
if ( element.type === 'sup' &&
element.props.className === 'footnote' &&
element.props[ 'data-footnote-id' ] ) {
return footnotes.concat( { id: element.props[ 'data-footnote-id' ] } );
}

return footnotes;
}, [] );
}

/**
* Creates a block with fallback to the unknown type handler.
*
Expand Down Expand Up @@ -297,6 +320,11 @@ export function createBlockWithFallback( blockNode ) {
}
}

const footnotes = parseFootnotesFromContent( block.attributes.content );
if ( footnotes.length ) {
block.footnotes = footnotes;
}

return block;
}

Expand Down
26 changes: 26 additions & 0 deletions blocks/api/test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getBlockAttribute,
getBlockAttributes,
asType,
parseFootnotesFromContent,
createBlockWithFallback,
getAttributesAndInnerBlocksFromDeprecatedVersion,
default as parse,
Expand Down Expand Up @@ -312,6 +313,31 @@ describe( 'block parser', () => {
} );
} );

describe( 'parseFootnotesFromContent', () => {
it( 'should return empty array if there is no content', () => {
const footnotes = parseFootnotesFromContent();

expect( footnotes ).toEqual( [] );
} );
it( 'should parse content and return footnote ids', () => {
const content = [
'Lorem ipsum',
{
type: 'sup',
props: {
className: 'footnote',
'data-footnote-id': '12345',
},
},
'is a text',
];

const footnotes = parseFootnotesFromContent( content );

expect( footnotes ).toEqual( [ { id: '12345' } ] );
} );
} );

describe( 'createBlockWithFallback', () => {
it( 'should create the requested block if it exists', () => {
registerBlockType( 'core/test-block', defaultBlockSettings );
Expand Down
3 changes: 2 additions & 1 deletion editor/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
/**
* WordPress dependencies
*/
import { isSharedBlock } from '@wordpress/blocks';
import { isSharedBlock, parseFootnotesFromContent } from '@wordpress/blocks';
import { combineReducers } from '@wordpress/data';

/**
Expand Down Expand Up @@ -321,6 +321,7 @@ export const editor = flow( [
[ action.uid ]: {
...state[ action.uid ],
attributes: nextAttributes,
footnotes: parseFootnotesFromContent( nextAttributes.content ),
},
};

Expand Down