1 |
|
2 |
|
3 | var remove = require('unist-util-remove')
|
4 |
|
5 | module.exports = squeeze
|
6 |
|
7 | var whiteSpaceOnly = /^\s*$/
|
8 |
|
9 | function squeeze(ast) {
|
10 | return remove(ast, {cascade: false}, isEmptyParagraph)
|
11 | }
|
12 |
|
13 | // Whether paragraph is empty or composed only of whitespace.
|
14 | function isEmptyParagraph(node) {
|
15 | return node.type === 'paragraph' && node.children.every(isEmptyText)
|
16 | }
|
17 |
|
18 | function isEmptyText(node) {
|
19 | return node.type === 'text' && whiteSpaceOnly.test(node.value)
|
20 | }
|