Package com.wontlost.ckeditor.internal
Class ContentManager
java.lang.Object
com.wontlost.ckeditor.internal.ContentManager
Internal class for managing editor content.
Handles content retrieval, setting, sanitization, and transformation.
This class is an internal API and should not be used directly by external code.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record内容统计结果:纯文本字符数与词数。 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountWords(String text) 从纯文本计算词数(纯函数,便于单测;不触碰 HTML 解析)。intgetCharacterCount(String html) Estimate the character count of the content (excluding HTML tags).getContentStats(String html) 一次解析同时计算字符数与词数(review 发现:分别调用 getCharacterCount/getWordCount 会对同一 HTML 重复 Jsoup.parse)。getPlainText(String html) Convert HTML to plain text.getSanitizedHtml(String html) Sanitize HTML using relaxed rules.getSanitizedValue(String html) Get sanitized HTML content.intgetWordCount(String html) Estimate the word count of the content.booleanisContentEmpty(String html) Check whether the content is empty.normalizeForComparison(String html) Normalize HTML content for comparison.sanitizeHtml(String html, org.jsoup.safety.Safelist safelist) Sanitize HTML using custom rules.
-
Constructor Details
-
ContentManager
Create a content manager.- Parameters:
htmlSanitizer- HTML sanitizer, may be null
-
-
Method Details
-
getSanitizedValue
Get sanitized HTML content.null 语义:本方法对 null/空串原样透传(null in → null out),不归一为
""; 这与getSanitizedHtml(java.lang.String)/sanitizeHtml(java.lang.String, org.jsoup.safety.Safelist)/getPlainText(java.lang.String)(对 null 返回"") 不同,是有意的契约差异——本方法保留输入值的 null 语义。调用方若需要空串,应自行归一。- Parameters:
html- raw HTML(可为 null)- Returns:
- sanitized HTML;无 sanitizer 时原样返回;null/空串原样返回
-
getPlainText
Convert HTML to plain text.- Parameters:
html- HTML content- Returns:
- plain text content
-
getSanitizedHtml
Sanitize HTML using relaxed rules.- Parameters:
html- HTML content- Returns:
- sanitized HTML
-
sanitizeHtml
Sanitize HTML using custom rules.- Parameters:
html- HTML contentsafelist- sanitization rules- Returns:
- sanitized HTML
-
normalizeForComparison
Normalize HTML content for comparison.- Parameters:
html- HTML content- Returns:
- normalized HTML
-
isContentEmpty
Check whether the content is empty.- Parameters:
html- HTML content- Returns:
- true if the content is empty or contains only whitespace tags
-
getCharacterCount
Estimate the character count of the content (excluding HTML tags).- Parameters:
html- HTML content- Returns:
- character count
-
getWordCount
Estimate the word count of the content.- Parameters:
html- HTML content- Returns:
- word count
-
getContentStats
一次解析同时计算字符数与词数(review 发现:分别调用 getCharacterCount/getWordCount 会对同一 HTML 重复 Jsoup.parse)。需要同时展示字/词数时用本方法避免重复解析。- Parameters:
html- HTML content- Returns:
- 字符数与词数
-
countWords
从纯文本计算词数(纯函数,便于单测;不触碰 HTML 解析)。分词规则保持不变:按空白切分;CJK(
Character.UnicodeScript.HAN)字符每个计一词, 词内非 CJK 部分整体再计一词。CJK 判定刻意沿用 UnicodeScript.HAN 以保持既有计数行为, 不改用 isIdeographic(二者结果不同,会改变用户的词数)。- Parameters:
text- 纯文本- Returns:
- 词数
-