diff --git a/lib/functions.ts b/lib/functions.ts
index 5298d2b..c956a97 100644
--- a/lib/functions.ts
+++ b/lib/functions.ts
@@ -57,3 +57,11 @@ export function stringifyStream(
stream.on("end", () => res(Buffer.concat(chunks).toString("utf-8")));
});
}
+
+export function norm(text: string): string {
+ return text
+ .replace(/\n/g, "
")
+ .replace(/
/gm, "
") + .replace(/
<\/p>/gm, "") + .replace(/
<\/p>/gm, "");
+}
diff --git a/lib/server/dbHelpers/chapterTransformer.ts b/lib/server/dbHelpers/chapterTransformer.ts
index 722e89a..c1361fc 100644
--- a/lib/server/dbHelpers/chapterTransformer.ts
+++ b/lib/server/dbHelpers/chapterTransformer.ts
@@ -1,7 +1,7 @@
import { H3Event, EventHandlerRequest } from "h3";
import { GridFSBucket } from "mongodb";
import mongoose, { Document } from "mongoose";
-import { stringifyStream } from "~/lib/functions";
+import { norm, stringifyStream } from "~/lib/functions";
import { IStory } from "~/models/stories";
import { IChapter } from "~/models/stories/chapter";
import getBucket from "../storyHelpers/getBucket";
@@ -24,11 +24,7 @@ export default async function (
let stream = await stringifyStream(ds);
finObj.currentChapter = {
...cloned.chapters[cindex || event.context.chapterIndex || 0],
- text: stream
- .replace(/\n/g, "
")
- .replace(/
/gm, "
") - .replace(/
<\/p>/gm, "") - .replace(/
<\/p>/gm, ""),
+ text: norm(stream),
};
finObj.totalChapters = story.chapters.length;
finObj.chapterNames = story.chapters.map((a) => a.title);