def depart_html(self, node): ''' The HTML render ends for the node. ''' node._body_children_end = len(self.body) self.body.append(node.endtag()) node._body_end = len(self.body) if hasattr(node, 'html_extract'): node._html = u"".join(self.body[(node._body_begin + 1):-1]) if hasattr(node, 'yaml_data'): recursive_fill(self.body, node.yaml_data, node) if 'data-aplus-exercise' in node: # If the body of the submit directive is used to define the exercise # description in RST, store the exercise description in the HTML format # into the exercise YAML configuration file. # If the submit directive is used without a body, it contains # a placeholder text node, in which case the instructions in YAML # must not be modified. has_body = not (len(node) > 0 and node[0].tagname == 'p' and len(node[0]) > 0 \ and node[0][0].astext() == translations.get(self.builder.env, 'submit_placeholder')) if has_body: # The instructions in the submit directive body have been # compiled to HTML at this point. # Drop the wrapper <div data-aplus-exercise> element. node.yaml_data['instructions'] = ''.join( self.body[node._body_begin + 1:node._body_end - 1]) if hasattr(node, 'yaml_write'): yaml_writer.write(node.yaml_write, node.pop_yaml()) if node.no_write: self.body = node._real_body
def join_children(self, path, lang1, c1_list, lang2, c2_list): c_list = [] for i,c1 in enumerate( self.require_identical_list_len(path, lang1, c1_list, lang2, c2_list) ): c2 = c2_list[i] c_path = path + [str(i + 1)] c = {} self.require_identical_dict_keys(c_path, lang1, c1, lang2, c2, ACCEPTED_CHILDREN_DEFAULT_KEYS) key = join_keys(lang1, c1.get('key', ''), lang2, c2.get('key', '')) for k,v in c1.items(): if k == 'key': c[k] = key elif k in ('name', 'title', 'static_content'): c[k] = join_values(lang1, v, lang2, c2.get(k, v)) elif k == 'config': e1 = yaml_writer.read(yaml_writer.file_path(self.app.env, v)) e2 = yaml_writer.read(yaml_writer.file_path(self.app.env, c2.get(k, v))) yaml_writer.write( yaml_writer.file_path(self.app.env, key), self.join_exercises(key, lang1, e1, lang2, e2) ) c[k] = key + '.yaml' elif k == 'children': c[k] = self.join_children(c_path, lang1, v, lang2, c2.get(k, [])) elif deep_equals(v, c2.get(k, v)): c[k] = v else: self.raise_unequal(c_path, lang2, k) c_list.append(c) return c_list
def depart_html(self, node): ''' The HTML render ends for the node. ''' node._body_children_end = len(self.body) self.body.append(node.endtag()) node._body_end = len(self.body) if hasattr(node, 'html_extract'): node._html = u"".join(self.body[(node._body_begin+1):-1]) if hasattr(node, 'yaml_data'): recursive_fill(self.body, node.yaml_data, node) if hasattr(node, 'yaml_write'): yaml_writer.write(node.yaml_write, node.pop_yaml()) if node.no_write: self.body = node._real_body
def depart_html(self, node): ''' The HTML render ends for the node. ''' node._body_children_end = len(self.body) self.body.append(node.endtag()) node._body_end = len(self.body) if hasattr(node, 'html_extract'): node._html = "".join(self.body[(node._body_begin + 1):-1]) # Remove <p> elements from inside choice labels and question hints. # They occur in questionnaires. HTML <label> may not contain <p> and # the hints are inserted to a template that already wraps them in <p>. if node.html_extract in ['hint', 'label']: node._html = p_tag_end.sub('', p_tag_start.sub('', node._html)) if hasattr(node, 'yaml_data'): recursive_fill(self.body, node.yaml_data, node) if hasattr(node, 'yaml_write'): yaml_writer.write(node.yaml_write, node.pop_yaml()) if node.no_write: self.body = node._real_body
def write(app, exception): ''' Writes the table of contents level configuration. ''' if app.builder.name != 'html': # course configuration YAML is only built with the Sphinx HTML builder # because some parts of the YAML generation have only been implemented # in the visit methods of the HTML builder (aplus_nodes functions # visit_html and depart_html) return if exception: return root = app.env.get_doctree(app.config.master_doc) # Check for language tree. tocs = root.traverse(addnodes.toctree) keys = set() if tocs and tocs[0].get('rawcaption') == u'Select language': app.info('Detected language tree.') indexes = [] for docname, _, doc in traverse_tocs(app, root): i = docname.rfind('_') if i < 0: raise SphinxError( 'Language postfix is required (e.g. docname_en): ' + docname) lang = docname[(i + 1):] app.info( 'Traverse document elements to write configuration index ({}).' .format(lang)) index = make_index(app, doc) yaml_writer.write(yaml_writer.file_path(app.env, 'index_' + lang), index) indexes.append((lang, index)) app.info('Joining language tree to one index.') index = toc_languages.join(app, indexes) append_manual_content(app, index) yaml_writer.write(yaml_writer.file_path(app.env, 'index'), index) keys |= set(m['key'] for m in index['modules']) else: app.info('Traverse document elements to write configuration index.') index = make_index(app, root) append_manual_content(app, index) yaml_writer.write(yaml_writer.file_path(app.env, 'index'), index) keys |= set(m['key'] for m in index['modules']) # Rewrite links for remote inclusion. app.info('Retouch all files to rewrite links.') keys |= {'toc', 'user', 'account'} html_tools.rewrite_outdir(app.outdir, keys, app.config.static_host)