Files
30-seconds-of-code/node_modules/parse-latin/lib/plugin/make-initial-white-space-siblings.js
2019-08-20 15:52:05 +02:00

26 lines
619 B
JavaScript

'use strict'
var visitChildren = require('unist-util-visit-children')
module.exports = visitChildren(makeInitialWhiteSpaceSiblings)
// Move white space starting a sentence up, so they are the siblings of
// sentences.
function makeInitialWhiteSpaceSiblings(child, index, parent) {
var children = child.children
var next
if (
children &&
children.length !== 0 &&
children[0].type === 'WhiteSpaceNode'
) {
parent.children.splice(index, 0, children.shift())
next = children[0]
if (next && next.position && child.position) {
child.position.start = next.position.start
}
}
}