def render_colon_fence(self, token: Token): """Render a code fence with ``:`` colon delimiters.""" # TODO remove deprecation after v0.13.0 match = REGEX_ADMONTION.match(token.info.strip()) if match and match.groupdict( )["name"] in list(STD_ADMONITIONS) + ["figure"]: classes = match.groupdict()["classes"][1:].split(",") name = match.groupdict()["name"] if classes and classes[0]: self.current_node.append( self.reporter.warning( "comma-separated classes are deprecated, " "use `:class:` option instead", line=token_line(token), )) # we assume that no other options have been used token.content = f":class: {' '.join(classes)}\n\n" + token.content if name == "figure": self.current_node.append( self.reporter.warning( ":::{figure} is deprecated, " "use :::{figure-md} instead", line=token_line(token), )) name = "figure-md" token.info = f"{{{name}}} {match.groupdict()['title']}" if token.content.startswith(":::"): # the content starts with a nested fence block, # but must distinguish between ``:options:``, so we add a new line token.content = "\n" + token.content return self.render_fence(token)
def render_fence(self, token: Token): text = token.content if token.info: # Ensure that we'll have an empty string if info exists but is only spaces token.info = token.info.strip() language = token.info.split()[0] if token.info else "" if not self.config.get("commonmark_only", False) and language == "{eval-rst}": # copy necessary elements (source, line no, env, reporter) newdoc = make_document() newdoc["source"] = self.document["source"] newdoc.settings = self.document.settings newdoc.reporter = self.reporter # pad the line numbers artificially so they offset with the fence block pseudosource = ("\n" * token_line(token)) + token.content # actually parse the rst into our document MockRSTParser().parse(pseudosource, newdoc) for node in newdoc: if node["names"]: self.document.note_explicit_target(node, node) self.current_node.extend(newdoc[:]) return elif (not self.config.get("commonmark_only", False) and language.startswith("{") and language.endswith("}")): return self.render_directive(token) if not language: try: sphinx_env = self.document.settings.env language = sphinx_env.temp_data.get( "highlight_language", sphinx_env.config.highlight_language) except AttributeError: pass if not language: language = self.config.get("highlight_language", "") node = nodes.literal_block(text, text, language=language) self.add_line_and_source_path(node, token) self.current_node.append(node)