🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
62
node_modules/parse-latin/lib/plugin/merge-initialisms.js
generated
vendored
Normal file
62
node_modules/parse-latin/lib/plugin/merge-initialisms.js
generated
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import {toString} from 'nlcst-to-string'
|
||||
import {modifyChildren} from 'unist-util-modify-children'
|
||||
import {numerical} from '../expressions.js'
|
||||
|
||||
// Merge initialisms.
|
||||
export const mergeInitialisms = modifyChildren(function (child, index, parent) {
|
||||
if (index > 0 && toString(child) === '.') {
|
||||
const siblings = parent.children
|
||||
|
||||
const previous = siblings[index - 1]
|
||||
const children = previous.children
|
||||
|
||||
if (
|
||||
previous.type === 'WordNode' &&
|
||||
children &&
|
||||
children.length !== 1 &&
|
||||
children.length % 2 !== 0
|
||||
) {
|
||||
let position = children.length
|
||||
let isAllDigits = true
|
||||
|
||||
while (children[--position]) {
|
||||
const otherChild = children[position]
|
||||
|
||||
const value = toString(otherChild)
|
||||
|
||||
if (position % 2 === 0) {
|
||||
// Initialisms consist of one character values.
|
||||
if (value.length > 1) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!numerical.test(value)) {
|
||||
isAllDigits = false
|
||||
}
|
||||
} else if (value !== '.') {
|
||||
if (position < children.length - 2) {
|
||||
break
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAllDigits) {
|
||||
// Remove `child` from parent.
|
||||
siblings.splice(index, 1)
|
||||
|
||||
// Add child to the previous children.
|
||||
children.push(child)
|
||||
|
||||
// Update position.
|
||||
if (previous.position && child.position) {
|
||||
previous.position.end = child.position.end
|
||||
}
|
||||
|
||||
// Next, iterate over the node *now* at the current position.
|
||||
return index
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue