about summary refs log tree commit diff
path: root/src/lib/strings/rich-text-sanitize.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/strings/rich-text-sanitize.ts')
-rw-r--r--src/lib/strings/rich-text-sanitize.ts32
1 files changed, 0 insertions, 32 deletions
diff --git a/src/lib/strings/rich-text-sanitize.ts b/src/lib/strings/rich-text-sanitize.ts
deleted file mode 100644
index 0b5895707..000000000
--- a/src/lib/strings/rich-text-sanitize.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import {RichText} from './rich-text'
-
-const EXCESS_SPACE_RE = /[\r\n]([\u00AD\u2060\u200D\u200C\u200B\s]*[\r\n]){2,}/
-const REPLACEMENT_STR = '\n\n'
-
-export function removeExcessNewlines(richText: RichText): RichText {
-  return clean(richText, EXCESS_SPACE_RE, REPLACEMENT_STR)
-}
-
-// TODO: check on whether this works correctly with multi-byte codepoints
-export function clean(
-  richText: RichText,
-  targetRegexp: RegExp,
-  replacementString: string,
-): RichText {
-  richText = richText.clone()
-
-  let match = richText.text.match(targetRegexp)
-  while (match && typeof match.index !== 'undefined') {
-    const oldText = richText.text
-    const removeStartIndex = match.index
-    const removeEndIndex = removeStartIndex + match[0].length
-    richText.delete(removeStartIndex, removeEndIndex)
-    if (richText.text === oldText) {
-      break // sanity check
-    }
-    richText.insert(removeStartIndex, replacementString)
-    match = richText.text.match(targetRegexp)
-  }
-
-  return richText
-}