Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lms/djangoapps/courseware/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from lms.djangoapps.courseware.masquerade import check_content_start_date_for_masquerade_user
from lms.djangoapps.courseware.model_data import FieldDataCache
from lms.djangoapps.courseware.block_render import get_block
from lms.djangoapps.courseware.utils import is_empty_html
from lms.djangoapps.grades.api import CourseGradeFactory
from lms.djangoapps.survey.utils import SurveyRequiredAccessError, check_survey_required_and_unanswered
from openedx.core.djangoapps.content.block_structure.api import get_block_structure_manager
Expand Down Expand Up @@ -418,7 +419,10 @@ def get_course_about_section(request, course, section_key):

if about_block is not None:
try:
html = about_block.render(STUDENT_VIEW).content
# Only render XBlock if content exists to avoid generating empty wrapper divs
content = about_block.data
if not is_empty_html(content):
html = about_block.render(STUDENT_VIEW).content
Copy link
Contributor

@ormsbee ormsbee Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that if you delete everything in the HTML editor for the course overview, it still leaves <p>&nbsp;</p>. It might be worth special casing this to be equivalent to blank.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that! I’ve added an is_empty_html function to handle cases with empty tags that might get saved on the frontend.

I also think this should ideally be validated on the Authoring MFE side. I’m planning to open a separate issue for that.

except Exception: # pylint: disable=broad-except
html = render_to_string('courseware/error-message.html', None)
log.exception(
Expand Down
14 changes: 14 additions & 0 deletions lms/djangoapps/courseware/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import hashlib
import logging
from bs4 import BeautifulSoup

from django.conf import settings
from django.http import HttpResponse, HttpResponseBadRequest
Expand Down Expand Up @@ -229,3 +230,16 @@ def _use_new_financial_assistance_flow(course_id):
):
return True
return False


def is_empty_html(html_content):
"""
Check if HTML content is effectively empty.
"""
if not html_content:
return True

soup = BeautifulSoup(html_content, 'html.parser')
text = soup.get_text(strip=True)

return not text
Loading