32 lines
785 B
Python
32 lines
785 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import re
|
||
|
|
|
||
|
|
|
||
|
|
def sanitize_text(content: str, max_chars: int = 2000) -> str:
|
||
|
|
if len(content) <= max_chars:
|
||
|
|
return content
|
||
|
|
return content[: max_chars - 3] + "..."
|
||
|
|
|
||
|
|
|
||
|
|
def markdown_to_native(md_text: str) -> str:
|
||
|
|
return md_text
|
||
|
|
|
||
|
|
|
||
|
|
def strip_html(content: str) -> str:
|
||
|
|
return re.sub(r"<[^>]+>", "", content or "")
|
||
|
|
|
||
|
|
|
||
|
|
class KuaishouFormat:
|
||
|
|
def __init__(self, max_text_length: int = 2000):
|
||
|
|
self._max_text_length = max_text_length
|
||
|
|
|
||
|
|
def sanitize_text(self, content: str) -> str:
|
||
|
|
return sanitize_text(content, self._max_text_length)
|
||
|
|
|
||
|
|
def markdown_to_native(self, md_text: str) -> str:
|
||
|
|
return markdown_to_native(md_text)
|
||
|
|
|
||
|
|
def strip_html(self, content: str) -> str:
|
||
|
|
return strip_html(content)
|