def handle_mlabel(self, cmd_args, elem): # pylint: disable=line-too-long r"""Handle ``\MLabel`` command. Will search for the previous header element and update its ID to the ID defined in the command. Otherwise proceed like ``\MDeclareSiteUXID``. Hides identifier in fake element like (:py:func:`innoconv_mintmod.mintmod_filter.commands.Commands.handle_mdeclaresiteuxid`). """ identifier = cmd_args[0] # Ignore MLabel in test sections as this would mess up the previous # section caption. if "Abschlusstest" in identifier or "Ausgangstest" in identifier: return [] # attach identifier to previous element try: get_remembered(elem.doc, "label").identifier = identifier return [] except AttributeError: pass # otherwise return a div/span with ID that is parsed in the parent # process if isinstance(elem, pf.Block): ret = pf.Div() else: ret = pf.Span() ret.identifier = "{}-{}".format(INDEX_LABEL_PREFIX, identifier) ret.classes = [INDEX_LABEL_PREFIX] ret.attributes = {"hidden": "hidden"} return ret
def test_remember(self): """It should remember and forget.""" doc = pf.Doc() self.assertIsNone(get_remembered(doc, "somekey")) header = pf.Header() remember(doc, "header", header) rememembered_el = get_remembered(doc, "header") self.assertEqual(rememembered_el, header) self.assertIsNone(get_remembered(doc, "header")) img = pf.Image() remember(doc, "img", img) rememembered_img = get_remembered(doc, "img") self.assertEqual(rememembered_img, img) self.assertIsNone(get_remembered(doc, "img"))
def handle_mlintervalquestion(self, cmd_args, elem): r"""Handle questions defined by ``\MLIntervalQuestion`` command""" return Question( cmd_args, mintmod_class="MLIntervalQuestion", oktypes=elem.parent.content.oktypes, points=get_remembered(elem.doc, "points", keep=True), )
def handle_msetsectionid(self, cmd_args, elem): r"""Handle ``\MSetSectionID`` command. Will search for the previous header element and update its ID to the ID defined in the command. """ identifier = cmd_args[0] # attach identifier to previous element try: get_remembered(elem.doc, "label").identifier = identifier except AttributeError: pass return []