🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
51
node_modules/parse-latin/lib/plugin/break-implicit-sentences.js
generated
vendored
Normal file
51
node_modules/parse-latin/lib/plugin/break-implicit-sentences.js
generated
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import {toString} from 'nlcst-to-string'
|
||||
import {modifyChildren} from 'unist-util-modify-children'
|
||||
|
||||
// Break a sentence if a white space with more than one new-line is found.
|
||||
export const breakImplicitSentences = modifyChildren(function (
|
||||
child,
|
||||
index,
|
||||
parent
|
||||
) {
|
||||
if (child.type !== 'SentenceNode') {
|
||||
return
|
||||
}
|
||||
|
||||
const children = child.children
|
||||
|
||||
// Ignore first and last child.
|
||||
let position = 0
|
||||
|
||||
while (++position < children.length - 1) {
|
||||
const node = children[position]
|
||||
|
||||
if (
|
||||
node.type !== 'WhiteSpaceNode' ||
|
||||
toString(node).split(/\r\n|\r|\n/).length < 3
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
child.children = children.slice(0, position)
|
||||
|
||||
const insertion = {
|
||||
type: 'SentenceNode',
|
||||
children: children.slice(position + 1)
|
||||
}
|
||||
|
||||
const tail = children[position - 1]
|
||||
const head = children[position + 1]
|
||||
|
||||
parent.children.splice(index + 1, 0, node, insertion)
|
||||
|
||||
if (child.position && tail.position && head.position) {
|
||||
const end = child.position.end
|
||||
|
||||
child.position.end = tail.position.end
|
||||
|
||||
insertion.position = {start: head.position.start, end}
|
||||
}
|
||||
|
||||
return index + 1
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue