fix: duplicate rendering of instructions in annotatable xblock (#36445)

In the Annotatable XBlock, the <instructions> element was appearing
twice in the student view:

* Once in "annotatable-instructions" (where it should be).
* Again in "annotatable-content" (where annotations and other content are rendered).

The _render_content method processed and rendered the entire XML
data, including <instructions>, without removing it. The
_extract_instructions method, which is responsible for removing
<instructions>, was not called in _render_content, leading to
duplication.

This fix will:

* Prevents duplicate instructions in the student view.
* Maintains the expected behavior of showing instructions only in
  "annotatable-instructions".
* No impact on existing annotation functionality.
This commit is contained in:
Irtaza Akram
2025-04-10 20:01:38 +05:00
committed by GitHub
parent b9556211be
commit de75c37047
2 changed files with 9 additions and 2 deletions

View File

@@ -140,9 +140,8 @@ class _BuiltInAnnotatableBlock(
""" Renders annotatable content with annotation spans and returns HTML. """
xmltree = etree.fromstring(self.data)
content = etree.tostring(xmltree, encoding='unicode')
self._extract_instructions(xmltree)
xmltree = etree.fromstring(content)
xmltree.tag = 'div'
if 'display_name' in xmltree.attrib:
del xmltree.attrib['display_name']

View File

@@ -134,3 +134,11 @@ class AnnotatableBlockTestCase(unittest.TestCase): # lint-amnesty, pylint: disa
xmltree = etree.fromstring('<annotatable>foo</annotatable>')
actual = self.annotatable._extract_instructions(xmltree) # lint-amnesty, pylint: disable=protected-access
assert actual is None
def test_instruction_removal(self):
xmltree = etree.fromstring(self.sample_xml)
instructions = self.annotatable._extract_instructions(xmltree) # pylint: disable=protected-access
assert instructions is not None
assert "Read the text." in instructions
assert xmltree.find("instructions") is None