0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Move text_from_html to wagtail.utils.text

This commit is contained in:
Matt Westcott 2023-04-25 16:57:05 +01:00
parent 5cee28756d
commit 6f86a612a8
3 changed files with 9 additions and 7 deletions

View File

@ -1,6 +1,5 @@
import difflib
from bs4 import BeautifulSoup
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.utils.encoding import force_str
@ -13,11 +12,7 @@ from taggit.managers import TaggableManager
from wagtail import blocks
from wagtail.fields import RichTextField, StreamField
from wagtail.utils.registry import ModelFieldRegistry
def text_from_html(val):
# Return the unescaped text content of an HTML string
return BeautifulSoup(force_str(val), "html5lib").getText()
from wagtail.utils.text import text_from_html
comparison_class_registry = ModelFieldRegistry()

View File

@ -1,7 +1,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.utils.safestring import mark_safe
from wagtail.admin.compare import text_from_html
from wagtail.admin.forms.models import (
WagtailAdminDraftStateFormMixin,
WagtailAdminModelForm,
@ -11,6 +10,7 @@ from wagtail.blocks import StreamValue
from wagtail.coreutils import safe_snake_case
from wagtail.models import DraftStateMixin
from wagtail.rich_text import RichText
from wagtail.utils.text import text_from_html
def get_form_for_model(

7
wagtail/utils/text.py Normal file
View File

@ -0,0 +1,7 @@
from bs4 import BeautifulSoup
from django.utils.encoding import force_str
def text_from_html(val):
# Return the unescaped text content of an HTML string
return BeautifulSoup(force_str(val), "html5lib").getText()