From 66d594acd4cebe38faf099b35af11507ecefe12b Mon Sep 17 00:00:00 2001 From: vanyauhalin Date: Thu, 12 Dec 2024 18:43:08 +0400 Subject: [PATCH] temp: add mdast-util-first-sentence package x3 --- .../mdast-util-first-sentence/lib/main.test.ts | 1 + packages/mdast-util-first-sentence/lib/main.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/mdast-util-first-sentence/lib/main.test.ts b/packages/mdast-util-first-sentence/lib/main.test.ts index f03b30f34..aedb05fdc 100644 --- a/packages/mdast-util-first-sentence/lib/main.test.ts +++ b/packages/mdast-util-first-sentence/lib/main.test.ts @@ -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) { diff --git a/packages/mdast-util-first-sentence/lib/main.ts b/packages/mdast-util-first-sentence/lib/main.ts index 52a2a45b6..2d986b4d0 100644 --- a/packages/mdast-util-first-sentence/lib/main.ts +++ b/packages/mdast-util-first-sentence/lib/main.ts @@ -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" @@ -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 }