Example #1
0
 def __call__(self, document):
     for index, pre in enumerate(document.soup.select("pre")):
         context = str(pre.string)
         try:
             lexer = guess_lexer(context)
         except ClassNotFound:
             LOGGER.info("code block %s colored by %s" % (index, "Normal String"))
         else:
             context_drawed = highlight(context, lexer, HtmlFormatter(linenos=self.linenos, cssclass="source"))
             context_soup = BeautifulSoup(context_drawed, "html.parser")
             pre.replace_with(context_soup)
             LOGGER.info("code block %s colored by %s" % (index, lexer.name))
     document.settings.drawcode = True
Example #2
0
 def show(self):
     for node in self.children:
         LOGGER.info("|    " * (node.deep - 1) + node.id + " " + node.string)
         node.show()