feat: remove the 10,000-character article body limit and make the New article body optional
This commit is contained in:
1 parent
5e05b606a7
commit
10ec74c8cf
28 files changed
+860
-397
No files matched your search
@@ -0,0 +1,23 @@
|
||||
const HTML_MIME = 'text/html'
|
||||
const WHITESPACE = /\s+/
|
||||
const EMPTY_DOCUMENT = '<p></p>'
|
||||
const BLOCK_END = /<\/(?:p|h[1-6]|li|blockquote|pre|div)>|<br\s*\/?>/gi
|
||||
|
||||
export const LARGE_BODY_CHARACTERS = 50000
|
||||
|
||||
export function isLargeBody(characters: number) {
|
||||
return characters >= LARGE_BODY_CHARACTERS
|
||||
}
|
||||
|
||||
export type BodyCounts = { words: number; characters: number }
|
||||
|
||||
export function bodyCounts(html: string): BodyCounts {
|
||||
if (html.length === 0 || html === EMPTY_DOCUMENT) {
|
||||
return { words: 0, characters: 0 }
|
||||
}
|
||||
const text =
|
||||
new DOMParser().parseFromString(html.replace(BLOCK_END, '$& '), HTML_MIME).body
|
||||
.textContent ?? ''
|
||||
const words = text.split(WHITESPACE).filter(Boolean).length
|
||||
return { words, characters: html.length }
|
||||
}
|
||||
Reference in new issue
Block a user