浏览代码

added export_text in _format_output

Vividha 3 年之前
父节点
当前提交
35ab306308
共有 2 个文件被更改,包括 6 次插入4 次删除
  1. 4 2
      howdoi/howdoi.py
  2. 2 2
      test_howdoi.py

+ 4 - 2
howdoi/howdoi.py

@@ -323,7 +323,7 @@ def _format_output(args, code):
     # or the query arguments
     for keyword in args['query'].split() + args['tags']:
         try:
-            lexer = get_lexer_by_name(keyword)
+            lexer = get_lexer_by_name(keyword).name
             break
         except ClassNotFound:
             pass
@@ -336,7 +336,9 @@ def _format_output(args, code):
             return code
 
     syntax = Syntax(code, lexer, background_color="default", line_numbers=False)
-    return syntax
+    console = Console(record=True)
+    console.print(syntax)
+    return console.export_text(styles=True)
 
 
 def _is_question(link):

+ 2 - 2
test_howdoi.py

@@ -195,8 +195,8 @@ class HowdoiTestCase(unittest.TestCase):  # pylint: disable=too-many-public-meth
         query = self.queries[0]
         normal = howdoi.howdoi(query)
         colorized = howdoi.howdoi('-c ' + query)
-        self.assertTrue(normal.find('[39;') == -1)
-        self.assertTrue(colorized.find('[39;') != -1)
+        self.assertTrue(normal.find('[38;') == -1)
+        self.assertTrue(colorized.find('[38;') != -1)
 
     # pylint: disable=line-too-long
     def test_get_text_without_links(self):