-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from FrancisMengx/change-getTextContent
Add getTextContent
- Loading branch information
Showing
6 changed files
with
50 additions
and
9 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
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 @@ | ||
import ContentTraverser from '../contentTraverser/ContentTraverser'; | ||
|
||
/** | ||
* get block element's text content. | ||
* @param rootNode Root node that the get the textContent of. | ||
* @returns text content of given text content. | ||
*/ | ||
export default function getTextContent(rootNode: Node): string { | ||
const traverser = ContentTraverser.createBodyTraverser(rootNode); | ||
let block = traverser && traverser.currentBlockElement; | ||
let textContent: string[] = []; | ||
|
||
while (block) { | ||
textContent.push(block.getTextContent()); | ||
block = traverser.getNextBlockElement(); | ||
} | ||
|
||
return textContent.join('\n'); | ||
} |
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