diff --git a/src/shared/utils/helpers/insertAfterMedia.test.ts b/src/shared/utils/helpers/insertAfterMedia.test.ts
new file mode 100644
index 000000000..55fe0b97a
--- /dev/null
+++ b/src/shared/utils/helpers/insertAfterMedia.test.ts
@@ -0,0 +1,85 @@
+import { insertAfterMedia } from './insertAfterMedia';
+
+describe('insertAfterMedia', () => {
+ it('should insert the string after the first line containing content that does not contain solely media', () => {
+ const markdown = `
+
+
+
+This line does not contain media.
+This line also does not contain media.`;
+ const inserted = 'Inserted string';
+
+ const result = insertAfterMedia(markdown, inserted);
+
+ expect(result).toBe(`
+
+
+
+Inserted string
+This line does not contain media.
+This line also does not contain media.`);
+ });
+
+ it('should append the string to the end if there is no line containing content that does not contain solely media', () => {
+ const markdown = `
+
+
+`;
+ const inserted = 'Inserted string';
+
+ const result = insertAfterMedia(markdown, inserted);
+
+ expect(result).toBe(`
+
+
+
+Inserted string`);
+ });
+
+ it('should insert the string before a line containing both media and text content', () => {
+ const markdown = `
+
+
+
+ This line contains text and media.
+This line does not contain media.`;
+ const inserted = 'Inserted string';
+
+ const result = insertAfterMedia(markdown, inserted);
+
+ expect(result).toBe(`
+
+
+
+Inserted string
+ This line contains text and media.
+This line does not contain media.`);
+ });
+
+ it('should insert the string after a line that contains media wrapped in an alignment block', () => {
+ const markdown = `::: hljs-center
+
+
+
+
+:::
+::: hljs-center :::
+::: hljs-right This line does not contain media. :::
+This line also does not contain media.`;
+ const inserted = 'Inserted string';
+
+ const result = insertAfterMedia(markdown, inserted);
+
+ expect(result).toBe(`::: hljs-center
+
+
+
+
+:::
+::: hljs-center :::
+Inserted string
+::: hljs-right This line does not contain media. :::
+This line also does not contain media.`);
+ });
+});
diff --git a/src/shared/utils/helpers/insertAfterMedia.ts b/src/shared/utils/helpers/insertAfterMedia.ts
index 1c76b3c35..64149c8c9 100644
--- a/src/shared/utils/helpers/insertAfterMedia.ts
+++ b/src/shared/utils/helpers/insertAfterMedia.ts
@@ -14,7 +14,10 @@ export const insertAfterMedia = (markdown: string, inserted: string) => {
let i: number;
for (i = 0; i < lines.length; i++) {
const lineWithoutMedia = lines[i]
- .replaceAll(/^:::\s+hljs-\S+|:::$|<(img|video|audio)[^>]+>|!\[[^\]]*\]\([^)]*\)/gi, '')
+ .replaceAll(
+ /^:::\s+hljs-\S+|:::$|]+>|