-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
559 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Browser dependencies | ||
*/ | ||
const { ELEMENT_NODE } = window.Node; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { isInlineWrapper, isInline, isAllowedBlock, deepFilterNodeList } from './utils'; | ||
import createUnwrapper from './create-unwrapper'; | ||
|
||
export default function( node, doc ) { | ||
if ( node.nodeType !== ELEMENT_NODE ) { | ||
return; | ||
} | ||
|
||
if ( ! isInlineWrapper( node ) ) { | ||
return; | ||
} | ||
|
||
deepFilterNodeList( node.childNodes, [ | ||
createUnwrapper( | ||
( childNode ) => ! isInline( childNode ) && ! isAllowedBlock( node, childNode ), | ||
( childNode ) => childNode.nextElementSibling && doc.createElement( 'BR' ) | ||
), | ||
], doc ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Paste | ||
|
||
This folder contains all paste specific logic (filters, converters, normalisers...). Each module is tested on their own, and in addition we have some integration tests for frequently used editors. | ||
|
||
## Support table | ||
|
||
| Source | Formatting | Headings | Lists | Image | Separator | Table | | ||
| ---------------- | ---------- | -------- | ----- | ----- | --------- | ----- | | ||
| Google Docs | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ||
| Apple Pages | ✓ | ✘ [1] | ✓ | ✘ [1] | n/a | ✓ | | ||
| MS Word | ✓ | ✓ | ✓ | ✘ [2] | n/a | ✓ | | ||
| MS Word Online | ✓ | ✘ [3] | ✓ | ✓ | n/a | ✓ | | ||
| Markdown | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ||
| Legacy WordPress | ✓ | ✓ | ✓ | … [4] | ✓ | ✓ | | ||
| Web | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ||
|
||
|
||
1. Apple Pages does not pass heading and image information. | ||
2. MS Word only provides a local file path, which cannot be accessed in JavaScript for security reasons. | ||
3. Still to do for MS Word Online. | ||
4. For caption and gallery shortcodes, see #2874. | ||
|
||
## Other notable capabilities | ||
|
||
* Filters out analytics trackers in the form of images. | ||
* Direct image data pasting coming soon. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Browser dependencies | ||
*/ | ||
const { TEXT_NODE } = window.Node; | ||
|
||
export default function( node ) { | ||
if ( node.nodeType !== TEXT_NODE ) { | ||
return; | ||
} | ||
|
||
const parentNode = node.parentNode; | ||
|
||
if ( [ 'TR', 'TBODY', 'THEAD', 'TFOOT', 'TABLE' ].indexOf( parentNode.nodeName ) === -1 ) { | ||
return; | ||
} | ||
|
||
parentNode.removeChild( node ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { equal } from 'assert'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import inlineContentConverter from '../inline-content-converter'; | ||
import { deepFilterHTML } from '../utils'; | ||
|
||
describe( 'inlineContentConverter', () => { | ||
it( 'should remove non-inline content from inline wrapper', () => { | ||
equal( | ||
deepFilterHTML( '<figcaption><p>test</p><p>test</p></figcaption>', [ inlineContentConverter ] ), | ||
'<figcaption>test<br>test</figcaption>' | ||
); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,61 @@ | ||
<!-- Apple Pages and Apple Notes have the same content structure. --> | ||
<!-- We do not get any heading level info. The classes are useless. --> | ||
<!-- Images are not included either. --> | ||
<p class="p1"><b>This is a </b>title</p> | ||
<p class="p2"><br></p> | ||
<p class="p3"><b>This is a <i>heading</i></b></p> | ||
<p class="p2"><i></i><br></p> | ||
<p class="p4">This is a <b>paragraph</b> with a <a href="https://w.org"><span class="s1">link</span></a>.</p> | ||
<p class="p2"><br></p> | ||
<p class="p1"><span class="s1"><b>This is a </b>title</span></p> | ||
<p class="p2"><span class="s1"></span><br></p> | ||
<p class="p3"><span class="s1"><b>This is a <i>heading</i></b></span></p> | ||
<p class="p2"><span class="s1"></span><br></p> | ||
<p class="p4"><span class="s1">This is a <b>paragraph</b> with a <a href="https://w.org"><span class="s2">link</span></a>.</span></p> | ||
<p class="p2"><span class="s1"></span><br></p> | ||
<ul class="ul1"> | ||
<li class="li5"><span class="s2">A</span></li> | ||
<li class="li4"><span class="s3"></span>Bulleted</li> | ||
<li class="li4"><span class="s1">A</span></li> | ||
<li class="li4"><span class="s1">Bulleted</span></li> | ||
<ul class="ul1"> | ||
<li class="li4"><span class="s3"></span>Indented</li> | ||
<li class="li4"><span class="s1">Indented</span></li> | ||
</ul> | ||
<li class="li4"><span class="s3"></span>List</li> | ||
<li class="li4"><span class="s1">List</span></li> | ||
</ul> | ||
<p class="p2"><br></p> | ||
<p class="p2"><span class="s1"></span><br></p> | ||
<ol class="ol1"> | ||
<li class="li4">One</li> | ||
<li class="li4">Two</li> | ||
<li class="li4">Three</li> | ||
<li class="li4"><span class="s1">One</span></li> | ||
<li class="li4"><span class="s1">Two</span></li> | ||
<li class="li4"><span class="s1">Three</span></li> | ||
</ol> | ||
<p class="p2"><br></p> | ||
<p class="p4">An Image:</p> | ||
<p class="p2"><br></p> | ||
<p class="p6"><br></p> | ||
<p class="p2"><span class="s1"></span><br></p> | ||
<table cellspacing="0" cellpadding="0" class="t1"> | ||
<tbody> | ||
<tr> | ||
<td valign="top" class="td1"> | ||
<p class="p5"><span class="s1">One</span></p> | ||
</td> | ||
<td valign="top" class="td2"> | ||
<p class="p5"><span class="s1">Two</span></p> | ||
</td> | ||
<td valign="top" class="td1"> | ||
<p class="p5"><span class="s1">Three</span></p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td valign="top" class="td3"> | ||
<p class="p6"><span class="s1">1</span></p> | ||
</td> | ||
<td valign="top" class="td4"> | ||
<p class="p6"><span class="s1">2</span></p> | ||
</td> | ||
<td valign="top" class="td3"> | ||
<p class="p6"><span class="s1">3</span></p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td valign="top" class="td1"> | ||
<p class="p5"><span class="s1">I</span></p> | ||
</td> | ||
<td valign="top" class="td2"> | ||
<p class="p5"><span class="s1">II</span></p> | ||
</td> | ||
<td valign="top" class="td1"> | ||
<p class="p5"><span class="s1">III</span></p> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p class="p2"><span class="s1"></span><br></p> | ||
<p class="p4"><span class="s1">An image: </span></p> | ||
<p class="p2"><span class="s1"></span><br></p> |
Oops, something went wrong.