示例#1
0
文件: handlers.py 项目: Mohanson/zerg
 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
示例#2
0
文件: handlers.py 项目: Mohanson/zerg
 def show(self):
     for node in self.children:
         LOGGER.info("|    " * (node.deep - 1) + node.id + " " + node.string)
         node.show()