Skip to content

Commit

Permalink
temp: add mdast-util-first-sentence package x3
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyauhalin committed Dec 12, 2024
1 parent 78390aa commit 66d594a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/mdast-util-first-sentence/lib/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const cs: [string, string][] = [
["**a. b**", "**a.**"],
["**a*b. c*d**", "**a*b.***"],
["A container. Box", "A container."],
["on `I`", "on `I`."],
]

for (const [a, e] of cs) {
Expand Down
14 changes: 11 additions & 3 deletions packages/mdast-util-first-sentence/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import {
isParagraphNode,
isParentNode,
} from "@onlyoffice/mdast-util-is-node"
import {type Node, type Parent, type Root, type RootContent} from "mdast"
import {
type Node,
type Parent,
type Root,
type RootContent,
type Text,
} from "mdast"
import {toString} from "mdast-util-to-string"
import {split} from "sentence-splitter"
import {English} from "sentence-splitter/lang"
Expand Down Expand Up @@ -54,10 +60,12 @@ function append(c: {s: string}, r: Parent, n: unknown): void {
}

if (!c.s && !t.value.endsWith(".")) {
t.value += "."
const d: Text = {type: "text", value: "."}
r.children.push(t as RootContent, d)
} else {
r.children.push(t as RootContent)
}

r.children.push(t as RootContent)
return
}

Expand Down

0 comments on commit 66d594a

Please sign in to comment.