Commits

Rajeev Sebastian committed 0191b13

add utility to format contents to html

  • Participants
  • Parent commits 14218cd

Comments (0)

Files changed (1)

 from vcs.utils import safe_unicode
 from vcs.exceptions import VCSError
 
-from pygments import lexers
+from pygments import lexers, highlight
+from pygments.formatters import HtmlFormatter
 
 class NodeError(VCSError):
     pass
             lexer = lexers.TextLexer()
         # returns first alias
         return lexer
+        
+    @LazyProperty
+    def in_html(self):
+        """
+        Returns formatted code as html via Pygments
+        """
+        formatter = HtmlFormatter()
+        ret = '<style type="text/css">'+formatter.get_style_defs(arg='')+'</style>'
+        ret += highlight(self.content, self.lexer, formatter)
+        return ret
 
     @LazyProperty
     def lexer_alias(self):